Skip to content

Commit c2dccf9

Browse files
author
Davide Italiano
committed
[CodeGenPrepare] Reset the debug location when promoting trunc(s)
The promotion machinery in CGP moves instructions retaining debug locations. When the transformation is local, this is mostly correct, but when instructions are moved cross-BBs, this is not always true and causes jumpiness in line tables. This is the first of a series of commits. sext(s) and zext(s) need to be treated similarly. Differential Revision: https://reviews.llvm.org/D81879
1 parent a93ff18 commit c2dccf9

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,6 +2605,7 @@ class TypePromotionTransaction {
26052605
/// trunc Opnd to Ty.
26062606
TruncBuilder(Instruction *Opnd, Type *Ty) : TypePromotionAction(Opnd) {
26072607
IRBuilder<> Builder(Opnd);
2608+
Builder.SetCurrentDebugLocation(DebugLoc());
26082609
Val = Builder.CreateTrunc(Opnd, Ty, "promoted");
26092610
LLVM_DEBUG(dbgs() << "Do: TruncBuilder: " << *Val << "\n");
26102611
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; RUN: opt < %s -codegenprepare -S -mtriple=x86_64-unknown-unknown | FileCheck %s
2+
3+
; Make sure the promoted trunc doesn't get a debug location associated.
4+
; CHECK: %promoted = trunc i32 %or to i16
5+
6+
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
7+
target triple = "x86_64-apple-macosx10.13.0"
8+
9+
@b = global i16 0, align 2
10+
11+
declare void @bar(i64)
12+
13+
define i32 @foo(i16 %kkk) !dbg !6 {
14+
entry:
15+
%t4 = load i16, i16* @b, align 2, !dbg !8
16+
%conv4 = zext i16 %t4 to i32, !dbg !9
17+
%or = or i16 %kkk, %t4, !dbg !10
18+
%c = sext i16 %or to i64, !dbg !11
19+
call void @bar(i64 %c), !dbg !12
20+
%t5 = and i16 %or, 5, !dbg !13
21+
%z = zext i16 %t5 to i32, !dbg !14
22+
ret i32 %z, !dbg !15
23+
}
24+
25+
!llvm.dbg.cu = !{!0}
26+
!llvm.debugify = !{!3, !4}
27+
!llvm.module.flags = !{!5}
28+
29+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
30+
!1 = !DIFile(filename: "/Users/davide/work/llvm-project/patatino.ll", directory: "/")
31+
!2 = !{}
32+
!3 = !{i32 8}
33+
!4 = !{i32 0}
34+
!5 = !{i32 2, !"Debug Info Version", i32 3}
35+
!6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
36+
!7 = !DISubroutineType(types: !2)
37+
!8 = !DILocation(line: 1, column: 1, scope: !6)
38+
!9 = !DILocation(line: 2, column: 1, scope: !6)
39+
!10 = !DILocation(line: 3, column: 1, scope: !6)
40+
!11 = !DILocation(line: 4, column: 1, scope: !6)
41+
!12 = !DILocation(line: 5, column: 1, scope: !6)
42+
!13 = !DILocation(line: 6, column: 1, scope: !6)
43+
!14 = !DILocation(line: 7, column: 1, scope: !6)
44+
!15 = !DILocation(line: 8, column: 1, scope: !6)

0 commit comments

Comments
 (0)