Skip to content

Commit

Permalink
[Hexagon] Optimize post-increment load and stores in loops. (#82418)
Browse files Browse the repository at this point in the history
This patch optimizes the post-increment instructions so that we can
packetize them together.
v1 = phi(v0, v3')
v2,v3  = post_load v1, 4
v2',v3'= post_load v3, 4

This can be optimized in two ways

v1 = phi(v0, v3')
v2,v3' = post_load v1, 8
v2' = load v1, 4
  • Loading branch information
Sumanth Gundapaneni authored Feb 22, 2024
1 parent 4c0fdcd commit d62ca8d
Show file tree
Hide file tree
Showing 11 changed files with 1,462 additions and 1 deletion.
1 change: 1 addition & 0 deletions llvm/lib/Target/Hexagon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ add_llvm_target(HexagonCodeGen
HexagonOptAddrMode.cpp
HexagonOptimizeSZextends.cpp
HexagonPeephole.cpp
HexagonPostIncOpt.cpp
HexagonRDFOpt.cpp
HexagonRegisterInfo.cpp
HexagonSelectionDAGInfo.cpp
Expand Down
56 changes: 56 additions & 0 deletions llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,13 @@ bool HexagonInstrInfo::isPostIncrement(const MachineInstr &MI) const {
return getAddrMode(MI) == HexagonII::PostInc;
}

bool HexagonInstrInfo::isPostIncWithImmOffset(const MachineInstr &MI) const {
unsigned BasePos, OffsetPos;
if (!getBaseAndOffsetPosition(MI, BasePos, OffsetPos))
return false;
return isPostIncrement(MI) && MI.getOperand(OffsetPos).isImm();
}

// Returns true if an instruction is predicated irrespective of the predicate
// sense. For example, all of the following will return true.
// if (p0) R1 = add(R2, R3)
Expand Down Expand Up @@ -2436,6 +2443,55 @@ bool HexagonInstrInfo::isLoopN(const MachineInstr &MI) const {
Opcode == Hexagon::J2_loop1rext;
}

bool HexagonInstrInfo::isCircBufferInstr(const MachineInstr &MI) const {
switch (MI.getOpcode()) {
default:
return false;
case Hexagon::L2_loadalignb_pci:
case Hexagon::L2_loadalignb_pcr:
case Hexagon::L2_loadalignh_pci:
case Hexagon::L2_loadalignh_pcr:
case Hexagon::L2_loadbsw2_pci:
case Hexagon::L2_loadbsw2_pcr:
case Hexagon::L2_loadbsw4_pci:
case Hexagon::L2_loadbsw4_pcr:
case Hexagon::L2_loadbzw2_pci:
case Hexagon::L2_loadbzw2_pcr:
case Hexagon::L2_loadbzw4_pci:
case Hexagon::L2_loadbzw4_pcr:
case Hexagon::L2_loadrb_pci:
case Hexagon::L2_loadrb_pcr:
case Hexagon::L2_loadrd_pci:
case Hexagon::L2_loadrd_pcr:
case Hexagon::L2_loadrh_pci:
case Hexagon::L2_loadrh_pcr:
case Hexagon::L2_loadri_pci:
case Hexagon::L2_loadri_pcr:
case Hexagon::L2_loadrub_pci:
case Hexagon::L2_loadrub_pcr:
case Hexagon::L2_loadruh_pci:
case Hexagon::L2_loadruh_pcr:
case Hexagon::S2_storerbnew_pci:
case Hexagon::S2_storerbnew_pcr:
case Hexagon::S2_storerb_pci:
case Hexagon::S2_storerb_pcr:
case Hexagon::S2_storerd_pci:
case Hexagon::S2_storerd_pcr:
case Hexagon::S2_storerf_pci:
case Hexagon::S2_storerf_pcr:
case Hexagon::S2_storerhnew_pci:
case Hexagon::S2_storerhnew_pcr:
case Hexagon::S2_storerh_pci:
case Hexagon::S2_storerh_pcr:
case Hexagon::S2_storerinew_pci:
case Hexagon::S2_storerinew_pcr:
case Hexagon::S2_storeri_pci:
case Hexagon::S2_storeri_pcr:
return true;
}
return false;
}

bool HexagonInstrInfo::isMemOp(const MachineInstr &MI) const {
switch (MI.getOpcode()) {
default: return false;
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/Hexagon/HexagonInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ class HexagonInstrInfo : public HexagonGenInstrInfo {
bool predCanBeUsedAsDotNew(const MachineInstr &MI, Register PredReg) const;
bool PredOpcodeHasJMP_c(unsigned Opcode) const;
bool predOpcodeHasNot(ArrayRef<MachineOperand> Cond) const;
bool isPostIncWithImmOffset(const MachineInstr &MI) const;
bool isCircBufferInstr(const MachineInstr &MI) const;

unsigned getAddrMode(const MachineInstr &MI) const;
MachineOperand *getBaseAndOffset(const MachineInstr &MI, int64_t &Offset,
Expand Down
Loading

0 comments on commit d62ca8d

Please sign in to comment.