[llvm] [X86] Ignore meta instructions when tracking SESES fences (PR #226344)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 19:54:59 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-x86

Author: Yongqiang Tian (yqtian-se)

<details>
<summary>Changes</summary>

Meta instructions do not emit executable code, but SESES currently treats them as ordinary instructions and clears `PrevInstIsLFENCE`. This can cause it to insert a redundant `LFENCE`, as seen when a `DBG_VALUE` occurs between an explicit fence and a load.

Skip meta instructions when updating the fence state. The regression test verifies that a `DBG_VALUE` between an explicit `LFENCE` and a volatile load does not cause another fence to be inserted.

Fixes #<!-- -->226336

Assisted-by: OpenAI Codex 5.6 Sol

---
Full diff: https://github.com/llvm/llvm-project/pull/226344.diff


2 Files Affected:

- (modified) llvm/lib/Target/X86/X86SpeculativeExecutionSideEffectSuppression.cpp (+3) 
- (added) llvm/test/CodeGen/X86/speculative-execution-side-effect-suppression-debug-instrs.ll (+36) 


``````````diff
diff --git a/llvm/lib/Target/X86/X86SpeculativeExecutionSideEffectSuppression.cpp b/llvm/lib/Target/X86/X86SpeculativeExecutionSideEffectSuppression.cpp
index 5558ffd7ab067..37c2f594ad61a 100644
--- a/llvm/lib/Target/X86/X86SpeculativeExecutionSideEffectSuppression.cpp
+++ b/llvm/lib/Target/X86/X86SpeculativeExecutionSideEffectSuppression.cpp
@@ -112,6 +112,9 @@ runX86SpeculativeExecutionSideEffectSuppression(MachineFunction &MF) {
     bool PrevInstIsLFENCE = false;
     for (auto &MI : MBB) {
 
+      if (MI.isMetaInstruction())
+        continue;
+
       if (MI.getOpcode() == X86::LFENCE) {
         PrevInstIsLFENCE = true;
         continue;
diff --git a/llvm/test/CodeGen/X86/speculative-execution-side-effect-suppression-debug-instrs.ll b/llvm/test/CodeGen/X86/speculative-execution-side-effect-suppression-debug-instrs.ll
new file mode 100644
index 0000000000000..40d6eb5702555
--- /dev/null
+++ b/llvm/test/CodeGen/X86/speculative-execution-side-effect-suppression-debug-instrs.ll
@@ -0,0 +1,36 @@
+; RUN: llc -mtriple=i686-unknown-linux-gnu -verify-machineinstrs %s -o - | FileCheck %s
+
+; A DBG_VALUE after an LFENCE should not make SESES insert another LFENCE
+; before the following load.
+
+ at probe = external global i32
+
+define i32 @read_after_fence(i32 %x) nounwind "target-features"="+sse2,+seses" !dbg !4 {
+; CHECK-LABEL: read_after_fence:
+; CHECK:         lfence
+; CHECK:         #DEBUG_VALUE: read_after_fence:x <- undef
+; CHECK-NOT:     lfence
+; CHECK:         movl probe, %eax
+entry:
+  call void @llvm.x86.sse2.lfence(), !dbg !8
+    #dbg_value(i32 %x, !7, !DIExpression(), !8)
+  %value = load volatile i32, ptr @probe, align 4, !dbg !8
+  %sum = add i32 %value, %x, !dbg !8
+  ret i32 %sum, !dbg !8
+}
+
+declare void @llvm.x86.sse2.lfence()
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "llvm", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "seses-debug-instr.c", directory: "/")
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = distinct !DISubprogram(name: "read_after_fence", linkageName: "read_after_fence", scope: !1, file: !1, line: 1, type: !5, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !6)
+!5 = !DISubroutineType(types: !10)
+!6 = !{!7}
+!7 = !DILocalVariable(name: "x", scope: !4, file: !1, line: 1, type: !9)
+!8 = !DILocation(line: 1, column: 1, scope: !4)
+!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!10 = !{!9, !9}

``````````

</details>


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


More information about the llvm-commits mailing list