Skip to content

[DebugInfo][LICM] Fix missing debug location updates #91729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/lib/Transforms/Scalar/LICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,12 +933,14 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
ReciprocalDivisor->setFastMathFlags(I.getFastMathFlags());
SafetyInfo->insertInstructionTo(ReciprocalDivisor, I.getParent());
ReciprocalDivisor->insertBefore(&I);
ReciprocalDivisor->setDebugLoc(I.getDebugLoc());

auto Product =
BinaryOperator::CreateFMul(I.getOperand(0), ReciprocalDivisor);
Product->setFastMathFlags(I.getFastMathFlags());
SafetyInfo->insertInstructionTo(Product, I.getParent());
Product->insertAfter(&I);
Product->setDebugLoc(I.getDebugLoc());
I.replaceAllUsesWith(Product);
eraseInstruction(I, *SafetyInfo, MSSAU);

Expand Down
66 changes: 66 additions & 0 deletions llvm/test/Transforms/LICM/debugloc-preserve-fmul-drop-fdiv.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
; RUN: opt -passes=licm -verify-memoryssa -S < %s | FileCheck %s

; JumpThreading's hoistRegion() replaces the `fdiv` (%v6), of which the second
; operand (%v) is a loop invariant, with a loop invariant `fdiv` and a `fmul`.
; This test checks that the debug location propagates to the new `fmul` from
; the old `fdiv` it replaces in block `loop` and the debug location drop of new
; `fdiv`, which is hoisted to block `entry` after being created.

define zeroext i1 @invariant_denom(double %v) !dbg !5 {
; CHECK: entry:
; CHECK-NEXT: [[TMP0:%.*]] = fdiv fast double 1.000000e+00, [[V:%.*]]{{$}}
; CHECK: loop:
; CHECK: [[TMP1:%.*]] = fmul fast double {{.*}}, !dbg [[DBG12:![0-9]+]]
; CHECK: [[DBG12]] = !DILocation(line: 5,
;
entry:
br label %loop, !dbg !8

loop: ; preds = %loop, %entry
%v3 = phi i32 [ 0, %entry ], [ %v11, %loop ], !dbg !9
%v4 = phi i32 [ 0, %entry ], [ %v12, %loop ], !dbg !10
%v5 = uitofp i32 %v4 to double, !dbg !11
%v6 = fdiv fast double %v5, %v, !dbg !12
%v7 = fptoui double %v6 to i64, !dbg !13
%v8 = and i64 %v7, 1, !dbg !14
%v9 = xor i64 %v8, 1, !dbg !15
%v10 = trunc i64 %v9 to i32, !dbg !16
%v11 = add i32 %v10, %v3, !dbg !17
%v12 = add nuw i32 %v4, 1, !dbg !18
%v13 = icmp eq i32 %v12, -1, !dbg !19
br i1 %v13, label %end, label %loop, !dbg !20

end: ; preds = %loop
%v15 = phi i32 [ %v11, %loop ], !dbg !21
%v16 = icmp ne i32 %v15, 0, !dbg !22
ret i1 %v16, !dbg !23
}

!llvm.dbg.cu = !{!0}
!llvm.debugify = !{!2, !3}
!llvm.module.flags = !{!4}

!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
!1 = !DIFile(filename: "test.ll", directory: "/")
!2 = !{i32 16}
!3 = !{i32 0}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = distinct !DISubprogram(name: "invariant_denom", linkageName: "invariant_denom", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
!6 = !DISubroutineType(types: !7)
!7 = !{}
!8 = !DILocation(line: 1, column: 1, scope: !5)
!9 = !DILocation(line: 2, column: 1, scope: !5)
!10 = !DILocation(line: 3, column: 1, scope: !5)
!11 = !DILocation(line: 4, column: 1, scope: !5)
!12 = !DILocation(line: 5, column: 1, scope: !5)
!13 = !DILocation(line: 6, column: 1, scope: !5)
!14 = !DILocation(line: 7, column: 1, scope: !5)
!15 = !DILocation(line: 8, column: 1, scope: !5)
!16 = !DILocation(line: 9, column: 1, scope: !5)
!17 = !DILocation(line: 10, column: 1, scope: !5)
!18 = !DILocation(line: 11, column: 1, scope: !5)
!19 = !DILocation(line: 12, column: 1, scope: !5)
!20 = !DILocation(line: 13, column: 1, scope: !5)
!21 = !DILocation(line: 14, column: 1, scope: !5)
!22 = !DILocation(line: 15, column: 1, scope: !5)
!23 = !DILocation(line: 16, column: 1, scope: !5)
Loading