[llvm] [SDAG] Reuse MMO in `legalizeStoreOps` promotion path (PR #229722)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 7 03:41:35 PDT 2026
https://github.com/Pierre-vh created https://github.com/llvm/llvm-project/pull/229722
I hit this bug in #229429 when using `i64` for the 64-bit stores.
I ended up using `<2 x i32>` for consistency with other intrinsics but the
bug still remains.
No target hits this so far so I can't test it, but I think it's good to fix it.
Otherwise a i64 store that goes through this path can lose its atomicity for example.
The load path already preserves the MMO I believe.
>From 028dae8f4ee770b042d7f8e6399d0924b487b45d Mon Sep 17 00:00:00 2001
From: pvanhout <pierre.vanhoutryve at amd.com>
Date: Wed, 7 Oct 2026 12:39:31 +0200
Subject: [PATCH] [SDAG] Reuse MMO in `legalizeStoreOps` promotion path
I hit this bug in #229429 when using `i64` for the 64-bit stores.
I ended up using `<2 x i32>` for consistency with other intrinsics but the
bug still remains.
No target hits this so far so I can't test it, but I think it's good to fix it.
Otherwise a i64 store that goes through this path can lose its atomicity for example.
The load path already preserves the MMO I believe.
---
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index ffc9173e767fa..c6d95dfeca754 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -535,8 +535,9 @@ void SelectionDAGLegalize::LegalizeStoreOps(SDNode *Node) {
assert(NVT.getSizeInBits() == VT.getSizeInBits() &&
"Can only promote stores to same size type");
Value = DAG.getNode(ISD::BITCAST, dl, NVT, Value);
- SDValue Result = DAG.getStore(Chain, dl, Value, Ptr, ST->getPointerInfo(),
- ST->getBaseAlign(), MMOFlags, Metadata);
+ // Reuse the original memory operand to preserve properties like atomicity.
+ SDValue Result =
+ DAG.getStore(Chain, dl, Value, Ptr, ST->getMemOperand());
ReplaceNode(SDValue(Node, 0), Result);
break;
}
More information about the llvm-commits
mailing list