[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Oct 26 23:12:11 PDT 2005
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.394 -> 1.395
---
Log message:
Promote cases like cast (malloc sbyte, 100) to int* into
(malloc [25 x int]) directly without having to convert to
(malloc [100 x sbyte]) first.
---
Diffs of the changes: (+22 -1)
InstructionCombining.cpp | 23 ++++++++++++++++++++++-
1 files changed, 22 insertions(+), 1 deletion(-)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.394 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.395
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.394 Thu Oct 27 00:53:56 2005
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Thu Oct 27 01:12:00 2005
@@ -3826,7 +3826,28 @@
Amt = InsertNewInstBefore(Tmp, AI);
}
} else {
- return 0;
+ // See if we can satisfy the modulus by pulling a scale out of the array
+ // size argument.
+ unsigned ArraySizeScale = 1;
+ Value *NumElements = AI.getOperand(0);
+
+ if (ConstantUInt *CI = dyn_cast<ConstantUInt>(NumElements)) {
+ ArraySizeScale = CI->getValue();
+ NumElements = ConstantUInt::get(Type::UIntTy, 1);
+ }
+
+ // If we can now satisfy the modulus, by using a non-1 scale, we really can
+ // do the xform.
+ if ((AllocElTySize*ArraySizeScale) % CastElTySize != 0) return 0;
+
+ Amt = ConstantUInt::get(Type::UIntTy,
+ (AllocElTySize*ArraySizeScale)/CastElTySize);
+ if (ConstantUInt *CI = dyn_cast<ConstantUInt>(NumElements))
+ Amt = ConstantExpr::getMul(CI, cast<ConstantUInt>(Amt));
+ else {
+ Instruction *Tmp = BinaryOperator::createMul(Amt, NumElements, "tmp");
+ Amt = InsertNewInstBefore(Tmp, AI);
+ }
}
std::string Name = AI.getName(); AI.setName("");
More information about the llvm-commits
mailing list