Cheng Shao pushed to branch wip/fix-cmm-atomic-load-store at Glasgow Haskell Compiler / GHC Commits: 0591305e by Cheng Shao at 2026-07-09T10:10:23+00:00 compiler: fix miscompiled %load_relaxed, add missing %store_relaxed This patch fixes the %load_relaxed cmm primop compilation logic to correctly use relaxed memory ordering, and adds the missing %store_relaxed primop. Parsing logic of %load/%store with explicit ordering is covered in the AtomicFetch test case. Fixes #27483. Co-authored-by: Codex <codex@openai.com> - - - - - 4 changed files: - + changelog.d/fix-cmm-atomic-load-store - compiler/GHC/Cmm/Parser.y - testsuite/tests/cmm/should_run/AtomicFetch.hs - testsuite/tests/cmm/should_run/AtomicFetch_cmm.cmm Changes: ===================================== changelog.d/fix-cmm-atomic-load-store ===================================== @@ -0,0 +1,4 @@ +section: cmm +synopsis: Fix miscompiled %load_relaxed primop, add missing %store_relaxed +issues: #27483 +mrs: !16320 ===================================== compiler/GHC/Cmm/Parser.y ===================================== @@ -1210,9 +1210,10 @@ callishMachOps platform = listToUFM $ , allWidths "pext" MO_Pext , allWidths "cmpxchg" MO_Cmpxchg , allWidths "xchg" MO_Xchg - , allWidths "load_relaxed" (\w -> MO_AtomicRead w MemOrderAcquire) + , allWidths "load_relaxed" (\w -> MO_AtomicRead w MemOrderRelaxed) , allWidths "load_acquire" (\w -> MO_AtomicRead w MemOrderAcquire) , allWidths "load_seqcst" (\w -> MO_AtomicRead w MemOrderSeqCst) + , allWidths "store_relaxed" (\w -> MO_AtomicWrite w MemOrderRelaxed) , allWidths "store_release" (\w -> MO_AtomicWrite w MemOrderRelease) , allWidths "store_seqcst" (\w -> MO_AtomicWrite w MemOrderSeqCst) , allWidths "fetch_add" (\w -> MO_AtomicRMW w AMO_Add) ===================================== testsuite/tests/cmm/should_run/AtomicFetch.hs ===================================== @@ -6,6 +6,7 @@ -- This is not a test of atomic semantics, -- just checking that GHC can parse %fetch_fooXX +-- and %load/%store with explicit ordering import GHC.Exts import GHC.Int ===================================== testsuite/tests/cmm/should_run/AtomicFetch_cmm.cmm ===================================== @@ -2,6 +2,7 @@ // This is not a test of atomic semantics, // just checking that GHC can parse %fetch_fooXX +// and %load/%store with explicit ordering cmm_foo64 (P_ p) { @@ -19,6 +20,10 @@ cmm_foo64 (P_ p) (x) = prim %fetch_xor64(q, 33 :: I64); (x) = prim %fetch_nand64(q, 127 :: I64); (x) = prim %load_seqcst64(q); + prim %store_relaxed64(q, x); + (x) = prim %load_relaxed64(q); + prim %store_release64(q, x); + (x) = prim %load_acquire64(q); return (x); } @@ -38,6 +43,10 @@ cmm_foo32 (P_ p) (x) = prim %fetch_xor32(q, 33 :: I32); (x) = prim %fetch_nand32(q, 127 :: I32); (x) = prim %load_seqcst32(q); + prim %store_relaxed32(q, x); + (x) = prim %load_relaxed32(q); + prim %store_release32(q, x); + (x) = prim %load_acquire32(q); return (x); } @@ -57,6 +66,10 @@ cmm_foo16 (P_ p) (x) = prim %fetch_xor16(q, 33 :: I16); (x) = prim %fetch_nand16(q, 127 :: I16); (x) = prim %load_seqcst16(q); + prim %store_relaxed16(q, x); + (x) = prim %load_relaxed16(q); + prim %store_release16(q, x); + (x) = prim %load_acquire16(q); return (x); } @@ -76,5 +89,9 @@ cmm_foo8 (P_ p) (x) = prim %fetch_xor8(q, 33 :: I8); (x) = prim %fetch_nand8(q, 127 :: I8); (x) = prim %load_seqcst8(q); + prim %store_relaxed8(q, x); + (x) = prim %load_relaxed8(q); + prim %store_release8(q, x); + (x) = prim %load_acquire8(q); return (x); } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0591305e319b4a66e5913a0940e25b10... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0591305e319b4a66e5913a0940e25b10... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Cheng Shao (@TerrorJack)