[llvm] [MemCpyOpt] fix miscompile for non-dominated use of src alloca for stack-move optimization (PR #66618)

Kohei Asano via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 03:25:10 PDT 2023


================
@@ -1486,6 +1486,14 @@ bool MemCpyOptPass::performStackMoveOptzn(Instruction *Load, Instruction *Store,
       Instruction *I = Worklist.back();
       Worklist.pop_back();
       for (const Use &U : I->uses()) {
+        auto *UI = cast<Instruction>(U.getUser());
+        // If any use that isn't dominated by SrcAlloca exists, non-dominating
+        // uses will be produced.
+        if (!DT->dominates(SrcAlloca, UI)) {
----------------
khei4 wrote:

Ah, exactly; moving srcAlloca before the dominators for all uses seems better. Dominator calculation will be here soon to fix the lifetime problem https://github.com/llvm/llvm-project/issues/66403. 

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


More information about the llvm-commits mailing list