Skip to content

Commit c2f92a3

Browse files
authored
[DebugInfo][NaryReassociate] Fix missing debug location updates (#92545)
Fixes #92537
1 parent 64e0835 commit c2f92a3

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

llvm/lib/Transforms/Scalar/NaryReassociate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ Instruction *NaryReassociatePass::tryReassociatedBinaryOp(const SCEV *LHSExpr,
519519
default:
520520
llvm_unreachable("Unexpected instruction.");
521521
}
522+
NewI->setDebugLoc(I->getDebugLoc());
522523
NewI->takeName(I);
523524
return NewI;
524525
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt < %s -passes=nary-reassociate -S | FileCheck %s
3+
4+
; Test that NaryReassociate's tryReassociatedBinaryOp() propagates the
5+
; debug location to new `add` and `mul` from the original binary operator
6+
; they replaced (`%3` in both `@add_reassociate` and `@mul_reassociate`).
7+
8+
define void @add_reassociate(i32 %a, i32 %b, i32 %c) !dbg !5 {
9+
; CHECK-LABEL: define void @add_reassociate(
10+
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]], i32 [[C:%.*]]) !dbg [[DBG5:![0-9]+]] {
11+
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[A]], [[C]]
12+
; CHECK-NEXT: call void @foo(i32 [[TMP1]])
13+
; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], [[B]], !dbg [[DBG8:![0-9]+]]
14+
; CHECK-NEXT: call void @foo(i32 [[TMP2]])
15+
; CHECK-NEXT: ret void
16+
;
17+
%1 = add i32 %a, %c
18+
call void @foo(i32 %1)
19+
%2 = add i32 %b, %c
20+
%3 = add i32 %a, %2, !dbg !11
21+
call void @foo(i32 %3)
22+
ret void
23+
}
24+
25+
define void @mul_reassociate(i32 %a, i32 %b, i32 %c) !dbg !14 {
26+
; CHECK-LABEL: define void @mul_reassociate(
27+
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]], i32 [[C:%.*]]) !dbg [[DBG9:![0-9]+]] {
28+
; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[A]], [[C]]
29+
; CHECK-NEXT: call void @foo(i32 [[TMP1]])
30+
; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], [[B]], !dbg [[DBG10:![0-9]+]]
31+
; CHECK-NEXT: call void @foo(i32 [[TMP2]])
32+
; CHECK-NEXT: ret void
33+
;
34+
%1 = mul i32 %a, %c
35+
call void @foo(i32 %1)
36+
%2 = mul i32 %a, %b
37+
%3 = mul i32 %2, %c, !dbg !18
38+
call void @foo(i32 %3)
39+
ret void
40+
}
41+
42+
declare void @foo(i32)
43+
44+
!llvm.dbg.cu = !{!0}
45+
!llvm.debugify = !{!2, !3}
46+
!llvm.module.flags = !{!4}
47+
48+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
49+
!1 = !DIFile(filename: "test.ll", directory: "/")
50+
!2 = !{i32 12}
51+
!3 = !{i32 0}
52+
!4 = !{i32 2, !"Debug Info Version", i32 3}
53+
!5 = distinct !DISubprogram(name: "add_reassociate", linkageName: "add_reassociate", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
54+
!6 = !DISubroutineType(types: !7)
55+
!7 = !{}
56+
!11 = !DILocation(line: 4, column: 1, scope: !5)
57+
!14 = distinct !DISubprogram(name: "mul_reassociate", linkageName: "mul_reassociate", scope: null, file: !1, line: 7, type: !6, scopeLine: 7, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
58+
!18 = !DILocation(line: 10, column: 1, scope: !14)
59+
60+
;.
61+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C, file: [[META1:![0-9]+]], producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
62+
; CHECK: [[META1]] = !DIFile(filename: "test.ll", directory: {{.*}})
63+
; CHECK: [[DBG5]] = distinct !DISubprogram(name: "add_reassociate", linkageName: "add_reassociate", scope: null, file: [[META1]], line: 1, type: [[META6:![0-9]+]], scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]])
64+
; CHECK: [[META6]] = !DISubroutineType(types: [[META7:![0-9]+]])
65+
; CHECK: [[META7]] = !{}
66+
; CHECK: [[DBG8]] = !DILocation(line: 4, column: 1, scope: [[DBG5]])
67+
; CHECK: [[DBG9]] = distinct !DISubprogram(name: "mul_reassociate", linkageName: "mul_reassociate", scope: null, file: [[META1]], line: 7, type: [[META6]], scopeLine: 7, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]])
68+
; CHECK: [[DBG10]] = !DILocation(line: 10, column: 1, scope: [[DBG9]])
69+
;.

0 commit comments

Comments
 (0)