summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-01-07 21:56:57 +0000
committerChris Lattner <sabre@nondot.org>2005-01-07 21:56:57 +0000
commit19a83990e1e0d9fb9a1a61e11b95eb04770a4cc9 (patch)
tree816367ad6f8cb3881a06cc8e6efe3d107965c5fc /llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
parent4d5ba992839a0ff67c0a9dc67337fa212973ccf4 (diff)
downloadbcm5719-llvm-19a83990e1e0d9fb9a1a61e11b95eb04770a4cc9.tar.gz
bcm5719-llvm-19a83990e1e0d9fb9a1a61e11b95eb04770a4cc9.zip
Implement support for long GEP indices on 32-bit archs and support for
int GEP indices on 64-bit archs. llvm-svn: 19354
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 4ba16f6d982..167d2f7e359 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -477,9 +477,20 @@ void SelectionDAGLowering::visitGetElementPtr(User &I) {
if (!isa<Constant>(Idx) || !cast<Constant>(Idx)->isNullValue()) {
// N = N + Idx * ElementSize;
uint64_t ElementSize = TD.getTypeSize(Ty);
- SDOperand IdxN = getValue(Idx);
- IdxN = DAG.getNode(ISD::MUL, N.getValueType(), IdxN,
- getIntPtrConstant(ElementSize));
+ SDOperand IdxN = getValue(Idx), Scale = getIntPtrConstant(ElementSize);
+
+ // If the index is smaller or larger than intptr_t, truncate or extend
+ // it.
+ if (IdxN.getValueType() < Scale.getValueType()) {
+ if (Idx->getType()->isSigned())
+ IdxN = DAG.getNode(ISD::SIGN_EXTEND, Scale.getValueType(), IdxN);
+ else
+ IdxN = DAG.getNode(ISD::ZERO_EXTEND, Scale.getValueType(), IdxN);
+ } else if (IdxN.getValueType() > Scale.getValueType())
+ IdxN = DAG.getNode(ISD::TRUNCATE, Scale.getValueType(), IdxN);
+
+ IdxN = DAG.getNode(ISD::MUL, N.getValueType(), IdxN, Scale);
+
N = DAG.getNode(ISD::ADD, N.getValueType(), N, IdxN);
}
}
OpenPOWER on IntegriCloud