[llvm-commits] CVS: llvm/lib/Transforms/Utils/Local.cpp LowerAllocations.cpp LowerInvoke.cpp SimplifyCFG.cpp
Reid Spencer
reid at x10sys.com
Sun Nov 26 17:06:26 PST 2006
Changes in directory llvm/lib/Transforms/Utils:
Local.cpp updated: 1.61 -> 1.62
LowerAllocations.cpp updated: 1.62 -> 1.63
LowerInvoke.cpp updated: 1.43 -> 1.44
SimplifyCFG.cpp updated: 1.106 -> 1.107
---
Log message:
For PR950: http://llvm.org/PR950 :
The long awaited CAST patch. This introduces 12 new instructions into LLVM
to replace the cast instruction. Corresponding changes throughout LLVM are
provided. This passes llvm-test, llvm/test, and SPEC CPUINT2000 with the
exception of 175.vpr which fails only on a slight floating point output
difference.
---
Diffs of the changes: (+32 -16)
Local.cpp | 15 +++++++++++++--
LowerAllocations.cpp | 14 +++++++++-----
LowerInvoke.cpp | 14 ++++++++++----
SimplifyCFG.cpp | 5 -----
4 files changed, 32 insertions(+), 16 deletions(-)
Index: llvm/lib/Transforms/Utils/Local.cpp
diff -u llvm/lib/Transforms/Utils/Local.cpp:1.61 llvm/lib/Transforms/Utils/Local.cpp:1.62
--- llvm/lib/Transforms/Utils/Local.cpp:1.61 Wed Nov 8 13:16:44 2006
+++ llvm/lib/Transforms/Utils/Local.cpp Sun Nov 26 19:05:10 2006
@@ -122,8 +122,19 @@
case Instruction::LShr:
case Instruction::AShr:
return ConstantExpr::get(Opc, Ops[0], Ops[1]);
- case Instruction::Cast:
- return ConstantExpr::getCast(Ops[0], DestTy);
+ case Instruction::Trunc:
+ case Instruction::ZExt:
+ case Instruction::SExt:
+ case Instruction::FPTrunc:
+ case Instruction::FPExt:
+ case Instruction::UIToFP:
+ case Instruction::SIToFP:
+ case Instruction::FPToUI:
+ case Instruction::FPToSI:
+ case Instruction::PtrToInt:
+ case Instruction::IntToPtr:
+ case Instruction::BitCast:
+ return ConstantExpr::getCast(Opc, Ops[0], DestTy);
case Instruction::Select:
return ConstantExpr::getSelect(Ops[0], Ops[1], Ops[2]);
case Instruction::ExtractElement:
Index: llvm/lib/Transforms/Utils/LowerAllocations.cpp
diff -u llvm/lib/Transforms/Utils/LowerAllocations.cpp:1.62 llvm/lib/Transforms/Utils/LowerAllocations.cpp:1.63
--- llvm/lib/Transforms/Utils/LowerAllocations.cpp:1.62 Fri Oct 20 02:07:24 2006
+++ llvm/lib/Transforms/Utils/LowerAllocations.cpp Sun Nov 26 19:05:10 2006
@@ -134,7 +134,7 @@
} else {
Value *Scale = MI->getOperand(0);
if (Scale->getType() != IntPtrTy)
- Scale = new CastInst(Scale, IntPtrTy, "", I);
+ Scale = CastInst::createInferredCast(Scale, IntPtrTy, "", I);
// Multiply it by the array size if necessary...
MallocArg = BinaryOperator::create(Instruction::Mul, Scale,
@@ -148,10 +148,13 @@
if (MallocFTy->getNumParams() > 0 || MallocFTy->isVarArg()) {
if (MallocFTy->isVarArg()) {
if (MallocArg->getType() != IntPtrTy)
- MallocArg = new CastInst(MallocArg, IntPtrTy, "", I);
+ MallocArg = CastInst::createInferredCast(MallocArg, IntPtrTy, "",
+ I);
} else if (MallocFTy->getNumParams() > 0 &&
MallocFTy->getParamType(0) != Type::UIntTy)
- MallocArg = new CastInst(MallocArg, MallocFTy->getParamType(0), "",I);
+ MallocArg =
+ CastInst::createInferredCast(MallocArg, MallocFTy->getParamType(0),
+ "",I);
MallocArgs.push_back(MallocArg);
}
@@ -166,7 +169,7 @@
// Create a cast instruction to convert to the right type...
Value *MCast;
if (MCall->getType() != Type::VoidTy)
- MCast = new CastInst(MCall, MI->getType(), "", I);
+ MCast = CastInst::createInferredCast(MCall, MI->getType(), "", I);
else
MCast = Constant::getNullValue(MI->getType());
@@ -183,7 +186,8 @@
Value *MCast = FI->getOperand(0);
if (FreeFTy->getNumParams() > 0 &&
FreeFTy->getParamType(0) != MCast->getType())
- MCast = new CastInst(MCast, FreeFTy->getParamType(0), "", I);
+ MCast = CastInst::createInferredCast(MCast, FreeFTy->getParamType(0),
+ "", I);
FreeArgs.push_back(MCast);
}
Index: llvm/lib/Transforms/Utils/LowerInvoke.cpp
diff -u llvm/lib/Transforms/Utils/LowerInvoke.cpp:1.43 llvm/lib/Transforms/Utils/LowerInvoke.cpp:1.44
--- llvm/lib/Transforms/Utils/LowerInvoke.cpp:1.43 Thu Nov 2 14:25:50 2006
+++ llvm/lib/Transforms/Utils/LowerInvoke.cpp Sun Nov 26 19:05:10 2006
@@ -326,7 +326,7 @@
Function *F = Invokes.back()->getParent()->getParent();
// To avoid having to handle incoming arguments specially, we lower each arg
- // to a copy instruction in the entry block. This ensure that the argument
+ // to a copy instruction in the entry block. This ensures that the argument
// value itself cannot be live across the entry block.
BasicBlock::iterator AfterAllocaInsertPt = F->begin()->begin();
while (isa<AllocaInst>(AfterAllocaInsertPt) &&
@@ -334,10 +334,16 @@
++AfterAllocaInsertPt;
for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end();
AI != E; ++AI) {
- CastInst *NC = new CastInst(AI, AI->getType(), AI->getName()+".tmp",
- AfterAllocaInsertPt);
+ // This is always a no-op cast because we're casting AI to AI->getType() so
+ // src and destination types are identical. BitCast is the only possibility.
+ CastInst *NC = new BitCastInst(
+ AI, AI->getType(), AI->getName()+".tmp", AfterAllocaInsertPt);
AI->replaceAllUsesWith(NC);
- NC->setOperand(0, AI);
+ // Normally its is forbidden to replace a CastInst's operand because it
+ // could cause the opcode to reflect an illegal conversion. However, we're
+ // replacing it here with the same value it was constructed with to simply
+ // make NC its user.
+ NC->setOperand(0, AI);
}
// Finally, scan the code looking for instructions with bad live ranges.
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.106 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.107
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.106 Sun Nov 26 04:17:54 2006
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Sun Nov 26 19:05:10 2006
@@ -425,11 +425,6 @@
Values.push_back(C);
return Inst->getOperand(1);
}
- } else if (Inst->getOpcode() == Instruction::Cast) {
- // Cast of X to bool is really a comparison against zero.
- assert(Inst->getType() == Type::BoolTy && "Can only handle bool values!");
- Values.push_back(ConstantInt::get(Inst->getOperand(0)->getType(), 0));
- return Inst->getOperand(0);
} else if (Inst->getOpcode() == Instruction::And) {
if (Value *LHS = GatherConstantSetNEs(Inst->getOperand(0), Values))
if (Value *RHS = GatherConstantSetNEs(Inst->getOperand(1), Values))
More information about the llvm-commits
mailing list