diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2006-12-23 06:05:41 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2006-12-23 06:05:41 +0000 |
commit | e4d87aa2de6e52952dca73716386db09aad5a8fd (patch) | |
tree | ce8c6e6ddc845de3585020c856118892f4206593 /lib/Transforms/Utils/Local.cpp | |
parent | add2bd7f5941537a97a41e037ae2277fbeed0b4f (diff) |
For PR950:
This patch removes the SetCC instructions and replaces them with the ICmp
and FCmp instructions. The SetCondInst instruction has been removed and
been replaced with ICmpInst and FCmpInst.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32751 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/Local.cpp')
-rw-r--r-- | lib/Transforms/Utils/Local.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index 366a95c49c..236ec4b8be 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -71,6 +71,7 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I) { case 2: Op1 = dyn_cast<Constant>(I->getOperand(1)); if (Op1 == 0) return 0; // Not a constant?, can't fold + /* FALL THROUGH */ case 1: Op0 = dyn_cast<Constant>(I->getOperand(0)); if (Op0 == 0) return 0; // Not a constant?, can't fold @@ -79,13 +80,14 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I) { } if (isa<BinaryOperator>(I) || isa<ShiftInst>(I)) { - if (Constant *Op0 = dyn_cast<Constant>(I->getOperand(0))) - if (Constant *Op1 = dyn_cast<Constant>(I->getOperand(1))) - return ConstantExpr::get(I->getOpcode(), Op0, Op1); - return 0; // Operands not constants. + return ConstantExpr::get(I->getOpcode(), Op0, Op1); + } else if (isa<ICmpInst>(I)) { + return ConstantExpr::getICmp(cast<ICmpInst>(I)->getPredicate(), Op0, Op1); + } else if (isa<FCmpInst>(I)) { + return ConstantExpr::getFCmp(cast<FCmpInst>(I)->getPredicate(), Op0, Op1); } - // Scan the operand list, checking to see if the are all constants, if so, + // Scan the operand list, checking to see if they are all constants, if so, // hand off to ConstantFoldInstOperands. std::vector<Constant*> Ops; for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) @@ -94,7 +96,7 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I) { else return 0; // All operands not constant! - return ConstantFoldInstOperands(I->getOpcode(), I->getType(), Ops); + return ConstantFoldInstOperands(I, Ops); } /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the @@ -103,9 +105,13 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I) { /// attempting to fold instructions like loads and stores, which have no /// constant expression form. /// -Constant *llvm::ConstantFoldInstOperands(unsigned Opc, const Type *DestTy, +Constant *llvm::ConstantFoldInstOperands(const Instruction* I, const std::vector<Constant*> &Ops) { - if (Opc >= Instruction::BinaryOpsBegin && Opc < Instruction::BinaryOpsEnd) + unsigned Opc = I->getOpcode(); + const Type *DestTy = I->getType(); + + // Handle easy binops first + if (isa<BinaryOperator>(I)) return ConstantExpr::get(Opc, Ops[0], Ops[1]); switch (Opc) { @@ -118,6 +124,10 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opc, const Type *DestTy, } } return 0; + case Instruction::ICmp: + case Instruction::FCmp: + return ConstantExpr::getCompare(cast<CmpInst>(I)->getPredicate(), Ops[0], + Ops[1]); case Instruction::Shl: case Instruction::LShr: case Instruction::AShr: @@ -257,8 +267,8 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB) { } else if (SI->getNumSuccessors() == 2) { // Otherwise, we can fold this switch into a conditional branch // instruction if it has only one non-default destination. - Value *Cond = new SetCondInst(Instruction::SetEQ, SI->getCondition(), - SI->getSuccessorValue(1), "cond", SI); + Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, SI->getCondition(), + SI->getSuccessorValue(1), "cond", SI); // Insert the new branch... new BranchInst(SI->getSuccessor(1), SI->getSuccessor(0), Cond, SI); |