summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-01-02 01:22:23 +0000
committerChris Lattner <sabre@nondot.org>2010-01-02 01:22:23 +0000
commit8fb74c6ee221a4e11885186f286e5a4c74eca5bd (patch)
tree2cd22353d0fada07f4012918973d837e3a3827a3 /llvm/lib/Analysis/ConstantFolding.cpp
parente36a6b3e44915d1305fa578b16ed0d815ec1b19c (diff)
downloadbcm5719-llvm-8fb74c6ee221a4e11885186f286e5a4c74eca5bd.tar.gz
bcm5719-llvm-8fb74c6ee221a4e11885186f286e5a4c74eca5bd.zip
constant fold nasty constant expressions formed by llvm-gcc,
wrapping up PR3351. llvm-svn: 92410
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index eaf90d014ff..194cabaf978 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -718,14 +718,13 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
switch (Opcode) {
default: return 0;
+ case Instruction::ICmp:
+ case Instruction::FCmp: assert(0 && "Invalid for compares");
case Instruction::Call:
if (Function *F = dyn_cast<Function>(Ops[0]))
if (canConstantFoldCallTo(F))
return ConstantFoldCall(F, Ops+1, NumOps-1);
return 0;
- case Instruction::ICmp:
- case Instruction::FCmp:
- llvm_unreachable("This function is invalid for compares: no predicate specified");
case Instruction::PtrToInt:
// If the input is a inttoptr, eliminate the pair. This requires knowing
// the width of a pointer, so it can't be done in ConstantExpr::getCast.
@@ -877,6 +876,20 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate,
CE1->getOperand(0), TD);
}
}
+
+ // icmp eq (or x, y), 0 -> (icmp eq x, 0) & (icmp eq y, 0)
+ // icmp ne (or x, y), 0 -> (icmp ne x, 0) | (icmp ne y, 0)
+ if ((Predicate == ICmpInst::ICMP_EQ || Predicate == ICmpInst::ICMP_NE) &&
+ CE0->getOpcode() == Instruction::Or && Ops1->isNullValue()) {
+ Constant *LHS =
+ ConstantFoldCompareInstOperands(Predicate, CE0->getOperand(0), Ops1,TD);
+ Constant *RHS =
+ ConstantFoldCompareInstOperands(Predicate, CE0->getOperand(1), Ops1,TD);
+ unsigned OpC =
+ Predicate == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or;
+ Constant *Ops[] = { LHS, RHS };
+ return ConstantFoldInstOperands(OpC, LHS->getType(), Ops, 2, TD);
+ }
}
return ConstantExpr::getCompare(Predicate, Ops0, Ops1);
OpenPOWER on IntegriCloud