[llvm] [DAGCombiner] Merge debug locations when combining stores (PR #225358)

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 04:33:02 PDT 2026


================
@@ -0,0 +1,178 @@
+; RUN: llc -O2 -mtriple=x86_64-unknown-linux-gnu -verify-machineinstrs -stop-after=finalize-isel -o - %s | FileCheck %s
+
+;; Consecutive stores combined into a single store must merge their locations,
+;; rather than attributing all effects to the lowest-addressed store's scope.
+
+; CHECK-DAG: ![[CALLER:[0-9]+]] = distinct !DISubprogram(name: "siblings",
+; CHECK-DAG: ![[FIRST:[0-9]+]] = distinct !DISubprogram(name: "clear_first",
+; CHECK-DAG: ![[SECOND:[0-9]+]] = distinct !DISubprogram(name: "clear_second",
+; CHECK-DAG: ![[SAME_CALL:[0-9]+]] = !DILocation(line: 21, column: 3, scope: ![[#]])
+; CHECK-DAG: ![[SAME:[0-9]+]] = !DILocation(line: 4, column: 3, scope: ![[FIRST]], inlinedAt: ![[SAME_CALL]])
+; CHECK-DAG: ![[PARTIAL_CALL:[0-9]+]] = !DILocation(line: 41, column: 3, scope: ![[#]])
+; CHECK-DAG: ![[PARTIAL:[0-9]+]] = !DILocation(line: 4, column: 3, scope: ![[FIRST]], inlinedAt: ![[PARTIAL_CALL]])
+; CHECK-DAG: ![[EXTRACT:[0-9]+]] = distinct !DISubprogram(name: "extract_siblings",
+; CHECK-DAG: ![[COPY:[0-9]+]] = distinct !DISubprogram(name: "copy_siblings",
+; CHECK-DAG: ![[INDEPENDENT:[0-9]+]] = distinct !DISubprogram(name: "copy_independent_locations",
+; CHECK-DAG: ![[LOAD_CALL:[0-9]+]] = !DILocation(line: 71, column: 3, scope: ![[INDEPENDENT]])
+; CHECK-DAG: ![[LOAD:[0-9]+]] = !DILocation(line: 4, column: 3, scope: ![[FIRST]], inlinedAt: ![[LOAD_CALL]])
+; CHECK-DAG: ![[STORE_CALL:[0-9]+]] = !DILocation(line: 72, column: 3, scope: ![[INDEPENDENT]])
+; CHECK-DAG: ![[STORE:[0-9]+]] = !DILocation(line: 7, column: 3, scope: ![[SECOND]], inlinedAt: ![[STORE_CALL]])
+; CHECK-DAG: ![[COPY_PARTIAL_CALL:[0-9]+]] = !DILocation(line: 81, column: 3, scope: ![[#]])
+; CHECK-DAG: ![[COPY_PARTIAL:[0-9]+]] = !DILocation(line: 4, column: 3, scope: ![[FIRST]], inlinedAt: ![[COPY_PARTIAL_CALL]])
+
+; CHECK-LABEL: name: siblings
+; CHECK: MOV64mi32 {{.*}}, debug-location !DILocation(line: 0, scope: ![[CALLER]]) :: (store (s64)
+define void @siblings(ptr %p) !dbg !10 {
+  store i32 0, ptr %p, align 4, !dbg !13
+  %q = getelementptr i32, ptr %p, i64 1
+  store i32 0, ptr %q, align 4, !dbg !14
+  ret void
+}
+
+;; Identical locations retain their line and inline scope.
+; CHECK-LABEL: name: same_location
+; CHECK: MOV64mi32 {{.*}}, debug-location ![[SAME]] :: (store (s64)
+define void @same_location(ptr %p) !dbg !20 {
+  store i32 0, ptr %p, align 4, !dbg !22
+  %q = getelementptr i32, ptr %p, i64 1
+  store i32 0, ptr %q, align 4, !dbg !22
+  ret void
+}
+
+;; Do not retain one store's scope when the other's location is unknown.
+; CHECK-LABEL: name: missing_location
+; CHECK: MOV64mi32
+; CHECK-NOT: debug-location
+; CHECK-SAME: :: (store (s64)
+define void @missing_location(ptr %p) !dbg !30 {
+  store i32 0, ptr %p, align 4, !dbg !32
+  %q = getelementptr i32, ptr %p, i64 1
+  store i32 0, ptr %q, align 4
+  ret void
+}
+
+;; Only the first two candidates are merged. Do not include the third store's
+;; location when computing the wider store's location.
----------------
jmorse wrote:

IMO "stores" instead of "candidates". Also note that this doesn't change behaviour versus todays llc, because !43 is picked anyway.

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


More information about the llvm-commits mailing list