aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-06-18 00:00:20 +0000
committerDan Gohman <gohman@apple.com>2009-06-18 00:00:20 +0000
commited1d8bb18a96d40ee22fc9759c0c4388519d0011 (patch)
tree399b71a26dfc56bcd1f0eea8764ab4c4f9c6617f /lib/Analysis
parentae1d7dd8a6b77e82c044ab98a25cba59959f78f6 (diff)
downloadexternal_llvm-ed1d8bb18a96d40ee22fc9759c0c4388519d0011.zip
external_llvm-ed1d8bb18a96d40ee22fc9759c0c4388519d0011.tar.gz
external_llvm-ed1d8bb18a96d40ee22fc9759c0c4388519d0011.tar.bz2
Teach ScalarEvolution how to recognize another xor(and(x, C), C) case.
If C is a single bit and the and gets analyzed as a truncate and zero-extend, the xor can be represnted as an add. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73664 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/ScalarEvolution.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 94fb871..751a635 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -2453,10 +2453,25 @@ SCEVHandle ScalarEvolution::createSCEV(Value *V) {
LCI->getValue() == CI->getValue())
if (const SCEVZeroExtendExpr *Z =
dyn_cast<SCEVZeroExtendExpr>(getSCEV(U->getOperand(0)))) {
- SCEVHandle ZO = Z->getOperand();
- if (APIntOps::isMask(getTypeSizeInBits(ZO->getType()),
- CI->getValue()))
- return getZeroExtendExpr(getNotSCEV(ZO), U->getType());
+ const Type *UTy = U->getType();
+ SCEVHandle Z0 = Z->getOperand();
+ const Type *Z0Ty = Z0->getType();
+ unsigned Z0TySize = getTypeSizeInBits(Z0Ty);
+
+ // If C is a low-bits mask, the zero extend is zerving to
+ // mask off the high bits. Complement the operand and
+ // re-apply the zext.
+ if (APIntOps::isMask(Z0TySize, CI->getValue()))
+ return getZeroExtendExpr(getNotSCEV(Z0), UTy);
+
+ // If C is a single bit, it may be in the sign-bit position
+ // before the zero-extend. In this case, represent the xor
+ // using an add, which is equivalent, and re-apply the zext.
+ APInt Trunc = APInt(CI->getValue()).trunc(Z0TySize);
+ if (APInt(Trunc).zext(getTypeSizeInBits(UTy)) == CI->getValue() &&
+ Trunc.isSignBit())
+ return getZeroExtendExpr(getAddExpr(Z0, getConstant(Trunc)),
+ UTy);
}
}
break;