aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-04-21 02:26:00 +0000
committerDan Gohman <gohman@apple.com>2009-04-21 02:26:00 +0000
commit4ee29af754f3b81ce90a5aa8f540b1f4a790191c (patch)
tree9e2abccc270ce136120bc1715e620a9431753379 /lib/Analysis/ScalarEvolution.cpp
parent59d0704c8f38c279670c5d555a44e5b33696ca89 (diff)
Teach ScalarEvolution how to recognize zext-inreg and sext-inreg,
as they appear in LLVM IR. This isn't particularly interesting on its own; this is just setting up some infrastructure. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69655 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--lib/Analysis/ScalarEvolution.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 0dbb258047..ace063a399 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -1947,6 +1947,19 @@ SCEVHandle ScalarEvolutionsImpl::createSCEV(Value *V) {
case Instruction::Sub:
return SE.getMinusSCEV(getSCEV(U->getOperand(0)),
getSCEV(U->getOperand(1)));
+ case Instruction::And:
+ // For an expression like x&255 that merely masks off the high bits,
+ // use zext(trunc(x)) as the SCEV expression.
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(U->getOperand(1))) {
+ const APInt &A = CI->getValue();
+ unsigned Ones = A.countTrailingOnes();
+ if (APIntOps::isMask(Ones, A))
+ return
+ SE.getZeroExtendExpr(SE.getTruncateExpr(getSCEV(U->getOperand(0)),
+ IntegerType::get(Ones)),
+ U->getType());
+ }
+ break;
case Instruction::Or:
// If the RHS of the Or is a constant, we may have something like:
// X*4+1 which got turned into X*4|1. Handle this as an Add so loop
@@ -1996,6 +2009,20 @@ SCEVHandle ScalarEvolutionsImpl::createSCEV(Value *V) {
}
break;
+ case Instruction::AShr:
+ // For a two-shift sext-inreg, use sext(trunc(x)) as the SCEV expression.
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(U->getOperand(1)))
+ if (Instruction *L = dyn_cast<Instruction>(U->getOperand(0)))
+ if (L->getOpcode() == Instruction::Shl &&
+ L->getOperand(1) == U->getOperand(1)) {
+ uint64_t Amt = CI->getZExtValue();
+ return
+ SE.getSignExtendExpr(SE.getTruncateExpr(getSCEV(L->getOperand(0)),
+ IntegerType::get(Amt)),
+ U->getType());
+ }
+ break;
+
case Instruction::Trunc:
return SE.getTruncateExpr(getSCEV(U->getOperand(0)), U->getType());