From: Sanjay Patel Date: Wed, 3 Aug 2016 19:48:40 +0000 (+0000) Subject: [InstCombine] use m_APInt to allow icmp eq (srem X, C1), C2 folds for splat constant... X-Git-Tag: android-x86-7.1-r4~29206 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=c6b62aa3e7d83b9c391e7ff633547cfd284cfd5a;p=android-x86%2Fexternal-llvm.git [InstCombine] use m_APInt to allow icmp eq (srem X, C1), C2 folds for splat constant vectors git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277638 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 4b949ab6561..576aa2d28ac 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2218,10 +2218,9 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) { switch (BO->getOpcode()) { case Instruction::SRem: // If we have a signed (X % (2^c)) == 0, turn it into an unsigned one. - // FIXME: Vectors are excluded by ConstantInt. - if (*RHSV == 0 && isa(BOp1) && BO->hasOneUse()) { - const APInt &V = cast(BOp1)->getValue(); - if (V.sgt(1) && V.isPowerOf2()) { + if (*RHSV == 0 && BO->hasOneUse()) { + const APInt *BOC; + if (match(BOp1, m_APInt(BOC)) && BOC->sgt(1) && BOC->isPowerOf2()) { Value *NewRem = Builder->CreateURem(BOp0, BOp1, BO->getName()); return new ICmpInst(ICI.getPredicate(), NewRem, Constant::getNullValue(BO->getType())); diff --git a/test/Transforms/InstCombine/rem.ll b/test/Transforms/InstCombine/rem.ll index cd3c937b267..74d42fa99bf 100644 --- a/test/Transforms/InstCombine/rem.ll +++ b/test/Transforms/InstCombine/rem.ll @@ -53,12 +53,10 @@ define i1 @test3a(i32 %A) { ret i1 %C } -; FIXME: Vectors should fold the same way. - define <2 x i1> @test3a_vec(<2 x i32> %A) { ; CHECK-LABEL: @test3a_vec( -; CHECK-NEXT: [[B:%.*]] = srem <2 x i32> %A, -; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> [[B]], zeroinitializer +; CHECK-NEXT: [[B1:%.*]] = and <2 x i32> %A, +; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i32> [[B1]], zeroinitializer ; CHECK-NEXT: ret <2 x i1> [[C]] ; %B = srem <2 x i32> %A,