From bd9e8a1faf8d718b2370710be7c67259cc14329e Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 4 Aug 2016 15:19:25 +0000 Subject: [PATCH] [InstCombine] use m_APInt to allow icmp eq (sub C1, X), C2 folds for splat constant vectors git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277731 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineCompares.cpp | 8 ++++---- test/Transforms/InstCombine/icmp.ll | 8 ++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 6a798f91759..4dc1bb0f83c 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2265,11 +2265,11 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) { break; case Instruction::Sub: if (BO->hasOneUse()) { - // FIXME: Vectors are excluded by ConstantInt. - if (ConstantInt *BOp0C = dyn_cast(BOp0)) { + const APInt *BOC; + if (match(BOp0, m_APInt(BOC))) { // Replace ((sub A, B) != C) with (B != A-C) if A & C are constants. - return new ICmpInst(ICI.getPredicate(), BOp1, - ConstantExpr::getSub(BOp0C, RHS)); + Constant *SubC = ConstantExpr::getSub(cast(BOp0), RHS); + return new ICmpInst(ICI.getPredicate(), BOp1, SubC); } else if (*RHSV == 0) { // Replace ((sub A, B) != 0) with (A != B) return new ICmpInst(ICI.getPredicate(), BOp0, BOp1); diff --git a/test/Transforms/InstCombine/icmp.ll b/test/Transforms/InstCombine/icmp.ll index 1e1957558ad..fda911ee507 100644 --- a/test/Transforms/InstCombine/icmp.ll +++ b/test/Transforms/InstCombine/icmp.ll @@ -660,11 +660,9 @@ define i1 @test55(i32 %a) { ret i1 %cmp } -; FIXME: Vectors should fold the same way. define <2 x i1> @test55vec(<2 x i32> %a) { ; CHECK-LABEL: @test55vec( -; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> zeroinitializer, %a -; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[SUB]], +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> %a, ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %sub = sub <2 x i32> zeroinitializer, %a @@ -682,11 +680,9 @@ define i1 @test56(i32 %a) { ret i1 %cmp } -; FIXME: Vectors should fold the same way. define <2 x i1> @test56vec(<2 x i32> %a) { ; CHECK-LABEL: @test56vec( -; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> , %a -; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[SUB]], +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> %a, ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %sub = sub <2 x i32> , %a -- 2.11.0