[llvm-commits] CVS: llvm/lib/Transforms/Utils/CloneFunction.cpp Local.cpp LowerInvoke.cpp LowerSwitch.cpp SimplifyCFG.cpp
Reid Spencer
reid at x10sys.com
Fri Dec 22 22:07:00 PST 2006
Changes in directory llvm/lib/Transforms/Utils:
CloneFunction.cpp updated: 1.33 -> 1.34
Local.cpp updated: 1.62 -> 1.63
LowerInvoke.cpp updated: 1.47 -> 1.48
LowerSwitch.cpp updated: 1.30 -> 1.31
SimplifyCFG.cpp updated: 1.107 -> 1.108
---
Log message:
For PR950: http://llvm.org/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.
---
Diffs of the changes: (+63 -47)
CloneFunction.cpp | 12 ++++++++++--
Local.cpp | 30 ++++++++++++++++++++----------
LowerInvoke.cpp | 12 ++++++------
LowerSwitch.cpp | 7 +++----
SimplifyCFG.cpp | 49 ++++++++++++++++++++++++-------------------------
5 files changed, 63 insertions(+), 47 deletions(-)
Index: llvm/lib/Transforms/Utils/CloneFunction.cpp
diff -u llvm/lib/Transforms/Utils/CloneFunction.cpp:1.33 llvm/lib/Transforms/Utils/CloneFunction.cpp:1.34
--- llvm/lib/Transforms/Utils/CloneFunction.cpp:1.33 Sun Nov 5 13:31:28 2006
+++ llvm/lib/Transforms/Utils/CloneFunction.cpp Sat Dec 23 00:05:41 2006
@@ -278,7 +278,15 @@
/// 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 @@
else
return 0; // All operands not constant!
- return ConstantFoldInstOperands(I->getOpcode(), I->getType(), Ops);
+ return ConstantFoldInstOperands(I, Ops);
}
/// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto,
Index: llvm/lib/Transforms/Utils/Local.cpp
diff -u llvm/lib/Transforms/Utils/Local.cpp:1.62 llvm/lib/Transforms/Utils/Local.cpp:1.63
--- llvm/lib/Transforms/Utils/Local.cpp:1.62 Sun Nov 26 19:05:10 2006
+++ llvm/lib/Transforms/Utils/Local.cpp Sat Dec 23 00:05:41 2006
@@ -71,6 +71,7 @@
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 @@
}
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 @@
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 @@
/// 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 @@
}
}
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 @@
} 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);
Index: llvm/lib/Transforms/Utils/LowerInvoke.cpp
diff -u llvm/lib/Transforms/Utils/LowerInvoke.cpp:1.47 llvm/lib/Transforms/Utils/LowerInvoke.cpp:1.48
--- llvm/lib/Transforms/Utils/LowerInvoke.cpp:1.47 Tue Dec 19 16:17:40 2006
+++ llvm/lib/Transforms/Utils/LowerInvoke.cpp Sat Dec 23 00:05:41 2006
@@ -517,9 +517,9 @@
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 @@
}
// 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.
Index: llvm/lib/Transforms/Utils/LowerSwitch.cpp
diff -u llvm/lib/Transforms/Utils/LowerSwitch.cpp:1.30 llvm/lib/Transforms/Utils/LowerSwitch.cpp:1.31
--- llvm/lib/Transforms/Utils/LowerSwitch.cpp:1.30 Tue Dec 19 16:17:40 2006
+++ llvm/lib/Transforms/Utils/LowerSwitch.cpp Sat Dec 23 00:05:41 2006
@@ -143,8 +143,7 @@
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 @@
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...
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.107 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.108
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.107 Sun Nov 26 19:05:10 2006
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Sat Dec 23 00:05:41 2006
@@ -369,12 +369,8 @@
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 @@
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 @@
// 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 @@
}
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 @@
}
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 @@
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 @@
// 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)
More information about the llvm-commits
mailing list