Skip to content

Commit 5c31c05

Browse files
committed
[llvm] X86DiscriminateMemOps: insert debug info when missing
Reviewers: davidxl Reviewed By: davidxl Subscribers: aprantl, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61735 llvm-svn: 360396
1 parent 6419685 commit 5c31c05

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

llvm/lib/Target/X86/X86DiscriminateMemOps.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,15 @@ bool X86DiscriminateMemOps::runOnMachineFunction(MachineFunction &MF) {
115115
if (X86II::getMemoryOperandNo(MI.getDesc().TSFlags) < 0)
116116
continue;
117117
const DILocation *DI = MI.getDebugLoc();
118-
if (!DI) {
118+
bool HasDebug = DI;
119+
if (!HasDebug) {
119120
DI = ReferenceDI;
120121
}
121122
Location L = diToLocation(DI);
122123
DenseSet<unsigned> &Set = Seen[L];
123124
const std::pair<DenseSet<unsigned>::iterator, bool> TryInsert =
124125
Set.insert(DI->getBaseDiscriminator());
125-
if (!TryInsert.second) {
126+
if (!TryInsert.second || !HasDebug) {
126127
unsigned BF, DF, CI = 0;
127128
DILocation::decodeDiscriminator(DI->getDiscriminator(), BF, DF, CI);
128129
Optional<unsigned> EncodedDiscriminator = DILocation::encodeDiscriminator(
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
; RUN: llc -x86-discriminate-memops < %s | FileCheck %s
2+
;
3+
; original source, compiled with -O3 -gmlt -fdebug-info-for-profiling:
4+
; int sum(int* arr, int pos1, int pos2) {
5+
; return arr[pos1] + arr[pos2];
6+
; }
7+
;
8+
; ModuleID = 'test.cc'
9+
source_filename = "test.cc"
10+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
11+
target triple = "x86_64-unknown-linux-gnu"
12+
13+
declare void @llvm.prefetch(i8 *, i32, i32, i32)
14+
; Function Attrs: norecurse nounwind readonly uwtable
15+
define i32 @sum(i32* %arr, i32 %pos1, i32 %pos2) !dbg !7 {
16+
entry:
17+
%idxprom = sext i32 %pos1 to i64
18+
%arrayidx = getelementptr inbounds i32, i32* %arr, i64 %idxprom
19+
%0 = load i32, i32* %arrayidx, align 4
20+
%idxprom1 = sext i32 %pos2 to i64
21+
%arrayidx2 = getelementptr inbounds i32, i32* %arr, i64 %idxprom1
22+
%1 = load i32, i32* %arrayidx2, align 4
23+
%add = add nsw i32 %1, %0, !dbg !15
24+
ret i32 %add
25+
}
26+
27+
attributes #0 = { "target-cpu"="x86-64" }
28+
29+
!llvm.dbg.cu = !{!0}
30+
!llvm.module.flags = !{!3, !4, !5}
31+
!llvm.ident = !{!6}
32+
33+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, debugInfoForProfiling: true)
34+
!1 = !DIFile(filename: "test.cc", directory: "/tmp")
35+
!2 = !{}
36+
!3 = !{i32 2, !"Dwarf Version", i32 4}
37+
!4 = !{i32 2, !"Debug Info Version", i32 3}
38+
!5 = !{i32 1, !"wchar_size", i32 4}
39+
!6 = !{!"clang version 7.0.0 (trunk 322155) (llvm/trunk 322159)"}
40+
!7 = distinct !DISubprogram(name: "sum", linkageName: "sum", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0)
41+
!8 = !DISubroutineType(types: !2)
42+
!9 = !DILocation(line: 2, column: 10, scope: !7)
43+
!10 = !{!11, !11, i64 0}
44+
!11 = !{!"int", !12, i64 0}
45+
!12 = !{!"omnipotent char", !13, i64 0}
46+
!13 = !{!"Simple C++ TBAA"}
47+
!15 = !DILocation(line: 2, column: 20, scope: !7)
48+
49+
50+
;CHECK-LABEL: sum:
51+
;CHECK: # %bb.0:
52+
;CHECK: .loc 1 1 0 {{.*}} discriminator 2
53+
;CHECK-NEXT: movl (%rdi,%rax,4), %eax
54+
;CHECK-NEXT: .loc 1 2 20
55+
;CHECK-NEXT: addl (%rdi,%rcx,4), %eax

0 commit comments

Comments
 (0)