summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-03-25 05:47:04 +0000
committerChris Lattner <sabre@nondot.org>2007-03-25 05:47:04 +0000
commit6d94bb79ac74c797a576bf24f712af2012171fbd (patch)
tree40a95c833410de40c6685e6747c272459ba066ce /llvm
parent80263aadf367ab8f48d55ec916158312ae662992 (diff)
downloadbcm5719-llvm-6d94bb79ac74c797a576bf24f712af2012171fbd.tar.gz
bcm5719-llvm-6d94bb79ac74c797a576bf24f712af2012171fbd.zip
fold constantexprs more aggressively, fixing PR1265
llvm-svn: 35336
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/VMCore/ConstantFold.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp
index d7e51956e4d..46263060e57 100644
--- a/llvm/lib/VMCore/ConstantFold.cpp
+++ b/llvm/lib/VMCore/ConstantFold.cpp
@@ -519,10 +519,20 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
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 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
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)) {
OpenPOWER on IntegriCloud