diff options
author | Dan Gohman <gohman@apple.com> | 2009-10-23 17:57:43 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-10-23 17:57:43 +0000 |
commit | 4ef112be6270f04fa7966288c990d95ec43c62fd (patch) | |
tree | 7b9f3f6a10c833598f7a5cfd43c4eda01da2c406 /llvm/lib | |
parent | 24e7cb6f2604bfa56cde4d7adf88202e001d9d0d (diff) | |
download | bcm5719-llvm-4ef112be6270f04fa7966288c990d95ec43c62fd.tar.gz bcm5719-llvm-4ef112be6270f04fa7966288c990d95ec43c62fd.zip |
APInt-ify the gep scaling code, so that it correctly handles the case where
the scale overflows pointer-sized arithmetic. This fixes PR5281.
llvm-svn: 84954
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index adcc5322721..d862e406031 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/llvm/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); } |