From: Sanjay Patel Date: Thu, 15 Sep 2016 14:15:47 +0000 (+0000) Subject: [InstCombine] use m_APInt to allow icmp folds using known bits for splat constant... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ee16969ab362f02f9de13e7a19ce86cf55335f1;p=llvm [InstCombine] use m_APInt to allow icmp folds using known bits for splat constant vectors git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281613 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index a55bfda320f..e744dde78d3 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/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/test/Transforms/InstCombine/icmp.ll b/test/Transforms/InstCombine/icmp.ll index 8a5b97c433c..b8bd0c05276 100644 --- a/test/Transforms/InstCombine/icmp.ll +++ b/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> , %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SHL]], -; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> %x, ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %shl = shl <2 x i32> , %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> , %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SHL]], -; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i32> %x, ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %shl = shl <2 x i32> , %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> , %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SH]], -; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> %x, ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %sh = lshr <2 x i32> , %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> , %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SH]], -; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> %x, ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %sh = lshr <2 x i32> , %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> , %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SHL]], -; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> %x, ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %shl = shl <2 x i32> , %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> , %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SHL]], -; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> %x, ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %shl = shl <2 x i32> , %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> , %x -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[SHL]], -; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[AND]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> %x, ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %shl = shl <2 x i32> , %x