summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-12-23 06:05:41 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-12-23 06:05:41 +0000
commite4d87aa2de6e52952dca73716386db09aad5a8fd (patch)
treece8c6e6ddc845de3585020c856118892f4206593 /lib/Transforms/Utils
parentadd2bd7f5941537a97a41e037ae2277fbeed0b4f (diff)
downloadllvm-e4d87aa2de6e52952dca73716386db09aad5a8fd.tar.gz
llvm-e4d87aa2de6e52952dca73716386db09aad5a8fd.tar.bz2
llvm-e4d87aa2de6e52952dca73716386db09aad5a8fd.tar.xz
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')
-rw-r--r--lib/Transforms/Utils/CloneFunction.cpp12
-rw-r--r--lib/Transforms/Utils/Local.cpp30
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp12
-rw-r--r--lib/Transforms/Utils/LowerSwitch.cpp7
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp49
5 files changed, 63 insertions, 47 deletions
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
index 3aa7397ef9..896c39943c 100644
--- a/lib/Transforms/Utils/CloneFunction.cpp
+++ b/lib/Transforms/Utils/CloneFunction.cpp
@@ -278,7 +278,15 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB) {
/// mapping its operands through ValueMap if they are available.
Constant *PruningFunctionCloner::
ConstantFoldMappedInstruction(const Instruction *I) {
- if (isa<BinaryOperator>(I) || isa<ShiftInst>(I)) {
+ if (isa<CmpInst>(I)) {
+ if (Constant *Op0 = dyn_cast_or_null<Constant>(MapValue(I->getOperand(0),
+ ValueMap)))
+ if (Constant *Op1 = dyn_cast_or_null<Constant>(MapValue(I->getOperand(1),
+ ValueMap)))
+ return ConstantExpr::getCompare(cast<CmpInst>(I)->getPredicate(), Op0,
+ Op1);
+ return 0;
+ } else if (isa<BinaryOperator>(I) || isa<ShiftInst>(I)) {
if (Constant *Op0 = dyn_cast_or_null<Constant>(MapValue(I->getOperand(0),
ValueMap)))
if (Constant *Op1 = dyn_cast_or_null<Constant>(MapValue(I->getOperand(1),
@@ -295,7 +303,7 @@ ConstantFoldMappedInstruction(const Instruction *I) {
else
return 0; // All operands not constant!
- return ConstantFoldInstOperands(I->getOpcode(), I->getType(), Ops);
+ return ConstantFoldInstOperands(I, Ops);
}
/// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto,
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);
diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp
index e4117d5874..361388c7bf 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -517,9 +517,9 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
EntryBB->getTerminator());
// Compare the return value to zero.
- Value *IsNormal = BinaryOperator::createSetEQ(SJRet,
- Constant::getNullValue(SJRet->getType()),
- "notunwind", EntryBB->getTerminator());
+ Value *IsNormal = new ICmpInst(ICmpInst::ICMP_EQ, SJRet,
+ Constant::getNullValue(SJRet->getType()),
+ "notunwind", EntryBB->getTerminator());
// Nuke the uncond branch.
EntryBB->getTerminator()->eraseFromParent();
@@ -551,9 +551,9 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
}
// Load the JBList, if it's null, then there was no catch!
- Value *NotNull = BinaryOperator::createSetNE(BufPtr,
- Constant::getNullValue(BufPtr->getType()),
- "notnull", UnwindHandler);
+ Value *NotNull = new ICmpInst(ICmpInst::ICMP_NE, BufPtr,
+ Constant::getNullValue(BufPtr->getType()),
+ "notnull", UnwindHandler);
new BranchInst(UnwindBlock, TermBlock, NotNull, UnwindHandler);
// Create the block to do the longjmp.
diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp
index 69df51c792..b2974a98c8 100644
--- a/lib/Transforms/Utils/LowerSwitch.cpp
+++ b/lib/Transforms/Utils/LowerSwitch.cpp
@@ -143,8 +143,7 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End,
BasicBlock* NewNode = new BasicBlock("NodeBlock");
F->getBasicBlockList().insert(OrigBlock->getNext(), NewNode);
- SetCondInst* Comp = new SetCondInst(Instruction::SetLT, Val, Pivot.first,
- "Pivot");
+ ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_ULT, Val, Pivot.first, "Pivot");
NewNode->getInstList().push_back(Comp);
new BranchInst(LBranch, RBranch, Comp, NewNode);
return NewNode;
@@ -165,8 +164,8 @@ BasicBlock* LowerSwitch::newLeafBlock(Case& Leaf, Value* Val,
F->getBasicBlockList().insert(OrigBlock->getNext(), NewLeaf);
// Make the seteq instruction...
- SetCondInst* Comp = new SetCondInst(Instruction::SetEQ, Val,
- Leaf.first, "SwitchLeaf");
+ ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_EQ, Val,
+ Leaf.first, "SwitchLeaf");
NewLeaf->getInstList().push_back(Comp);
// Make the conditional branch...
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 8d4cb83e17..b44ab09362 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -369,12 +369,8 @@ static bool DominatesMergePoint(Value *V, BasicBlock *BB,
case Instruction::Shl:
case Instruction::LShr:
case Instruction::AShr:
- case Instruction::SetEQ:
- case Instruction::SetNE:
- case Instruction::SetLT:
- case Instruction::SetGT:
- case Instruction::SetLE:
- case Instruction::SetGE:
+ case Instruction::ICmp:
+ case Instruction::FCmp:
break; // These are all cheap and non-trapping instructions.
}
@@ -390,12 +386,13 @@ static bool DominatesMergePoint(Value *V, BasicBlock *BB,
return true;
}
-// GatherConstantSetEQs - Given a potentially 'or'd together collection of seteq
-// instructions that compare a value against a constant, return the value being
-// compared, and stick the constant into the Values vector.
+// GatherConstantSetEQs - Given a potentially 'or'd together collection of
+// icmp_eq instructions that compare a value against a constant, return the
+// value being compared, and stick the constant into the Values vector.
static Value *GatherConstantSetEQs(Value *V, std::vector<ConstantInt*> &Values){
if (Instruction *Inst = dyn_cast<Instruction>(V))
- if (Inst->getOpcode() == Instruction::SetEQ) {
+ if (Inst->getOpcode() == Instruction::ICmp &&
+ cast<ICmpInst>(Inst)->getPredicate() == ICmpInst::ICMP_EQ) {
if (ConstantInt *C = dyn_cast<ConstantInt>(Inst->getOperand(1))) {
Values.push_back(C);
return Inst->getOperand(0);
@@ -417,7 +414,8 @@ static Value *GatherConstantSetEQs(Value *V, std::vector<ConstantInt*> &Values){
// being compared, and stick the constant into the Values vector.
static Value *GatherConstantSetNEs(Value *V, std::vector<ConstantInt*> &Values){
if (Instruction *Inst = dyn_cast<Instruction>(V))
- if (Inst->getOpcode() == Instruction::SetNE) {
+ if (Inst->getOpcode() == Instruction::ICmp &&
+ cast<ICmpInst>(Inst)->getPredicate() == ICmpInst::ICMP_NE) {
if (ConstantInt *C = dyn_cast<ConstantInt>(Inst->getOperand(1))) {
Values.push_back(C);
return Inst->getOperand(0);
@@ -503,11 +501,11 @@ static Value *isValueEqualityComparison(TerminatorInst *TI) {
}
if (BranchInst *BI = dyn_cast<BranchInst>(TI))
if (BI->isConditional() && BI->getCondition()->hasOneUse())
- if (SetCondInst *SCI = dyn_cast<SetCondInst>(BI->getCondition()))
- if ((SCI->getOpcode() == Instruction::SetEQ ||
- SCI->getOpcode() == Instruction::SetNE) &&
- isa<ConstantInt>(SCI->getOperand(1)))
- return SCI->getOperand(0);
+ if (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition()))
+ if ((ICI->getPredicate() == ICmpInst::ICMP_EQ ||
+ ICI->getPredicate() == ICmpInst::ICMP_NE) &&
+ isa<ConstantInt>(ICI->getOperand(1)))
+ return ICI->getOperand(0);
return 0;
}
@@ -525,11 +523,11 @@ GetValueEqualityComparisonCases(TerminatorInst *TI,
}
BranchInst *BI = cast<BranchInst>(TI);
- SetCondInst *SCI = cast<SetCondInst>(BI->getCondition());
- Cases.push_back(std::make_pair(cast<ConstantInt>(SCI->getOperand(1)),
- BI->getSuccessor(SCI->getOpcode() ==
- Instruction::SetNE)));
- return BI->getSuccessor(SCI->getOpcode() == Instruction::SetEQ);
+ ICmpInst *ICI = cast<ICmpInst>(BI->getCondition());
+ Cases.push_back(std::make_pair(cast<ConstantInt>(ICI->getOperand(1)),
+ BI->getSuccessor(ICI->getPredicate() ==
+ ICmpInst::ICMP_NE)));
+ return BI->getSuccessor(ICI->getPredicate() == ICmpInst::ICMP_EQ);
}
@@ -847,8 +845,8 @@ static bool HoistThenElseCodeToIf(BranchInst *BI) {
BasicBlock *BB2 = BI->getSuccessor(1); // The false destination
Instruction *I1 = BB1->begin(), *I2 = BB2->begin();
- if (I1->getOpcode() != I2->getOpcode() || !I1->isIdenticalTo(I2) ||
- isa<PHINode>(I1) || isa<InvokeInst>(I1))
+ if (I1->getOpcode() != I2->getOpcode() || isa<PHINode>(I1) ||
+ isa<InvokeInst>(I1) || !I1->isIdenticalTo(I2))
return false;
// If we get here, we can hoist at least one instruction.
@@ -1443,8 +1441,9 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
// predecessor and use logical operations to pick the right destination.
BasicBlock *TrueDest = BI->getSuccessor(0);
BasicBlock *FalseDest = BI->getSuccessor(1);
- if (BinaryOperator *Cond = dyn_cast<BinaryOperator>(BI->getCondition()))
- if (Cond->getParent() == BB && &BB->front() == Cond &&
+ if (Instruction *Cond = dyn_cast<Instruction>(BI->getCondition()))
+ if ((isa<CmpInst>(Cond) || isa<BinaryOperator>(Cond)) &&
+ Cond->getParent() == BB && &BB->front() == Cond &&
Cond->getNext() == BI && Cond->hasOneUse() &&
TrueDest != BB && FalseDest != BB)
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI!=E; ++PI)