diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2016-09-15 14:15:47 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2016-09-15 14:15:47 +0000 |
| commit | 7577a3d799b7fd66a9053f6059dcd5877e9d56e5 (patch) | |
| tree | 38a5175352c4195a1a019b47b63b7749c3223f20 | |
| parent | bc2bbb2e29e0a11aaeedadbf796035a8c0b707e4 (diff) | |
| download | bcm5719-llvm-7577a3d799b7fd66a9053f6059dcd5877e9d56e5.tar.gz bcm5719-llvm-7577a3d799b7fd66a9053f6059dcd5877e9d56e5.zip | |
[InstCombine] use m_APInt to allow icmp folds using known bits for splat constant vectors
llvm-svn: 281613
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 6 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/icmp.ll | 35 |
2 files changed, 10 insertions, 31 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index a55bfda320f..e744dde78d3 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3216,9 +3216,9 @@ Instruction *InstCombiner::foldICmpUsingKnownBits(ICmpInst &I) { if (~Op1KnownZero == 0) { // If the LHS is an AND with the same constant, look through it. Value *LHS = nullptr; - ConstantInt *LHSC = nullptr; - if (!match(Op0, m_And(m_Value(LHS), m_ConstantInt(LHSC))) || - LHSC->getValue() != Op0KnownZeroInverted) + const APInt *LHSC; + if (!match(Op0, m_And(m_Value(LHS), m_APInt(LHSC))) || + *LHSC != Op0KnownZeroInverted) LHS = Op0; Value *X; diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll index 8a5b97c433c..b8bd0c05276 100644 --- a/llvm/test/Transforms/InstCombine/icmp.ll +++ b/llvm/test/Transforms/InstCombine/icmp.ll @@ -171,12 +171,9 @@ define i1 @test17(i32 %x) { ret i1 %cmp } -; FIXME: Vectors should fold the same way. define <2 x i1> @test17vec(<2 x i32> %x) { ; CHECK-LABEL: @test17vec( -; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i32> <i32 1, i32 1>, %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SHL]], <i32 8, i32 8> -; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> %x, <i32 3, i32 3> ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %shl = shl <2 x i32> <i32 1, i32 1>, %x @@ -196,12 +193,9 @@ define i1 @test17a(i32 %x) { ret i1 %cmp } -; FIXME: Vectors should fold the same way. define <2 x i1> @test17a_vec(<2 x i32> %x) { ; CHECK-LABEL: @test17a_vec( -; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i32> <i32 1, i32 1>, %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SHL]], <i32 7, i32 7> -; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i32> %x, <i32 2, i32 2> ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %shl = shl <2 x i32> <i32 1, i32 1>, %x @@ -221,12 +215,9 @@ define i1 @test18_eq(i32 %x) { ret i1 %cmp } -; FIXME: Vectors should fold the same way. define <2 x i1> @test18_eq_vec(<2 x i32> %x) { ; CHECK-LABEL: @test18_eq_vec( -; CHECK-NEXT: [[SH:%.*]] = lshr <2 x i32> <i32 8, i32 8>, %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SH]], <i32 1, i32 1> -; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> %x, <i32 3, i32 3> ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %sh = lshr <2 x i32> <i32 8, i32 8>, %x @@ -246,12 +237,9 @@ define i1 @test18_ne(i32 %x) { ret i1 %cmp } -; FIXME: Vectors should fold the same way. define <2 x i1> @test18_ne_vec(<2 x i32> %x) { ; CHECK-LABEL: @test18_ne_vec( -; CHECK-NEXT: [[SH:%.*]] = lshr <2 x i32> <i32 8, i32 8>, %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SH]], <i32 1, i32 1> -; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> %x, <i32 3, i32 3> ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %sh = lshr <2 x i32> <i32 8, i32 8>, %x @@ -271,12 +259,9 @@ define i1 @test19(i32 %x) { ret i1 %cmp } -; FIXME: Vectors should fold the same way. define <2 x i1> @test19vec(<2 x i32> %x) { ; CHECK-LABEL: @test19vec( -; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i32> <i32 1, i32 1>, %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SHL]], <i32 8, i32 8> -; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> %x, <i32 3, i32 3> ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %shl = shl <2 x i32> <i32 1, i32 1>, %x @@ -306,12 +291,9 @@ define i1 @test20(i32 %x) { ret i1 %cmp } -; FIXME: Vectors should fold the same way. define <2 x i1> @test20vec(<2 x i32> %x) { ; CHECK-LABEL: @test20vec( -; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i32> <i32 1, i32 1>, %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SHL]], <i32 8, i32 8> -; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> %x, <i32 3, i32 3> ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %shl = shl <2 x i32> <i32 1, i32 1>, %x @@ -331,12 +313,9 @@ define i1 @test20a(i32 %x) { ret i1 %cmp } -; FIXME: Vectors should fold the same way. define <2 x i1> @test20a_vec(<2 x i32> %x) { ; CHECK-LABEL: @test20a_vec( -; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i32> <i32 1, i32 1>, %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SHL]], <i32 7, i32 7> -; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> %x, <i32 3, i32 3> ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %shl = shl <2 x i32> <i32 1, i32 1>, %x |

