aboutsummaryrefslogtreecommitdiff
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
commit7cc4777a263f6a52877d29201311fde5f6edb632 (patch)
tree225ebd28ffc14b065f9219766a0b04766845036a
parentfd8c39b77331fbb6f994665b45eba1b2cc6ced6d (diff)
Implement support for long GEP indices on 32-bit archs and support for
int GEP indices on 64-bit archs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19354 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/SelectionDAG/LegalizeDAG.cpp1
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp17
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index cbc2aabc47..42f217a674 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -529,6 +529,7 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
break;
case ISD::ZERO_EXTEND:
case ISD::SIGN_EXTEND:
+ case ISD::TRUNCATE:
case ISD::FP_EXTEND:
case ISD::FP_ROUND:
switch (getTypeAction(Node->getOperand(0).getValueType())) {
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 4ba16f6d98..167d2f7e35 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/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);
}
}