Skip to content

Commit 383c5c2

Browse files
committedFeb 6, 2017
Merge DebugLoc on combined stores; in this case, when combining stores
from the end of two blocks, merge instead of arbitrarily picking one. Differential Revision: http://reviews.llvm.org/D29504 llvm-svn: 294251
1 parent 44a856f commit 383c5c2

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed
 

‎llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/Analysis/Loads.h"
1818
#include "llvm/IR/ConstantRange.h"
1919
#include "llvm/IR/DataLayout.h"
20+
#include "llvm/IR/DebugInfo.h"
2021
#include "llvm/IR/LLVMContext.h"
2122
#include "llvm/IR/IntrinsicInst.h"
2223
#include "llvm/IR/MDBuilder.h"
@@ -1425,7 +1426,9 @@ bool InstCombiner::SimplifyStoreAtEndOfBlock(StoreInst &SI) {
14251426
SI.getOrdering(),
14261427
SI.getSynchScope());
14271428
InsertNewInstBefore(NewSI, *BBI);
1428-
NewSI->setDebugLoc(OtherStore->getDebugLoc());
1429+
// The debug locations of the original instructions might differ; merge them.
1430+
NewSI->setDebugLoc(DILocation::getMergedLocation(SI.getDebugLoc(),
1431+
OtherStore->getDebugLoc()));
14291432

14301433
// If the two stores had AA tags, merge them.
14311434
AAMDNodes AATags;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
; RUN: opt -instcombine -S < %s | FileCheck %s
2+
;
3+
; Generated with:
4+
;
5+
; clang -S -gmlt -emit-llvm test.c -o 1.ll
6+
; opt -sroa -S 1.ll -o test.ll
7+
;
8+
; extern int bar(int i);
9+
; extern int bar2(int i);
10+
;
11+
; int foo(int a, int *d) {
12+
; if(a) {
13+
; *d = bar(a);
14+
; } else {
15+
; *d = bar2(a);
16+
; }
17+
;
18+
; return a;
19+
; }
20+
;
21+
; CHECK: define {{.*}}@foo
22+
; CHECK: if.end:
23+
; CHECK-NEXT: %storemerge = phi
24+
; This final check is the "real" test, verify no !dbg on the store.
25+
; CHECK-NEXT: store i32 %storemerge{{.*}}, align 4{{$}}
26+
;
27+
; ModuleID = 'test1.ll'
28+
source_filename = "test.c"
29+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
30+
target triple = "x86_64-unknown-linux-gnu"
31+
32+
; Function Attrs: noinline nounwind uwtable
33+
define i32 @foo(i32 %a, i32* %d) !dbg !6 {
34+
entry:
35+
%tobool = icmp ne i32 %a, 0, !dbg !8
36+
br i1 %tobool, label %if.then, label %if.else, !dbg !8
37+
38+
if.then: ; preds = %entry
39+
%call = call i32 @bar(i32 %a), !dbg !9
40+
store i32 %call, i32* %d, align 4, !dbg !10
41+
br label %if.end, !dbg !11
42+
43+
if.else: ; preds = %entry
44+
%call1 = call i32 @bar2(i32 %a), !dbg !12
45+
store i32 %call1, i32* %d, align 4, !dbg !13
46+
br label %if.end
47+
48+
if.end: ; preds = %if.else, %if.then
49+
ret i32 %a, !dbg !14
50+
}
51+
52+
declare i32 @bar(i32)
53+
54+
declare i32 @bar2(i32)
55+
56+
!llvm.dbg.cu = !{!0}
57+
!llvm.module.flags = !{!3, !4}
58+
59+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
60+
!1 = !DIFile(filename: "test.c", directory: "/home/probinson/projects/scratch")
61+
!2 = !{}
62+
!3 = !{i32 2, !"Dwarf Version", i32 4}
63+
!4 = !{i32 2, !"Debug Info Version", i32 3}
64+
!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 4, type: !7, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
65+
!7 = !DISubroutineType(types: !2)
66+
!8 = !DILocation(line: 5, column: 6, scope: !6)
67+
!9 = !DILocation(line: 6, column: 12, scope: !6)
68+
!10 = !DILocation(line: 6, column: 10, scope: !6)
69+
!11 = !DILocation(line: 7, column: 3, scope: !6)
70+
!12 = !DILocation(line: 8, column: 12, scope: !6)
71+
!13 = !DILocation(line: 8, column: 10, scope: !6)
72+
!14 = !DILocation(line: 10, column: 3, scope: !6)

‎llvm/test/Transforms/SampleProfile/calls.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ while.cond: ; preds = %if.end, %entry
4848
store i32 %inc, i32* %i, align 4, !dbg !14
4949
%cmp = icmp slt i32 %0, 400000000, !dbg !14
5050
br i1 %cmp, label %while.body, label %while.end, !dbg !14
51-
; CHECK: edge while.cond -> while.body probability is 0x7d9eb367 / 0x80000000 = 98.14% [HOT edge]
52-
; CHECK: edge while.cond -> while.end probability is 0x02614c99 / 0x80000000 = 1.86%
51+
; CHECK: edge while.cond -> while.body probability is 0x75bcbf1b / 0x80000000 = 91.98% [HOT edge]
52+
; CHECK: edge while.cond -> while.end probability is 0x0a4340e5 / 0x80000000 = 8.02%
5353

5454
while.body: ; preds = %while.cond
5555
%1 = load i32, i32* %i, align 4, !dbg !16

0 commit comments

Comments
 (0)
Please sign in to comment.