From 5b35b687856581bf9c08cafdcd88ff4054f47ec3 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 22 Sep 2017 18:57:22 +0000 Subject: [PATCH] [InstCombine] Simplify check for RHS being a splat constant in foldICmpUsingKnownBits by just checking Op1Min==Op1Max rather than going through m_APInt. llvm-svn: 314017 --- .../Transforms/InstCombine/InstCombineCompares.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 0a2d0e58b479..d9ead9893eae 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -4223,12 +4223,11 @@ Instruction *InstCombiner::foldICmpUsingKnownBits(ICmpInst &I) { if (Op1Min == Op0Max) // A A != B if max(A) == min(B) return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1); - const APInt *CmpC; - if (match(Op1, m_APInt(CmpC))) { + if (Op1Min == Op1Max) { // A A == C-1 if min(A)+1 == C - if (Op1Max == Op0Min + 1) + if (Op1Min == Op0Min + 1) return new ICmpInst(ICmpInst::ICMP_EQ, Op0, - ConstantInt::get(Op0->getType(), *CmpC - 1)); + ConstantInt::get(Op0->getType(), Op1Min - 1)); } break; } @@ -4240,12 +4239,11 @@ Instruction *InstCombiner::foldICmpUsingKnownBits(ICmpInst &I) { if (Op1Max == Op0Min) // A >u B -> A != B if min(A) == max(B) return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1); - const APInt *CmpC; - if (match(Op1, m_APInt(CmpC))) { + if (Op1Min == Op1Max) { // A >u C -> A == C+1 if max(a)-1 == C - if (*CmpC == Op0Max - 1) + if (Op1Min == Op0Max - 1) return new ICmpInst(ICmpInst::ICMP_EQ, Op0, - ConstantInt::get(Op1->getType(), *CmpC + 1)); + ConstantInt::get(Op1->getType(), Op1Min + 1)); } break; }