diff options
| author | Craig Topper <craig.topper@gmail.com> | 2017-03-31 21:08:37 +0000 |
|---|---|---|
| committer | Craig Topper <craig.topper@gmail.com> | 2017-03-31 21:08:37 +0000 |
| commit | 0d8801f991bb475fe20044de3fe8d373e937d112 (patch) | |
| tree | aee1746851f1faab20cffcedcd0798b8092121ab /llvm | |
| parent | d04c9b999ced3be6a139d639a989b17698a3871a (diff) | |
| download | bcm5719-llvm-0d8801f991bb475fe20044de3fe8d373e937d112.tar.gz bcm5719-llvm-0d8801f991bb475fe20044de3fe8d373e937d112.zip | |
[InstCombine] Add test case demonstrating missed opportunities for removing add/sub when the LSBs of one input are known to be 0 and MSBs of the output aren't consumed.
llvm-svn: 299263
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/test/Transforms/InstCombine/and2.ll | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/and2.ll b/llvm/test/Transforms/InstCombine/and2.ll index 3d043b0864c..b7f72833b17 100644 --- a/llvm/test/Transforms/InstCombine/and2.ll +++ b/llvm/test/Transforms/InstCombine/and2.ll @@ -122,3 +122,66 @@ define i64 @test10(i64 %x) { ret i64 %add } +; The add in this test is unnecessary because the LSBs of the RHS are 0 and we only consume those bits. +define i32 @test11(i32 %a, i32 %b) { +; CHECK-LABEL: @test11( +; CHECK-NEXT: [[X:%.*]] = shl i32 [[A:%.*]], 8 +; CHECK-NEXT: [[Y:%.*]] = add i32 [[X]], [[B:%.*]] +; CHECK-NEXT: [[Z:%.*]] = and i32 [[Y]], 128 +; CHECK-NEXT: [[W:%.*]] = mul i32 [[Z]], [[X]] +; CHECK-NEXT: ret i32 [[W]] +; + %x = shl i32 %a, 8 + %y = add i32 %x, %b + %z = and i32 %y, 128 + %w = mul i32 %z, %x ; to keep the shift from being removed + ret i32 %w +} + +; The add in this test is unnecessary because the LSBs of the RHS are 0 and we only consume those bits. +define i32 @test12(i32 %a, i32 %b) { +; CHECK-LABEL: @test12( +; CHECK-NEXT: [[X:%.*]] = shl i32 [[A:%.*]], 8 +; CHECK-NEXT: [[Y:%.*]] = add i32 [[X]], [[B:%.*]] +; CHECK-NEXT: [[Z:%.*]] = and i32 [[Y]], 128 +; CHECK-NEXT: [[W:%.*]] = mul i32 [[Z]], [[X]] +; CHECK-NEXT: ret i32 [[W]] +; + %x = shl i32 %a, 8 + %y = add i32 %b, %x + %z = and i32 %y, 128 + %w = mul i32 %z, %x ; to keep the shift from being removed + ret i32 %w +} + +; The sub in this test is unnecessary because the LSBs of the RHS are 0 and we only consume those bits. +define i32 @test13(i32 %a, i32 %b) { +; CHECK-LABEL: @test13( +; CHECK-NEXT: [[X:%.*]] = shl i32 [[A:%.*]], 8 +; CHECK-NEXT: [[Y:%.*]] = sub i32 [[B:%.*]], [[X]] +; CHECK-NEXT: [[Z:%.*]] = and i32 [[Y]], 128 +; CHECK-NEXT: [[W:%.*]] = mul i32 [[Z]], [[X]] +; CHECK-NEXT: ret i32 [[W]] +; + %x = shl i32 %a, 8 + %y = sub i32 %b, %x + %z = and i32 %y, 128 + %w = mul i32 %z, %x ; to keep the shift from being removed + ret i32 %w +} + +; The sub in this test cannot be removed because we need to keep the negation of %b +define i32 @test14(i32 %a, i32 %b) { +; CHECK-LABEL: @test14( +; CHECK-NEXT: [[X:%.*]] = shl i32 [[A:%.*]], 8 +; CHECK-NEXT: [[Y:%.*]] = sub i32 [[X]], [[B:%.*]] +; CHECK-NEXT: [[Z:%.*]] = and i32 [[Y]], 128 +; CHECK-NEXT: [[W:%.*]] = mul i32 [[Z]], [[X]] +; CHECK-NEXT: ret i32 [[W]] +; + %x = shl i32 %a, 8 + %y = sub i32 %x, %b + %z = and i32 %y, 128 + %w = mul i32 %z, %x ; to keep the shift from being removed + ret i32 %w +} |

