[llvm] [AArch64MIPeepholeOpt] Coalesce sibling base-address materializations (PR #223682)
Nashe Mncube via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 15 07:47:11 PDT 2026
================
@@ -957,6 +966,114 @@ bool AArch64MIPeepholeOptImpl::visitCopy(MachineInstr &MI) {
return true;
}
+bool AArch64MIPeepholeOptImpl::shareBaseAddresses(MachineBasicBlock &MBB) {
+ if (!EnableBaseAddressCSE)
+ return false;
+
+ bool Changed = false;
+
+ DenseMap<MachineInstr *, unsigned> Pos;
+ unsigned Idx = 0;
+ for (MachineInstr &MI : MBB.instrs())
+ Pos[&MI] = Idx++;
+
+ struct Cand {
+ MachineInstr *DefMI;
+ Register SrcReg;
+ unsigned Opc;
+ int64_t C;
+ Register BaseReg;
+ MachineInstr *UserMI;
+ int Scale;
+ int64_t OldOff;
+ };
+ SmallVector<Cand, 8> Cands;
+ using Key = std::pair<Register, unsigned>;
+ MapVector<Key, SmallVector<unsigned, 4>> Groups;
+
+ for (MachineInstr &MI : MBB.instrs()) {
+ unsigned Opc = MI.getOpcode();
+ if (Opc != AArch64::ADDXri && Opc != AArch64::SUBXri)
+ continue;
+ if (!MI.getOperand(2).isImm() || !MI.getOperand(3).isImm())
+ continue;
+ if (MI.getOperand(3).getImm() != 0) // shift must be 0 (no LSL #12)
+ continue;
----------------
nasherm wrote:
Combine these two `if` statements
https://github.com/llvm/llvm-project/pull/223682
More information about the llvm-commits
mailing list