diff options
author | Chris Lattner <sabre@nondot.org> | 2003-05-27 19:16:07 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-05-27 19:16:07 +0000 |
commit | 5c38e99c59b8f9846a3fddb6c18c94a47717de02 (patch) | |
tree | c8cd4ae1c6cfe4586d568666a84d06279e696027 /lib/VMCore/ConstantFold.cpp | |
parent | 6ac79d115ec472c60aa57e2beae06a4a4a1fd8d8 (diff) |
Fix constant folding to ALWAYS work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6355 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index d5f98bd201..7644c1e419 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -6,6 +6,7 @@ #include "llvm/ConstantHandling.h" #include "llvm/iPHINode.h" +#include "llvm/InstrTypes.h" #include "llvm/DerivedTypes.h" #include <cmath> @@ -45,26 +46,15 @@ Constant *ConstantFoldInstruction(Instruction *I) { } } + if (isa<BinaryOperator>(I)) + return ConstantExpr::get(I->getOpcode(), Op0, Op1); + switch (I->getOpcode()) { case Instruction::Cast: - return ConstRules::get(*Op0, *Op0)->castTo(Op0, I->getType()); - case Instruction::Add: return *Op0 + *Op1; - case Instruction::Sub: return *Op0 - *Op1; - case Instruction::Mul: return *Op0 * *Op1; - case Instruction::Div: return *Op0 / *Op1; - case Instruction::Rem: return *Op0 % *Op1; - case Instruction::And: return *Op0 & *Op1; - case Instruction::Or: return *Op0 | *Op1; - case Instruction::Xor: return *Op0 ^ *Op1; - - case Instruction::SetEQ: return *Op0 == *Op1; - case Instruction::SetNE: return *Op0 != *Op1; - case Instruction::SetLE: return *Op0 <= *Op1; - case Instruction::SetGE: return *Op0 >= *Op1; - case Instruction::SetLT: return *Op0 < *Op1; - case Instruction::SetGT: return *Op0 > *Op1; - case Instruction::Shl: return *Op0 << *Op1; - case Instruction::Shr: return *Op0 >> *Op1; + return ConstantExpr::getCast(Op0, I->getType()); + case Instruction::Shl: + case Instruction::Shr: + return ConstantExpr::getShift(I->getOpcode(), Op0, Op1); case Instruction::GetElementPtr: { std::vector<Constant*> IdxList; IdxList.reserve(I->getNumOperands()-1); @@ -74,7 +64,7 @@ Constant *ConstantFoldInstruction(Instruction *I) { IdxList.push_back(C); else return 0; // Non-constant operand - return ConstantFoldGetElementPtr(Op0, IdxList); + return ConstantExpr::getGetElementPtr(Op0, IdxList); } default: return 0; |