mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-25 17:20:48 +00:00
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
This commit is contained in:
@@ -1194,13 +1194,17 @@ SDOperand DAGCombiner::visitSIGN_EXTEND(SDNode *N) {
|
|||||||
// fold (sext (sext x)) -> (sext x)
|
// fold (sext (sext x)) -> (sext x)
|
||||||
if (N0.getOpcode() == ISD::SIGN_EXTEND)
|
if (N0.getOpcode() == ISD::SIGN_EXTEND)
|
||||||
return DAG.getNode(ISD::SIGN_EXTEND, VT, N0.getOperand(0));
|
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)
|
// fold (sext (load x)) -> (sextload x)
|
||||||
if (N0.getOpcode() == ISD::LOAD && N0.Val->hasNUsesOfValue(1, 0)) {
|
if (N0.getOpcode() == ISD::LOAD && N0.Val->hasNUsesOfValue(1, 0)) {
|
||||||
SDOperand ExtLoad = DAG.getExtLoad(ISD::SEXTLOAD, VT, N0.getOperand(0),
|
SDOperand ExtLoad = DAG.getExtLoad(ISD::SEXTLOAD, VT, N0.getOperand(0),
|
||||||
N0.getOperand(1), N0.getOperand(2),
|
N0.getOperand(1), N0.getOperand(2),
|
||||||
N0.getValueType());
|
N0.getValueType());
|
||||||
CombineTo(N0.Val, ExtLoad, ExtLoad.getOperand(0));
|
CombineTo(N0.Val, ExtLoad, ExtLoad.getOperand(0));
|
||||||
return CombineTo(N, ExtLoad);
|
WorkList.push_back(N);
|
||||||
|
return SDOperand();
|
||||||
}
|
}
|
||||||
return SDOperand();
|
return SDOperand();
|
||||||
}
|
}
|
||||||
@@ -1303,13 +1307,19 @@ SDOperand DAGCombiner::visitTRUNCATE(SDNode *N) {
|
|||||||
assert(MVT::getSizeInBits(N0.getValueType()) > MVT::getSizeInBits(VT) &&
|
assert(MVT::getSizeInBits(N0.getValueType()) > MVT::getSizeInBits(VT) &&
|
||||||
"Cannot truncate to larger type!");
|
"Cannot truncate to larger type!");
|
||||||
MVT::ValueType PtrType = N0.getOperand(1).getValueType();
|
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 =
|
uint64_t PtrOff =
|
||||||
(MVT::getSizeInBits(N0.getValueType()) - MVT::getSizeInBits(VT)) / 8;
|
(MVT::getSizeInBits(N0.getValueType()) - MVT::getSizeInBits(VT)) / 8;
|
||||||
SDOperand NewPtr = DAG.getNode(ISD::ADD, PtrType, N0.getOperand(1),
|
SDOperand NewPtr = TLI.isLittleEndian() ? N0.getOperand(1) :
|
||||||
DAG.getConstant(PtrOff, PtrType));
|
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));
|
SDOperand Load = DAG.getLoad(VT, N0.getOperand(0), NewPtr,N0.getOperand(2));
|
||||||
CombineTo(N0.Val, Load, Load.getOperand(0));
|
CombineTo(N0.Val, Load, Load.getOperand(0));
|
||||||
return CombineTo(N, Load);
|
WorkList.push_back(N);
|
||||||
|
return SDOperand();
|
||||||
}
|
}
|
||||||
return SDOperand();
|
return SDOperand();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user