[llvm] [MCA][X86] Pretend To Have a Stack Engine (PR #153348)

Andrea Di Biagio via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 15 02:27:11 PDT 2025


================
@@ -36,11 +36,31 @@ void X86InstrPostProcess::setMemBarriers(std::unique_ptr<Instruction> &Inst,
   }
 }
 
+void X86InstrPostProcess::useStackEngine(std::unique_ptr<Instruction> &Inst,
+                                         const MCInst &MCI) {
+  if (X86::isPOP(MCI.getOpcode())) {
+    assert(Inst->getUses().size() == 1 &&
+           "Expected pop instruction to only use stack pointer register");
+    Inst->getUses().clear();
+  }
----------------
adibiagio wrote:

Strictly speaking, there is still a dependency. However, it is not on the last computed RSP, but on the "original" RSP value before the stack operation sequence started.

Example:

```
  RSP_1 = non_stack_op_defining_RSP 
  ...
  pushq a   ## RSP_1 + 0   ## waits on RSP_1. New Delta=8
  pushq b   ## RSP_1 + 8   ## waits on RSP_1. New Delta=16
  pushq c   ## RSP_1 + 16  ## waits on RSP_1. New Delta=24
  pushq d  ## RSP_1 + 24   ## waits on RSP_1. New Delta=32
  ...
  RSP_2 = RSP_1 + 32     ## sync definition of RSP.
  other_inst_that_uses_RSP(RSP_2)  ## waits on RSP_2
```

As soon as RSP_1 has been computed, all PUSH instructions in that sequence won't need to wait for any other register dependency.

https://github.com/llvm/llvm-project/pull/153348


More information about the llvm-commits mailing list