[llvm-commits] CVS: llvm/lib/VMCore/ConstantHandling.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Aug 21 14:47:01 PDT 2003
Changes in directory llvm/lib/VMCore:
ConstantHandling.cpp updated: 1.34 -> 1.35
---
Log message:
Implement Assembler/2003-08-21-ConstantExprCast-Fold.llx
---
Diffs of the changes:
Index: llvm/lib/VMCore/ConstantHandling.cpp
diff -u llvm/lib/VMCore/ConstantHandling.cpp:1.34 llvm/lib/VMCore/ConstantHandling.cpp:1.35
--- llvm/lib/VMCore/ConstantHandling.cpp:1.34 Wed Aug 20 11:11:27 2003
+++ llvm/lib/VMCore/ConstantHandling.cpp Thu Aug 21 14:45:55 2003
@@ -95,6 +95,17 @@
if (S1 <= S2 && S2 >= S3 && S1 <= S3)
return ConstantExpr::getCast(Op, DestTy);
}
+ } else if (CE->getOpcode() == Instruction::GetElementPtr) {
+ // If all of the indexes in the GEP are null values, there is no pointer
+ // adjustment going on. We might as well cast the source pointer.
+ bool isAllNull = true;
+ for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
+ if (!CE->getOperand(i)->isNullValue()) {
+ isAllNull = false;
+ break;
+ }
+ if (isAllNull)
+ return ConstantExpr::getCast(CE->getOperand(0), DestTy);
}
return ConstRules::get(*V, *V)->castTo(V, DestTy);
@@ -137,9 +148,8 @@
(IdxList.size() == 1 && IdxList[0]->isNullValue()))
return const_cast<Constant*>(C);
- // If C is null and all idx's are null, return null of the right type.
+ // TODO If C is null and all idx's are null, return null of the right type.
- // FIXME: Implement folding of GEP constant exprs the same as instcombine does
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
// Combine Indices - If the source pointer to this getelementptr instruction
More information about the llvm-commits
mailing list