[llvm] [GlobalISel] Preserve volatile and atomic undef stores (PR #200099)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 27 19:05:28 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-globalisel
Author: Justin Lebar (jlebar)
<details>
<summary>Changes</summary>
It's not correct to elide a volatile or atomic store, even if the stored
value is undef.
This bug was found by a large run of Opus 4.7 looking for bugs in LLVM.
---
Full diff: https://github.com/llvm/llvm-project/pull/200099.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp (+4-2)
- (modified) llvm/test/CodeGen/X86/GlobalISel/undef.ll (+25)
``````````diff
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index a910a900e775f..64f6a93b722ee 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -2880,8 +2880,10 @@ bool CombinerHelper::matchUndefShuffleVectorMask(MachineInstr &MI) const {
bool CombinerHelper::matchUndefStore(MachineInstr &MI) const {
assert(MI.getOpcode() == TargetOpcode::G_STORE);
- return getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, MI.getOperand(0).getReg(),
- MRI);
+ auto &Store = cast<GStore>(MI);
+ if (!Store.isSimple())
+ return false;
+ return getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, Store.getValueReg(), MRI);
}
bool CombinerHelper::matchUndefSelectCmp(MachineInstr &MI) const {
diff --git a/llvm/test/CodeGen/X86/GlobalISel/undef.ll b/llvm/test/CodeGen/X86/GlobalISel/undef.ll
index 34ada8a20999d..3fd706a01944c 100644
--- a/llvm/test/CodeGen/X86/GlobalISel/undef.ll
+++ b/llvm/test/CodeGen/X86/GlobalISel/undef.ll
@@ -56,3 +56,28 @@ define float @test4(float %a) {
ret float %r
}
+define void @plain_undef_store(ptr %p) {
+; ALL-LABEL: plain_undef_store:
+; ALL: # %bb.0:
+; ALL-NEXT: retq
+ store i32 undef, ptr %p, align 4
+ ret void
+}
+
+define void @volatile_undef_store(ptr %p) {
+; ALL-LABEL: volatile_undef_store:
+; ALL: # %bb.0:
+; ALL-NEXT: movl %eax, (%rdi)
+; ALL-NEXT: retq
+ store volatile i32 undef, ptr %p, align 4
+ ret void
+}
+
+define void @seq_cst_atomic_undef_store(ptr %p) {
+; ALL-LABEL: seq_cst_atomic_undef_store:
+; ALL: # %bb.0:
+; ALL-NEXT: movl %eax, (%rdi)
+; ALL-NEXT: retq
+ store atomic i32 undef, ptr %p seq_cst, align 4
+ ret void
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/200099
More information about the llvm-commits
mailing list