diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-09-15 16:23:20 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-09-15 16:23:20 +0000 |
commit | 40c53ea93374d90c303e4b9606cbcc745db9df95 (patch) | |
tree | 7221a277b7029e47c9a4da67a7dea730893642ee /llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | |
parent | 78a7c7d26a27a95eee3114affbbd027d08261dee (diff) | |
download | bcm5719-llvm-40c53ea93374d90c303e4b9606cbcc745db9df95.tar.gz bcm5719-llvm-40c53ea93374d90c303e4b9606cbcc745db9df95.zip |
[InstCombine] allow (icmp sgt smin(PosA, B), 0) fold for vectors
llvm-svn: 281624
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index fb5122a5edb..e8c6a27090d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1376,11 +1376,10 @@ static Instruction *ProcessUGT_ADDCST_ADD(ICmpInst &I, Value *A, Value *B, // Fold icmp Pred X, C. Instruction *InstCombiner::foldICmpWithConstant(ICmpInst &Cmp) { CmpInst::Predicate Pred = Cmp.getPredicate(); - Value *X = Cmp.getOperand(0), *C = Cmp.getOperand(1); + Value *X = Cmp.getOperand(0); - // FIXME: Use m_APInt to allow folds for splat constants. - ConstantInt *CI = dyn_cast<ConstantInt>(C); - if (!CI) + const APInt *C; + if (!match(Cmp.getOperand(1), m_APInt(C))) return nullptr; Value *A = nullptr, *B = nullptr; @@ -1400,21 +1399,26 @@ Instruction *InstCombiner::foldICmpWithConstant(ICmpInst &Cmp) { ConstantInt *CI2; // I = icmp ugt (add (add A, B), CI2), CI if (Pred == ICmpInst::ICMP_UGT && match(X, m_Add(m_Add(m_Value(A), m_Value(B)), m_ConstantInt(CI2)))) - if (Instruction *Res = ProcessUGT_ADDCST_ADD(Cmp, A, B, CI2, CI, *this)) + if (Instruction *Res = ProcessUGT_ADDCST_ADD( + Cmp, A, B, CI2, cast<ConstantInt>(Cmp.getOperand(1)), *this)) return Res; } // (icmp sgt smin(PosA, B) 0) -> (icmp sgt B 0) - if (CI->isZero() && Pred == ICmpInst::ICMP_SGT) - if (auto *SI = dyn_cast<SelectInst>(X)) { - SelectPatternResult SPR = matchSelectPattern(SI, A, B); - if (SPR.Flavor == SPF_SMIN) { - if (isKnownPositive(A, DL)) - return new ICmpInst(Pred, B, CI); - if (isKnownPositive(B, DL)) - return new ICmpInst(Pred, A, CI); - } + if (*C == 0 && Pred == ICmpInst::ICMP_SGT) { + SelectPatternResult SPR = matchSelectPattern(X, A, B); + if (SPR.Flavor == SPF_SMIN) { + if (isKnownPositive(A, DL)) + return new ICmpInst(Pred, B, Cmp.getOperand(1)); + if (isKnownPositive(B, DL)) + return new ICmpInst(Pred, A, Cmp.getOperand(1)); } + } + + // FIXME: Use m_APInt to allow folds for splat constants. + ConstantInt *CI = dyn_cast<ConstantInt>(Cmp.getOperand(1)); + if (!CI) + return nullptr; // The following transforms are only worth it if the only user of the subtract // is the icmp. |