-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[AArch64][GlobalISel] Add support for pre-indexed loads/stores. #70185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1141,11 +1141,29 @@ bool CombinerHelper::findPreIndexCandidate(GLoadStore &LdSt, Register &Addr, | |
return false; | ||
} | ||
|
||
// Avoid increasing cross-block register pressure. | ||
for (auto &AddrUse : MRI.use_nodbg_instructions(Addr)) { | ||
if (AddrUse.getParent() != LdSt.getParent()) | ||
return false; | ||
} | ||
|
||
// FIXME: check whether all uses of the base pointer are constant PtrAdds. | ||
// That might allow us to end base's liveness here by adjusting the constant. | ||
|
||
return all_of(MRI.use_nodbg_instructions(Addr), | ||
[&](MachineInstr &UseMI) { return dominates(LdSt, UseMI); }); | ||
bool RealUse = false; | ||
for (auto &PtrUse : MRI.use_nodbg_instructions(Addr)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 10 lines up it is called AddrUse?!? |
||
if (!dominates(LdSt, PtrUse)) | ||
return false; // All use must be dominated by the load/store. | ||
|
||
// If Ptr may be folded in addressing mode of other use, then it's | ||
// not profitable to do this transformation. | ||
if (auto *UseLdSt = dyn_cast<GLoadStore>(&PtrUse)) { | ||
if (!canFoldInAddressingMode(UseLdSt, TLI, MRI)) | ||
RealUse = true; | ||
} else { | ||
RealUse = true; | ||
} | ||
} | ||
return RealUse; | ||
} | ||
|
||
bool CombinerHelper::matchCombineIndexedLoadStore( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,7 +245,7 @@ def AArch64PostLegalizerLowering | |
// Post-legalization combines which are primarily optimizations. | ||
def AArch64PostLegalizerCombiner | ||
: GICombiner<"AArch64PostLegalizerCombinerImpl", | ||
[copy_prop, combines_for_extload, | ||
[copy_prop, combines_for_extload, reassocs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks unrelated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, will remove. |
||
combine_indexed_load_store, | ||
sext_trunc_sextload, mutate_anyext_to_zext, | ||
hoist_logic_op_with_same_opcode_hands, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5659,24 +5659,34 @@ bool AArch64InstructionSelector::selectIndexedLoad(MachineInstr &MI, | |
Register WriteBack = Ld.getWritebackReg(); | ||
Register Base = Ld.getBaseReg(); | ||
Register Offset = Ld.getOffsetReg(); | ||
|
||
if (Ld.isPre()) | ||
return false; // TODO: add pre-inc support | ||
|
||
unsigned Opc = 0; | ||
static constexpr unsigned GPROpcodes[] = { | ||
AArch64::LDRBBpost, AArch64::LDRHHpost, AArch64::LDRWpost, | ||
AArch64::LDRXpost}; | ||
static constexpr unsigned FPROpcodes[] = { | ||
AArch64::LDRBpost, AArch64::LDRHpost, AArch64::LDRSpost, | ||
AArch64::LDRDpost, AArch64::LDRQpost}; | ||
|
||
LLT Ty = MRI.getType(Dst); | ||
assert(Ty.getSizeInBits() <= 128); | ||
unsigned MemSize = Ld.getMMO().getMemoryType().getSizeInBytes(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dumb question: are we guaranteed that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. We have separate opcodes for extending loads, |
||
if (RBI.getRegBank(Dst, MRI, TRI)->getID() == AArch64::FPRRegBankID) | ||
Opc = FPROpcodes[Log2_32(MemSize)]; | ||
else | ||
Opc = GPROpcodes[Log2_32(MemSize)]; | ||
|
||
unsigned Opc = 0; | ||
if (Ld.isPre()) { | ||
static constexpr unsigned GPROpcodes[] = { | ||
AArch64::LDRBBpre, AArch64::LDRHHpre, AArch64::LDRWpre, | ||
AArch64::LDRXpre}; | ||
static constexpr unsigned FPROpcodes[] = { | ||
AArch64::LDRBpre, AArch64::LDRHpre, AArch64::LDRSpre, AArch64::LDRDpre, | ||
AArch64::LDRQpre}; | ||
if (RBI.getRegBank(Dst, MRI, TRI)->getID() == AArch64::FPRRegBankID) | ||
Opc = FPROpcodes[Log2_32(MemSize)]; | ||
else | ||
Opc = GPROpcodes[Log2_32(MemSize)]; | ||
} else { | ||
static constexpr unsigned GPROpcodes[] = { | ||
AArch64::LDRBBpost, AArch64::LDRHHpost, AArch64::LDRWpost, | ||
AArch64::LDRXpost}; | ||
static constexpr unsigned FPROpcodes[] = { | ||
AArch64::LDRBpost, AArch64::LDRHpost, AArch64::LDRSpost, | ||
AArch64::LDRDpost, AArch64::LDRQpost}; | ||
if (RBI.getRegBank(Dst, MRI, TRI)->getID() == AArch64::FPRRegBankID) | ||
Opc = FPROpcodes[Log2_32(MemSize)]; | ||
else | ||
Opc = GPROpcodes[Log2_32(MemSize)]; | ||
} | ||
auto Cst = getIConstantVRegVal(Offset, MRI); | ||
if (!Cst) | ||
return false; // Shouldn't happen, but just in case. | ||
|
@@ -5695,23 +5705,34 @@ bool AArch64InstructionSelector::selectIndexedStore(GIndexedStore &I, | |
Register Base = I.getBaseReg(); | ||
Register Offset = I.getOffsetReg(); | ||
LLT ValTy = MRI.getType(Val); | ||
|
||
if (I.isPre()) | ||
return false; // TODO: add pre-inc support | ||
assert(ValTy.getSizeInBits() <= 128); | ||
|
||
unsigned Opc = 0; | ||
static constexpr unsigned GPROpcodes[] = { | ||
AArch64::STRBBpost, AArch64::STRHHpost, AArch64::STRWpost, | ||
AArch64::STRXpost}; | ||
static constexpr unsigned FPROpcodes[] = { | ||
AArch64::STRBpost, AArch64::STRHpost, AArch64::STRSpost, | ||
AArch64::STRDpost, AArch64::STRQpost}; | ||
|
||
assert(ValTy.getSizeInBits() <= 128); | ||
if (RBI.getRegBank(Val, MRI, TRI)->getID() == AArch64::FPRRegBankID) | ||
Opc = FPROpcodes[Log2_32(ValTy.getSizeInBytes())]; | ||
else | ||
Opc = GPROpcodes[Log2_32(ValTy.getSizeInBytes())]; | ||
if (I.isPre()) { | ||
static constexpr unsigned GPROpcodes[] = { | ||
AArch64::STRBBpre, AArch64::STRHHpre, AArch64::STRWpre, | ||
AArch64::STRXpre}; | ||
static constexpr unsigned FPROpcodes[] = { | ||
AArch64::STRBpre, AArch64::STRHpre, AArch64::STRSpre, AArch64::STRDpre, | ||
AArch64::STRQpre}; | ||
|
||
if (RBI.getRegBank(Val, MRI, TRI)->getID() == AArch64::FPRRegBankID) | ||
Opc = FPROpcodes[Log2_32(ValTy.getSizeInBytes())]; | ||
else | ||
Opc = GPROpcodes[Log2_32(ValTy.getSizeInBytes())]; | ||
} else { | ||
static constexpr unsigned GPROpcodes[] = { | ||
AArch64::STRBBpost, AArch64::STRHHpost, AArch64::STRWpost, | ||
AArch64::STRXpost}; | ||
static constexpr unsigned FPROpcodes[] = { | ||
AArch64::STRBpost, AArch64::STRHpost, AArch64::STRSpost, | ||
AArch64::STRDpost, AArch64::STRQpost}; | ||
|
||
if (RBI.getRegBank(Val, MRI, TRI)->getID() == AArch64::FPRRegBankID) | ||
Opc = FPROpcodes[Log2_32(ValTy.getSizeInBytes())]; | ||
else | ||
Opc = GPROpcodes[Log2_32(ValTy.getSizeInBytes())]; | ||
} | ||
|
||
auto Cst = getIConstantVRegVal(Offset, MRI); | ||
if (!Cst) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure about the braces?