[llvm-commits] CVS: llvm/lib/VMCore/ConstantFold.cpp
Chris Lattner
sabre at nondot.org
Sat Mar 24 22:47:21 PDT 2007
Changes in directory llvm/lib/VMCore:
ConstantFold.cpp updated: 1.148 -> 1.149
---
Log message:
fold constantexprs more aggressively, fixing PR1265: http://llvm.org/PR1265
---
Diffs of the changes: (+17 -2)
ConstantFold.cpp | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
Index: llvm/lib/VMCore/ConstantFold.cpp
diff -u llvm/lib/VMCore/ConstantFold.cpp:1.148 llvm/lib/VMCore/ConstantFold.cpp:1.149
--- llvm/lib/VMCore/ConstantFold.cpp:1.148 Fri Mar 23 00:33:23 2007
+++ llvm/lib/VMCore/ConstantFold.cpp Sun Mar 25 00:47:04 2007
@@ -519,10 +519,20 @@
return Constant::getNullValue(CI->getType()); // X % 1 == 0
break;
case Instruction::And:
- if (const ConstantInt *CI = dyn_cast<ConstantInt>(C2))
+ if (const ConstantInt *CI = dyn_cast<ConstantInt>(C2)) {
+ if (CI->isZero()) return const_cast<Constant*>(C2); // X & 0 == 0
if (CI->isAllOnesValue())
return const_cast<Constant*>(C1); // X & -1 == X
- if (C2->isNullValue()) return const_cast<Constant*>(C2); // X & 0 == 0
+
+ // (zext i32 to i64) & 4294967295 -> (zext i32 to i64)
+ if (CE1->getOpcode() == Instruction::ZExt) {
+ APInt PossiblySetBits
+ = cast<IntegerType>(CE1->getOperand(0)->getType())->getMask();
+ PossiblySetBits.zext(C1->getType()->getPrimitiveSizeInBits());
+ if ((PossiblySetBits & CI->getValue()) == PossiblySetBits)
+ return const_cast<Constant*>(C1);
+ }
+ }
if (CE1->isCast() && isa<GlobalValue>(CE1->getOperand(0))) {
GlobalValue *CPR = cast<GlobalValue>(CE1->getOperand(0));
@@ -543,6 +553,11 @@
case Instruction::Xor:
if (C2->isNullValue()) return const_cast<Constant*>(C1); // X ^ 0 == X
break;
+ case Instruction::AShr:
+ if (CE1->getOpcode() == Instruction::ZExt) // Top bits known zero.
+ return ConstantExpr::getLShr(const_cast<Constant*>(C1),
+ const_cast<Constant*>(C2));
+ break;
}
}
} else if (isa<ConstantExpr>(C2)) {
More information about the llvm-commits
mailing list