diff options
author | Dan Gohman <gohman@apple.com> | 2009-06-18 00:00:20 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-06-18 00:00:20 +0000 |
commit | eddf77123a1972a85f175ac1361fae30ff016a6a (patch) | |
tree | 21ec1f9da04da7aa9d09129004aca2a09704a88a /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | 4d8723d47f67c3e99b18fcba9bec863461dd8ca1 (diff) | |
download | bcm5719-llvm-eddf77123a1972a85f175ac1361fae30ff016a6a.tar.gz bcm5719-llvm-eddf77123a1972a85f175ac1361fae30ff016a6a.zip |
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.
llvm-svn: 73664
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 94fb871dc31..751a635194c 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/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; |