mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-05 14:34:55 +00:00
Compile:
unsigned foo4(unsigned short *P) { return *P & 255; } unsigned foo5(short *P) { return *P & 255; } to: _foo4: lbz r3,1(r3) blr _foo5: lbz r3,1(r3) blr not: _foo4: lhz r2, 0(r3) rlwinm r3, r2, 0, 24, 31 blr _foo5: lhz r2, 0(r3) rlwinm r3, r2, 0, 24, 31 blr git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26419 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f4c8575c27
commit
35a9f5a241
@ -1043,9 +1043,13 @@ SDOperand DAGCombiner::visitAND(SDNode *N) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fold (and (load x), 255) -> (zextload x)
|
// fold (and (load x), 255) -> (zextload x, i8)
|
||||||
if (N1C && N0.getOpcode() == ISD::LOAD && N0.hasOneUse()) {
|
// fold (and (extload x, i16), 255) -> (zextload x, i8)
|
||||||
MVT::ValueType EVT;
|
if (N1C &&
|
||||||
|
(N0.getOpcode() == ISD::LOAD || N0.getOpcode() == ISD::EXTLOAD ||
|
||||||
|
N0.getOpcode() == ISD::ZEXTLOAD) &&
|
||||||
|
N0.hasOneUse()) {
|
||||||
|
MVT::ValueType EVT, LoadedVT;
|
||||||
if (N1C->getValue() == 255)
|
if (N1C->getValue() == 255)
|
||||||
EVT = MVT::i8;
|
EVT = MVT::i8;
|
||||||
else if (N1C->getValue() == 65535)
|
else if (N1C->getValue() == 65535)
|
||||||
@ -1054,16 +1058,19 @@ SDOperand DAGCombiner::visitAND(SDNode *N) {
|
|||||||
EVT = MVT::i32;
|
EVT = MVT::i32;
|
||||||
else
|
else
|
||||||
EVT = MVT::Other;
|
EVT = MVT::Other;
|
||||||
if (EVT != MVT::Other) {
|
|
||||||
assert(MVT::getSizeInBits(VT) > MVT::getSizeInBits(EVT) &&
|
LoadedVT = N0.getOpcode() == ISD::LOAD ? VT :
|
||||||
"Cannot zext to larger type!");
|
cast<VTSDNode>(N0.getOperand(3))->getVT();
|
||||||
|
if (EVT != MVT::Other && LoadedVT > EVT) {
|
||||||
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
|
// 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
|
// the correct bytes. For little endian systems, we merely need to read
|
||||||
// fewer bytes from the same pointer.
|
// fewer bytes from the same pointer.
|
||||||
uint64_t PtrOff = (MVT::getSizeInBits(VT) - MVT::getSizeInBits(EVT)) / 8;
|
unsigned PtrOff =
|
||||||
SDOperand NewPtr = TLI.isLittleEndian() ? N0.getOperand(1) :
|
(MVT::getSizeInBits(LoadedVT) - MVT::getSizeInBits(EVT)) / 8;
|
||||||
DAG.getNode(ISD::ADD, PtrType, N0.getOperand(1),
|
SDOperand NewPtr = N0.getOperand(1);
|
||||||
|
if (!TLI.isLittleEndian())
|
||||||
|
NewPtr = DAG.getNode(ISD::ADD, PtrType, NewPtr,
|
||||||
DAG.getConstant(PtrOff, PtrType));
|
DAG.getConstant(PtrOff, PtrType));
|
||||||
WorkList.push_back(NewPtr.Val);
|
WorkList.push_back(NewPtr.Val);
|
||||||
SDOperand Load =
|
SDOperand Load =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user