aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNate Begeman <natebegeman@mac.com>2005-10-12 23:18:53 +0000
committerNate Begeman <natebegeman@mac.com>2005-10-12 23:18:53 +0000
commit765784ad760ee6cc504d79e4966c272387c313f8 (patch)
treee0f651e36f6f372cef2cbebae9c9f0cc15fc68cd /lib
parent3df4d525c58d5db878eaadcfdcffbbfca96dd6a2 (diff)
downloadexternal_llvm-765784ad760ee6cc504d79e4966c272387c313f8.zip
external_llvm-765784ad760ee6cc504d79e4966c272387c313f8.tar.gz
external_llvm-765784ad760ee6cc504d79e4966c272387c313f8.tar.bz2
Fix a potential bug with two combine-to's back to back that chris pointed
out, where after the first CombineTo() call, the node the second CombineTo wishes to replace may no longer exist. Fix a very real bug with the truncated load optimization on little endian targets, which do not need a byte offset added to the load. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23704 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/SelectionDAG/DAGCombiner.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index d5dbf3c..e254811 100644
--- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -1194,13 +1194,17 @@ SDOperand DAGCombiner::visitSIGN_EXTEND(SDNode *N) {
// fold (sext (sext x)) -> (sext x)
if (N0.getOpcode() == ISD::SIGN_EXTEND)
return DAG.getNode(ISD::SIGN_EXTEND, VT, N0.getOperand(0));
+ // fold (sext (sextload x)) -> (sextload x)
+ if (N0.getOpcode() == ISD::SEXTLOAD && VT == N0.getValueType())
+ return N0;
// fold (sext (load x)) -> (sextload x)
if (N0.getOpcode() == ISD::LOAD && N0.Val->hasNUsesOfValue(1, 0)) {
SDOperand ExtLoad = DAG.getExtLoad(ISD::SEXTLOAD, VT, N0.getOperand(0),
N0.getOperand(1), N0.getOperand(2),
N0.getValueType());
CombineTo(N0.Val, ExtLoad, ExtLoad.getOperand(0));
- return CombineTo(N, ExtLoad);
+ WorkList.push_back(N);
+ return SDOperand();
}
return SDOperand();
}
@@ -1303,13 +1307,19 @@ SDOperand DAGCombiner::visitTRUNCATE(SDNode *N) {
assert(MVT::getSizeInBits(N0.getValueType()) > MVT::getSizeInBits(VT) &&
"Cannot truncate to larger type!");
MVT::ValueType PtrType = N0.getOperand(1).getValueType();
+ // For big endian targets, we need to add an offset to the pointer to load
+ // the correct bytes. For little endian systems, we merely need to read
+ // fewer bytes from the same pointer.
uint64_t PtrOff =
(MVT::getSizeInBits(N0.getValueType()) - MVT::getSizeInBits(VT)) / 8;
- SDOperand NewPtr = DAG.getNode(ISD::ADD, PtrType, N0.getOperand(1),
- DAG.getConstant(PtrOff, PtrType));
+ SDOperand NewPtr = TLI.isLittleEndian() ? N0.getOperand(1) :
+ DAG.getNode(ISD::ADD, PtrType, N0.getOperand(1),
+ DAG.getConstant(PtrOff, PtrType));
+ WorkList.push_back(NewPtr.Val);
SDOperand Load = DAG.getLoad(VT, N0.getOperand(0), NewPtr,N0.getOperand(2));
CombineTo(N0.Val, Load, Load.getOperand(0));
- return CombineTo(N, Load);
+ WorkList.push_back(N);
+ return SDOperand();
}
return SDOperand();
}