[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri Oct 28 20:20:05 PDT 2005
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.399 -> 1.400
---
Log message:
Remove a special case, allowing the general case to handle it. No functionality
change.
---
Diffs of the changes: (+37 -49)
InstructionCombining.cpp | 86 ++++++++++++++++++++---------------------------
1 files changed, 37 insertions(+), 49 deletions(-)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.399 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.400
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.399 Fri Oct 28 11:27:35 2005
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Oct 28 22:19:53 2005
@@ -3814,59 +3814,47 @@
uint64_t CastElTySize = TD->getTypeSize(CastElTy);
if (CastElTySize == 0 || AllocElTySize == 0) return 0;
- // If the allocation is for an even multiple of the cast type size
+ // 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);
+ } else if (ShiftInst *SI = dyn_cast<ShiftInst>(NumElements)) {
+ if (SI->getOpcode() == Instruction::Shl)
+ if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(SI->getOperand(1))) {
+ // This is a value scaled by '1 << the shift amt'.
+ NumElements = SI->getOperand(0);
+ ArraySizeScale = 1U << CUI->getValue();
+ }
+ } else if (isa<Instruction>(NumElements) &&
+ cast<Instruction>(NumElements)->getOpcode() == Instruction::Mul){
+ BinaryOperator *BO = cast<BinaryOperator>(NumElements);
+ if (ConstantUInt *Scale = dyn_cast<ConstantUInt>(BO->getOperand(1))) {
+ // This value is scaled by 'Scale'.
+ NumElements = BO->getOperand(0);
+ ArraySizeScale = Scale->getValue();
+ }
+ }
+
+ // 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;
+
+ unsigned Scale = (AllocElTySize*ArraySizeScale)/CastElTySize;
Value *Amt = 0;
- if (AllocElTySize % CastElTySize == 0) {
- Amt = ConstantUInt::get(Type::UIntTy, AllocElTySize/CastElTySize);
- if (ConstantUInt *CI = dyn_cast<ConstantUInt>(AI.getOperand(0)))
+ if (Scale == 1) {
+ Amt = NumElements;
+ } else {
+ Amt = ConstantUInt::get(Type::UIntTy, Scale);
+ if (ConstantUInt *CI = dyn_cast<ConstantUInt>(NumElements))
Amt = ConstantExpr::getMul(CI, cast<ConstantUInt>(Amt));
- else {
- // Perform an explicit scale.
- Instruction *Tmp = BinaryOperator::createMul(Amt, AI.getOperand(0),"tmp");
+ else if (Scale != 1) {
+ Instruction *Tmp = BinaryOperator::createMul(Amt, NumElements, "tmp");
Amt = InsertNewInstBefore(Tmp, AI);
}
- } else {
- // 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);
- } else if (ShiftInst *SI = dyn_cast<ShiftInst>(NumElements)) {
- if (SI->getOpcode() == Instruction::Shl)
- if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(SI->getOperand(1))) {
- // This is a value scaled by '1 << the shift amt'.
- NumElements = SI->getOperand(0);
- ArraySizeScale = 1U << CUI->getValue();
- }
- } else if (isa<Instruction>(NumElements) &&
- cast<Instruction>(NumElements)->getOpcode() == Instruction::Mul){
- BinaryOperator *BO = cast<BinaryOperator>(NumElements);
- if (ConstantUInt *Scale = dyn_cast<ConstantUInt>(BO->getOperand(1))) {
- // This value is scaled by 'Scale'.
- NumElements = BO->getOperand(0);
- ArraySizeScale = Scale->getValue();
- }
- }
-
- // 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;
-
- unsigned Scale = (AllocElTySize*ArraySizeScale)/CastElTySize;
- if (Scale == 1) {
- Amt = NumElements;
- } else {
- Amt = ConstantUInt::get(Type::UIntTy, Scale);
- if (ConstantUInt *CI = dyn_cast<ConstantUInt>(NumElements))
- Amt = ConstantExpr::getMul(CI, cast<ConstantUInt>(Amt));
- else if (Scale != 1) {
- 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