summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2009-02-09 20:54:38 +0000
committerEvan Cheng <evan.cheng@apple.com>2009-02-09 20:54:38 +0000
commit020588cee38380c9c4797244b1ce88c4409ee223 (patch)
treee9cf21b6654ec3c88b029b5cee22f3cd4f21b95a /llvm/lib/CodeGen
parentd7b4f40b184760843d3903a79a93621c3a958be4 (diff)
downloadbcm5719-llvm-020588cee38380c9c4797244b1ce88c4409ee223.tar.gz
bcm5719-llvm-020588cee38380c9c4797244b1ce88c4409ee223.zip
Make sure constant subscript is truncated to ptr size if it may not fit.
llvm-svn: 64163
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
index 3c90cd767ce..7b613d7f242 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
@@ -2699,8 +2699,15 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
if (CI->getZExtValue() == 0) continue;
uint64_t Offs =
TD->getTypePaddedSize(Ty)*cast<ConstantInt>(CI)->getSExtValue();
+ SDValue OffsVal = DAG.getConstant(Offs, MVT::i64);
+ unsigned PtrBits = TLI.getPointerTy().getSizeInBits();
+ if (PtrBits < 64)
+ OffsVal = DAG.getNode(ISD::TRUNCATE, getCurDebugLoc(),
+ TLI.getPointerTy(), OffsVal);
+ else
+ OffsVal = DAG.getIntPtrConstant(Offs);
N = DAG.getNode(ISD::ADD, getCurDebugLoc(), N.getValueType(), N,
- DAG.getIntPtrConstant(Offs));
+ OffsVal);
continue;
}
OpenPOWER on IntegriCloud