[llvm-commits] [llvm] r73664 - in /llvm/trunk: lib/Analysis/ScalarEvolution.cpp test/Analysis/ScalarEvolution/xor-and.ll
Dan Gohman
gohman at apple.com
Wed Jun 17 17:00:30 PDT 2009
Author: djg
Date: Wed Jun 17 19:00:20 2009
New Revision: 73664
URL: http://llvm.org/viewvc/llvm-project?rev=73664&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
llvm/trunk/test/Analysis/ScalarEvolution/xor-and.ll
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=73664&r1=73663&r2=73664&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed Jun 17 19:00:20 2009
@@ -2453,10 +2453,25 @@
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;
Modified: llvm/trunk/test/Analysis/ScalarEvolution/xor-and.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/xor-and.ll?rev=73664&r1=73663&r2=73664&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/xor-and.ll (original)
+++ llvm/trunk/test/Analysis/ScalarEvolution/xor-and.ll Wed Jun 17 19:00:20 2009
@@ -1,6 +1,7 @@
-; RUN: llvm-as < %s | opt -scalar-evolution -disable-output -analyze | grep {\\--> %z}
+; RUN: llvm-as < %s | opt -scalar-evolution -disable-output -analyze \
+; RUN: | grep {\\--> (zext i4 (-8 + (trunc i64 (8 \\* %x) to i4)) to i64)}
-; ScalarEvolution shouldn't try to analyze %s into something like
+; ScalarEvolution shouldn't try to analyze %z into something like
; --> (zext i4 (-1 + (-1 * (trunc i64 (8 * %x) to i4))) to i64)
define i64 @foo(i64 %x) {
More information about the llvm-commits
mailing list