diff options
| author | Dan Gohman <gohman@apple.com> | 2009-06-18 20:21:07 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2009-06-18 20:21:07 +0000 |
| commit | 4d3c3cfffd8aa8ffc978909f4bcd0e068315d3ca (patch) | |
| tree | e499c8fde00b0fc21579a519e705c6b762959b0c /llvm | |
| parent | 830ff50abf79bb44feb008fcc51c7be92c70e9c4 (diff) | |
| download | bcm5719-llvm-4d3c3cfffd8aa8ffc978909f4bcd0e068315d3ca.tar.gz bcm5719-llvm-4d3c3cfffd8aa8ffc978909f4bcd0e068315d3ca.zip | |
Recognize n != 0 ? n : 1 as umax(n, 1). Previously only ULT/UGT/ULE/UGE
comparisons were recognized for umax, but instcombine canonicalizes
unsigned comparisons with zero to this simpler form.
llvm-svn: 73717
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 9c6941f0d31..18c136fc0a6 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -2580,6 +2580,24 @@ SCEVHandle ScalarEvolution::createSCEV(Value *V) { return getNotSCEV(getUMaxExpr(getNotSCEV(getSCEV(LHS)), getNotSCEV(getSCEV(RHS)))); break; + case ICmpInst::ICMP_NE: + // n != 0 ? n : 1 -> umax(n, 1) + if (LHS == U->getOperand(1) && + isa<ConstantInt>(U->getOperand(2)) && + cast<ConstantInt>(U->getOperand(2))->isOne() && + isa<ConstantInt>(RHS) && + cast<ConstantInt>(RHS)->isZero()) + return getUMaxExpr(getSCEV(LHS), getSCEV(U->getOperand(2))); + break; + case ICmpInst::ICMP_EQ: + // n == 0 ? 1 : n -> umax(n, 1) + if (LHS == U->getOperand(2) && + isa<ConstantInt>(U->getOperand(1)) && + cast<ConstantInt>(U->getOperand(1))->isOne() && + isa<ConstantInt>(RHS) && + cast<ConstantInt>(RHS)->isZero()) + return getUMaxExpr(getSCEV(LHS), getSCEV(U->getOperand(1))); + break; default: break; } |

