aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-06-18 20:21:07 +0000
committerDan Gohman <gohman@apple.com>2009-06-18 20:21:07 +0000
commitf27dc69fd1ec742ef5046805d61b921a6c1ee81b (patch)
tree06b450ad82068ceecffbd1c280ac11ef82e1420a /lib/Analysis
parentfdc6c105373816f286fc8a42136d53aa39a4dd95 (diff)
downloadexternal_llvm-f27dc69fd1ec742ef5046805d61b921a6c1ee81b.zip
external_llvm-f27dc69fd1ec742ef5046805d61b921a6c1ee81b.tar.gz
external_llvm-f27dc69fd1ec742ef5046805d61b921a6c1ee81b.tar.bz2
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73717 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/ScalarEvolution.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 9c6941f..18c136f 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/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;
}