diff options
| author | Robert Lougher <rob.lougher@gmail.com> | 2019-05-07 14:14:29 +0000 |
|---|---|---|
| committer | Robert Lougher <rob.lougher@gmail.com> | 2019-05-07 14:14:29 +0000 |
| commit | 07298c9b1eed0afa7362801b091c134148dcfd1e (patch) | |
| tree | 2a152c781ba2edbbc793e89fca27321f3de79be2 | |
| parent | 25f64629761f583324c716aab319cf6298aed45b (diff) | |
| download | bcm5719-llvm-07298c9b1eed0afa7362801b091c134148dcfd1e.tar.gz bcm5719-llvm-07298c9b1eed0afa7362801b091c134148dcfd1e.zip | |
Precommit tests for or/add transform. NFC.
llvm-svn: 360149
| -rw-r--r-- | llvm/test/Transforms/InstCombine/add.ll | 80 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/sub.ll | 50 |
2 files changed, 130 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/add.ll b/llvm/test/Transforms/InstCombine/add.ll index 0f805e856f8..8b30026b4cf 100644 --- a/llvm/test/Transforms/InstCombine/add.ll +++ b/llvm/test/Transforms/InstCombine/add.ll @@ -978,3 +978,83 @@ define i32 @add_to_sub2(i32 %A, i32 %M) { %E = add i32 %D, 1 ret i32 %E } + +; (X | C1) + C2 --> (X | C1) ^ C1 iff (C1 == -C2) +define i32 @test44(i32 %A) { +; CHECK-LABEL: @test44( +; CHECK-NEXT: [[B:%.*]] = or i32 [[A:%.*]], 123 +; CHECK-NEXT: [[C:%.*]] = add nsw i32 [[B]], -123 +; CHECK-NEXT: ret i32 [[C]] +; + %B = or i32 %A, 123 + %C = add i32 %B, -123 + ret i32 %C +} + +define i32 @test44_extra_use(i32 %A) { +; CHECK-LABEL: @test44_extra_use( +; CHECK-NEXT: [[B:%.*]] = or i32 [[A:%.*]], 123 +; CHECK-NEXT: [[C:%.*]] = add nsw i32 [[B]], -123 +; CHECK-NEXT: [[D:%.*]] = mul i32 [[B]], [[C]] +; CHECK-NEXT: ret i32 [[D]] +; + %B = or i32 %A, 123 + %C = add i32 %B, -123 + %D = mul i32 %B, %C + ret i32 %D +} + +define i32 @test44_non_matching(i32 %A) { +; CHECK-LABEL: @test44_non_matching( +; CHECK-NEXT: [[B:%.*]] = or i32 [[A:%.*]], 123 +; CHECK-NEXT: [[C:%.*]] = add i32 [[B]], -321 +; CHECK-NEXT: ret i32 [[C]] +; + %B = or i32 %A, 123 + %C = add i32 %B, -321 + ret i32 %C +} + +define <2 x i32> @test44_vec(<2 x i32> %A) { +; CHECK-LABEL: @test44_vec( +; CHECK-NEXT: [[B:%.*]] = or <2 x i32> [[A:%.*]], <i32 123, i32 123> +; CHECK-NEXT: [[C:%.*]] = add nsw <2 x i32> [[B]], <i32 -123, i32 -123> +; CHECK-NEXT: ret <2 x i32> [[C]] +; + %B = or <2 x i32> %A, <i32 123, i32 123> + %C = add <2 x i32> %B, <i32 -123, i32 -123> + ret <2 x i32> %C +} + +define <2 x i32> @test44_vec_non_matching(<2 x i32> %A) { +; CHECK-LABEL: @test44_vec_non_matching( +; CHECK-NEXT: [[B:%.*]] = or <2 x i32> [[A:%.*]], <i32 123, i32 123> +; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], <i32 -321, i32 -321> +; CHECK-NEXT: ret <2 x i32> [[C]] +; + %B = or <2 x i32> %A, <i32 123, i32 123> + %C = add <2 x i32> %B, <i32 -321, i32 -321> + ret <2 x i32> %C +} + +define <2 x i32> @test44_vec_undef(<2 x i32> %A) { +; CHECK-LABEL: @test44_vec_undef( +; CHECK-NEXT: [[B:%.*]] = or <2 x i32> [[A:%.*]], <i32 123, i32 undef> +; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], <i32 -123, i32 undef> +; CHECK-NEXT: ret <2 x i32> [[C]] +; + %B = or <2 x i32> %A, <i32 123, i32 undef> + %C = add <2 x i32> %B, <i32 -123, i32 undef> + ret <2 x i32> %C +} + +define <2 x i32> @test44_vec_non_splat(<2 x i32> %A) { +; CHECK-LABEL: @test44_vec_non_splat( +; CHECK-NEXT: [[B:%.*]] = or <2 x i32> [[A:%.*]], <i32 123, i32 456> +; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], <i32 -123, i32 -456> +; CHECK-NEXT: ret <2 x i32> [[C]] +; + %B = or <2 x i32> %A, <i32 123, i32 456> + %C = add <2 x i32> %B, <i32 -123, i32 -456> + ret <2 x i32> %C +} diff --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll index 6e1f34868f2..7af94f9b785 100644 --- a/llvm/test/Transforms/InstCombine/sub.ll +++ b/llvm/test/Transforms/InstCombine/sub.ll @@ -1267,6 +1267,56 @@ define <2 x i32> @test69(<2 x i32> %x) { ret <2 x i32> %res } +; Check (X | Y) - Y --> X & ~Y when Y is a constant +define i32 @test70(i32 %A) { +; CHECK-LABEL: @test70( +; CHECK-NEXT: [[B:%.*]] = or i32 [[A:%.*]], 123 +; CHECK-NEXT: [[C:%.*]] = add nsw i32 [[B]], -123 +; CHECK-NEXT: ret i32 [[C]] +; + %B = or i32 %A, 123 + %C = sub i32 %B, 123 + ret i32 %C +} + +; Check (X | Y) - Y --> (X | Y) ^ Y doesn't happen where (X | Y) has multiple uses +define i32 @test71(i32 %A, i32 %B) { +; CHECK-LABEL: @test71( +; CHECK-NEXT: [[C:%.*]] = or i32 [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[D:%.*]] = sub i32 [[C]], [[B]] +; CHECK-NEXT: [[E:%.*]] = mul i32 [[C]], [[D]] +; CHECK-NEXT: ret i32 [[E]] +; + %C = or i32 %A, %B + %D = sub i32 %C, %B + %E = mul i32 %C, %D + ret i32 %E +} + +; Check (X | Y) - Y --> X & ~Y where X and Y are vectors +define <2 x i32> @test72(<2 x i32> %A, <2 x i32> %B) { +; CHECK-LABEL: @test72( +; CHECK-NEXT: [[B_NOT:%.*]] = xor <2 x i32> [[B:%.*]], <i32 -1, i32 -1> +; CHECK-NEXT: [[D:%.*]] = and <2 x i32> [[B_NOT]], [[A:%.*]] +; CHECK-NEXT: ret <2 x i32> [[D]] +; + %C = or <2 x i32> %A, %B + %D = sub <2 x i32> %C, %B + ret <2 x i32> %D +} + +; Check reversing sub operands won't trigger (X | Y) - Y --> X & ~Y +define i32 @test73(i32 %A, i32 %B) { +; CHECK-LABEL: @test73( +; CHECK-NEXT: [[C:%.*]] = or i32 [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[D:%.*]] = sub i32 [[B]], [[C]] +; CHECK-NEXT: ret i32 [[D]] +; + %C = or i32 %A, %B + %D = sub i32 %B, %C + ret i32 %D +} + define i32 @nsw_inference1(i32 %x, i32 %y) { ; CHECK-LABEL: @nsw_inference1( ; CHECK-NEXT: [[X2:%.*]] = or i32 [[X:%.*]], 1024 |

