aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-10-23 17:57:43 +0000
committerDan Gohman <gohman@apple.com>2009-10-23 17:57:43 +0000
commit6530ae50de6d78e90f499b67ee9db01da894ff4a (patch)
tree2d81c7ee2eaabbabf5c2b107324fb9a9621ab478 /lib
parentaf1c05ad386e69449b53582da8f2b94c044e57db (diff)
downloadexternal_llvm-6530ae50de6d78e90f499b67ee9db01da894ff4a.tar.gz
external_llvm-6530ae50de6d78e90f499b67ee9db01da894ff4a.tar.bz2
external_llvm-6530ae50de6d78e90f499b67ee9db01da894ff4a.zip
APInt-ify the gep scaling code, so that it correctly handles the case where
the scale overflows pointer-sized arithmetic. This fixes PR5281. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84954 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
index adcc532272..d862e40603 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
@@ -2666,7 +2666,8 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
}
// N = N + Idx * ElementSize;
- uint64_t ElementSize = TD->getTypeAllocSize(Ty);
+ APInt ElementSize = APInt(TLI.getPointerTy().getSizeInBits(),
+ TD->getTypeAllocSize(Ty));
SDValue IdxN = getValue(Idx);
// If the index is smaller or larger than intptr_t, truncate or extend
@@ -2676,13 +2677,13 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
// If this is a multiply by a power of two, turn it into a shl
// immediately. This is a very common case.
if (ElementSize != 1) {
- if (isPowerOf2_64(ElementSize)) {
- unsigned Amt = Log2_64(ElementSize);
+ if (ElementSize.isPowerOf2()) {
+ unsigned Amt = ElementSize.logBase2();
IdxN = DAG.getNode(ISD::SHL, getCurDebugLoc(),
N.getValueType(), IdxN,
DAG.getConstant(Amt, TLI.getPointerTy()));
} else {
- SDValue Scale = DAG.getIntPtrConstant(ElementSize);
+ SDValue Scale = DAG.getConstant(ElementSize, TLI.getPointerTy());
IdxN = DAG.getNode(ISD::MUL, getCurDebugLoc(),
N.getValueType(), IdxN, Scale);
}