On 64-bit targets, change 32-bit getelementptr indices to be 64-bit
getelementptr indices, inserting an explicit cast if necessary.
This helps expose the sign-extension operation to other optimizations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56133 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index f02a710..1cb4fa2 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -9795,7 +9795,8 @@
}
}
// If we are using a wider index than needed for this platform, shrink it
- // to what we need. If the incoming value needs a cast instruction,
+ // to what we need. If narrower, sign-extend it to what we need.
+ // If the incoming value needs a cast instruction,
// insert it. This explicit cast can make subsequent optimizations more
// obvious.
Value *Op = *i;
@@ -9809,6 +9810,16 @@
*i = Op;
MadeChange = true;
}
+ } else if (TD->getTypeSizeInBits(Op->getType()) < TD->getPointerSizeInBits()) {
+ if (Constant *C = dyn_cast<Constant>(Op)) {
+ *i = ConstantExpr::getSExt(C, TD->getIntPtrType());
+ MadeChange = true;
+ } else {
+ Op = InsertCastBefore(Instruction::SExt, Op, TD->getIntPtrType(),
+ GEP);
+ *i = Op;
+ MadeChange = true;
+ }
}
}
}