[llvm] [CodeGenPrepare] Make sure instruction get from SunkAddrs is before MemoryInst (PR #139303)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon May 12 05:18:54 PDT 2025


================
@@ -5913,6 +5913,9 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
   if (SunkAddr) {
     LLVM_DEBUG(dbgs() << "CGP: Reusing nonlocal addrmode: " << AddrMode
                       << " for " << *MemoryInst << "\n");
+    Instruction *AddrInst = dyn_cast<Instruction>(SunkAddr);
+    if (AddrInst && MemoryInst->comesBefore(AddrInst))
----------------
arsenm wrote:

This is a bit brute force, is there another way to get the implied correct insert point? e.g. change the insertion point above instead of MemoryInst

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


More information about the llvm-commits mailing list