Skip to content

Commit 468fe66

Browse files
SLTozervar-const
authored andcommitted
[DebugInfo][Reassociate] Propagate source locs when factoring add->mul (llvm#134829)
As part of reassociating add instructions, we may factorize some of the adds and produce a mul instruction; this patch propagates the source location of the reassociated tree of instructions to the new mul. Found using llvm#107279.
1 parent af9cf60 commit 468fe66

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

llvm/lib/Transforms/Scalar/Reassociate.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,7 @@ Value *ReassociatePass::OptimizeAdd(Instruction *I,
15261526
Constant *C = Ty->isIntOrIntVectorTy() ?
15271527
ConstantInt::get(Ty, NumFound) : ConstantFP::get(Ty, NumFound);
15281528
Instruction *Mul = CreateMul(TheOp, C, "factor", I->getIterator(), I);
1529+
Mul->setDebugLoc(I->getDebugLoc());
15291530

15301531
// Now that we have inserted a multiply, optimize it. This allows us to
15311532
// handle cases that require multiple factoring steps, such as this:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -p=reassociate -S | FileCheck %s
3+
4+
;; Ensure that when we factorize part of a tree of adds into a multiply, we
5+
;; propagate the debug loc of the tree to the mul.
6+
7+
define fastcc void @ham(i32 %arg) !dbg !10 {
8+
; CHECK-LABEL: define fastcc void @ham(
9+
; CHECK-SAME: i32 [[ARG:%.*]]) !dbg [[DBG4:![0-9]+]] {
10+
; CHECK-NEXT: [[BB:.*:]]
11+
; CHECK-NEXT: [[FACTOR:%.*]] = mul i32 [[ARG]], 2, !dbg [[DBG7:![0-9]+]]
12+
; CHECK-NEXT: [[ADD1:%.*]] = add i32 [[FACTOR]], 1, !dbg [[DBG7]]
13+
; CHECK-NEXT: store i32 [[ADD1]], ptr null, align 4
14+
; CHECK-NEXT: ret void
15+
;
16+
bb:
17+
%add = add i32 %arg, 1
18+
%add1 = add i32 %arg, %add, !dbg !4
19+
store i32 %add1, ptr null, align 4
20+
ret void
21+
}
22+
23+
!llvm.dbg.cu = !{!0}
24+
!llvm.module.flags = !{!3}
25+
26+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 20.0.0git", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, splitDebugInlining: false, nameTableKind: None)
27+
!1 = !DIFile(filename: "debugloc-factoring-add.c", directory: "/tmp")
28+
!2 = !{}
29+
!3 = !{i32 2, !"Debug Info Version", i32 3}
30+
!4 = !DILocation(line: 10, column: 1, scope: !10)
31+
!6 = !DIFile(filename: "debugloc-factoring-add.c", directory: "/tmp")
32+
!10 = distinct !DISubprogram(name: "ham", scope: !6, file: !6, line: 10, type: !11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
33+
!11 = distinct !DISubroutineType(types: !12)
34+
!12 = !{null}
35+
;.
36+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], retainedTypes: [[META2]], globals: [[META2]], splitDebugInlining: false, nameTableKind: None)
37+
; CHECK: [[META1]] = !DIFile(filename: "debugloc-factoring-add.c", directory: {{.*}})
38+
; CHECK: [[META2]] = !{}
39+
; CHECK: [[DBG4]] = distinct !DISubprogram(name: "ham", scope: [[META1]], file: [[META1]], line: 10, type: [[META5:![0-9]+]], flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]])
40+
; CHECK: [[META5]] = distinct !DISubroutineType(types: [[META6:![0-9]+]])
41+
; CHECK: [[META6]] = !{null}
42+
; CHECK: [[DBG7]] = !DILocation(line: 10, column: 1, scope: [[DBG4]])
43+
;.

0 commit comments

Comments
 (0)