diff options
| author | Roman Lebedev <lebedev.ri@gmail.com> | 2020-01-03 21:10:51 +0300 |
|---|---|---|
| committer | Roman Lebedev <lebedev.ri@gmail.com> | 2020-01-03 21:25:48 +0300 |
| commit | 7973aa05f6f987bb4746db2bcbb34e7fa0ce8897 (patch) | |
| tree | 4c8d2ce1e2f828b32e87a63fe1b0a20f37fb0af4 /llvm/test/Transforms/InstCombine | |
| parent | 6f922dbbeae7b647dfd548c4d74f384ca9c252da (diff) | |
| download | bcm5719-llvm-7973aa05f6f987bb4746db2bcbb34e7fa0ce8897.tar.gz bcm5719-llvm-7973aa05f6f987bb4746db2bcbb34e7fa0ce8897.zip | |
[NFC][InstCombine] '(Op1 & С) - Op1' -> '-(Op1 & ~C)' fold (PR44427)
This decreases use count of Op1, potentially allows
us to further hoist said 'neg' later on,
and results in marginally better X86 codegen.
Name: (Op1 & С) - Op1 -> -(Op1 & ~C)
%o = and i64 %Op1, C1
%r = sub i64 %o, %Op1
=>
%n = and i64 %Op1, ~C1
%r = sub i64 0, %n
https://rise4fun.com/Alive/rwgA
https://godbolt.org/z/R_RMfM
https://bugs.llvm.org/show_bug.cgi?id=44427
Diffstat (limited to 'llvm/test/Transforms/InstCombine')
| -rw-r--r-- | llvm/test/Transforms/InstCombine/and2.ll | 4 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/hoist-negation-out-of-bias-calculation-with-constant.ll | 16 |
2 files changed, 10 insertions, 10 deletions
diff --git a/llvm/test/Transforms/InstCombine/and2.ll b/llvm/test/Transforms/InstCombine/and2.ll index c872b4caa6c..74b120458ba 100644 --- a/llvm/test/Transforms/InstCombine/and2.ll +++ b/llvm/test/Transforms/InstCombine/and2.ll @@ -84,8 +84,8 @@ define <2 x i64> @test9vec(<2 x i64> %x) { define i64 @test10(i64 %x) { ; CHECK-LABEL: @test10( -; CHECK-NEXT: [[AND:%.*]] = and i64 [[X:%.*]], 1 -; CHECK-NEXT: [[ADD:%.*]] = sub i64 [[AND]], [[X]] +; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[X:%.*]], -2 +; CHECK-NEXT: [[ADD:%.*]] = sub i64 0, [[TMP1]] ; CHECK-NEXT: ret i64 [[ADD]] ; %sub = sub nsw i64 0, %x diff --git a/llvm/test/Transforms/InstCombine/hoist-negation-out-of-bias-calculation-with-constant.ll b/llvm/test/Transforms/InstCombine/hoist-negation-out-of-bias-calculation-with-constant.ll index 2956ea81a91..d8cabb3116e 100644 --- a/llvm/test/Transforms/InstCombine/hoist-negation-out-of-bias-calculation-with-constant.ll +++ b/llvm/test/Transforms/InstCombine/hoist-negation-out-of-bias-calculation-with-constant.ll @@ -15,8 +15,8 @@ define i8 @t0(i8 %x) { ; CHECK-LABEL: @t0( -; CHECK-NEXT: [[UNBIASEDX:%.*]] = and i8 [[X:%.*]], 42 -; CHECK-NEXT: [[NEGBIAS:%.*]] = sub i8 [[UNBIASEDX]], [[X]] +; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -43 +; CHECK-NEXT: [[NEGBIAS:%.*]] = sub i8 0, [[TMP1]] ; CHECK-NEXT: ret i8 [[NEGBIAS]] ; %unbiasedx = and i8 %x, 42 @@ -26,8 +26,8 @@ define i8 @t0(i8 %x) { define <2 x i8> @t1_vec(<2 x i8> %x) { ; CHECK-LABEL: @t1_vec( -; CHECK-NEXT: [[UNBIASEDX:%.*]] = and <2 x i8> [[X:%.*]], <i8 42, i8 42> -; CHECK-NEXT: [[NEGBIAS:%.*]] = sub <2 x i8> [[UNBIASEDX]], [[X]] +; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], <i8 -43, i8 -43> +; CHECK-NEXT: [[NEGBIAS:%.*]] = sub <2 x i8> zeroinitializer, [[TMP1]] ; CHECK-NEXT: ret <2 x i8> [[NEGBIAS]] ; %unbiasedx = and <2 x i8> %x, <i8 42, i8 42> @@ -37,8 +37,8 @@ define <2 x i8> @t1_vec(<2 x i8> %x) { define <2 x i8> @t2_vec_undef(<2 x i8> %x) { ; CHECK-LABEL: @t2_vec_undef( -; CHECK-NEXT: [[UNBIASEDX:%.*]] = and <2 x i8> [[X:%.*]], <i8 42, i8 undef> -; CHECK-NEXT: [[NEGBIAS:%.*]] = sub <2 x i8> [[UNBIASEDX]], [[X]] +; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], <i8 -43, i8 undef> +; CHECK-NEXT: [[NEGBIAS:%.*]] = sub <2 x i8> zeroinitializer, [[TMP1]] ; CHECK-NEXT: ret <2 x i8> [[NEGBIAS]] ; %unbiasedx = and <2 x i8> %x, <i8 42, i8 undef> @@ -48,8 +48,8 @@ define <2 x i8> @t2_vec_undef(<2 x i8> %x) { define <2 x i8> @t3_vec_nonsplat(<2 x i8> %x) { ; CHECK-LABEL: @t3_vec_nonsplat( -; CHECK-NEXT: [[UNBIASEDX:%.*]] = and <2 x i8> [[X:%.*]], <i8 42, i8 44> -; CHECK-NEXT: [[NEGBIAS:%.*]] = sub <2 x i8> [[UNBIASEDX]], [[X]] +; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], <i8 -43, i8 -45> +; CHECK-NEXT: [[NEGBIAS:%.*]] = sub <2 x i8> zeroinitializer, [[TMP1]] ; CHECK-NEXT: ret <2 x i8> [[NEGBIAS]] ; %unbiasedx = and <2 x i8> %x, <i8 42, i8 44> |

