From 3bade138b5edb59a472996aeb21fdf9b29d98209 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 4 Aug 2016 22:19:27 +0000 Subject: [PATCH] [InstCombine] use m_APInt to allow icmp eq (mul X, C1), C2 folds for splat constant vectors This concludes the splat vector enhancements for foldICmpEqualityWithConstant(). Other commits in this series: https://reviews.llvm.org/rL277762 https://reviews.llvm.org/rL277752 https://reviews.llvm.org/rL277738 https://reviews.llvm.org/rL277731 https://reviews.llvm.org/rL277659 https://reviews.llvm.org/rL277638 https://reviews.llvm.org/rL277629 llvm-svn: 277779 --- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 11 +++++------ llvm/test/Transforms/InstCombine/icmp.ll | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 6c795db..778a75f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2314,14 +2314,13 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) { } case Instruction::Mul: if (*RHSV == 0 && BO->hasNoSignedWrap()) { - // FIXME: Vectors are excluded by ConstantInt. - if (ConstantInt *BOC = dyn_cast(BOp1)) { - // The trivial case (mul X, 0) is handled by InstSimplify + const APInt *BOC; + if (match(BOp1, m_APInt(BOC)) && *BOC != 0) { + // The trivial case (mul X, 0) is handled by InstSimplify. // General case : (mul X, C) != 0 iff X != 0 // (mul X, C) == 0 iff X == 0 - if (!BOC->isZero()) - return new ICmpInst(ICI.getPredicate(), BOp0, - Constant::getNullValue(RHS->getType())); + return new ICmpInst(ICI.getPredicate(), BOp0, + Constant::getNullValue(RHS->getType())); } } break; diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll index 88cf0cd..27ae64e 100644 --- a/llvm/test/Transforms/InstCombine/icmp.ll +++ b/llvm/test/Transforms/InstCombine/icmp.ll @@ -1207,8 +1207,7 @@ define i1 @icmp_mul_neq0(i32 %x) { ; FIXME: Vectors should fold the same way. define <2 x i1> @icmp_mul_neq0_vec(<2 x i32> %x) { ; CHECK-LABEL: @icmp_mul_neq0_vec( -; CHECK-NEXT: [[MUL:%.*]] = mul nsw <2 x i32> %x, -; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[MUL]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> %x, zeroinitializer ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %mul = mul nsw <2 x i32> %x, -- 2.7.4