]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/DebugInfo/Generic/simplifycfg_sink_last_inst.ll
Vendor import of llvm release_40 branch r292009:
[FreeBSD/FreeBSD.git] / test / DebugInfo / Generic / simplifycfg_sink_last_inst.ll
1 ; RUN: opt -simplifycfg -S < %s | FileCheck %s
2
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
5
6 ; Simplify CFG will try to sink the last instruction in a series of basic
7 ; blocks, creating a "common" instruction in the successor block.  If the
8 ; debug locations of the commoned instructions have different file/line
9 ; numbers the debug location of the common instruction should not be set.
10
11 ; Generated from source:
12
13 ; extern int foo(void);
14 ; extern int bar(void);
15
16 ; int test(int a, int b) {
17 ;   if(a)
18 ;     b -= foo();
19 ;   else
20 ;     b -= bar();
21 ;   return b;
22 ; }
23
24 ; CHECK: define i32 @test
25 ; CHECK-LABEL: if.end:
26 ; CHECK: %[[PHI:.*]] = phi i32 [ %call1, %if.else ], [ %call, %if.then ]
27 ; CHECK: sub nsw i32 %b, %[[PHI]]
28 ; CHECK-NOT: !dbg
29 ; CHECK: ret i32
30
31 define i32 @test(i32 %a, i32 %b) !dbg !6 {
32 entry:
33   %tobool = icmp ne i32 %a, 0, !dbg !8
34   br i1 %tobool, label %if.then, label %if.else, !dbg !8
35
36 if.then:                                          ; preds = %entry
37   %call = call i32 @foo(), !dbg !9
38   %sub = sub nsw i32 %b, %call, !dbg !10
39   br label %if.end, !dbg !11
40
41 if.else:                                          ; preds = %entry
42   %call1 = call i32 @bar(), !dbg !12
43   %sub2 = sub nsw i32 %b, %call1, !dbg !13
44   br label %if.end
45
46 if.end:                                           ; preds = %if.else, %if.then
47   %b.addr.0 = phi i32 [ %sub, %if.then ], [ %sub2, %if.else ]
48   ret i32 %b.addr.0, !dbg !14
49 }
50
51 ; When the commoned instructions have the same debug location, this location
52 ; should be used as the location of the common instruction.
53
54 ; Generated from source (with -mllvm -no-discriminators and -gno-column-info):
55
56 ; int test2(int a, int b) {
57 ;   if(a) b -= foo(); else b -= bar();
58 ;   return b;
59 ; }
60
61 ; CHECK: define i32 @test2
62 ; CHECK-LABEL: if.end:
63 ; CHECK: %[[PHI:.*]] = phi i32 [ %call1, %if.else ], [ %call, %if.then ]
64 ; CHECK: sub nsw i32 %b, %[[PHI]], !dbg ![[DBG:.*]]
65 ; CHECK: ret i32
66 ; CHECK: ![[DBG]] = !DILocation(line: 17, scope: !{{.*}})
67
68 define i32 @test2(i32 %a, i32 %b) !dbg !15 {
69 entry:
70   %tobool = icmp ne i32 %a, 0, !dbg !16
71   br i1 %tobool, label %if.then, label %if.else, !dbg !16
72
73 if.then:                                          ; preds = %entry
74   %call = call i32 @foo(), !dbg !16
75   %sub = sub nsw i32 %b, %call, !dbg !16
76   br label %if.end, !dbg !16
77
78 if.else:                                          ; preds = %entry
79   %call1 = call i32 @bar(), !dbg !16
80   %sub2 = sub nsw i32 %b, %call1, !dbg !16
81   br label %if.end
82
83 if.end:                                           ; preds = %if.else, %if.then
84   %b.addr.0 = phi i32 [ %sub, %if.then ], [ %sub2, %if.else ]
85   ret i32 %b.addr.0, !dbg !17
86 }
87
88 declare i32 @foo()
89 declare i32 @bar()
90
91 !llvm.dbg.cu = !{!0}
92 !llvm.module.flags = !{!3, !4}
93
94 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
95 !1 = !DIFile(filename: "test.c", directory: "")
96 !2 = !{}
97 !3 = !{i32 2, !"Dwarf Version", i32 4}
98 !4 = !{i32 2, !"Debug Info Version", i32 3}
99 !6 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 8, type: !7, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
100 !7 = !DISubroutineType(types: !2)
101 !8 = !DILocation(line: 9, column: 6, scope: !6)
102 !9 = !DILocation(line: 10, column: 10, scope: !6)
103 !10 = !DILocation(line: 10, column: 7, scope: !6)
104 !11 = !DILocation(line: 10, column: 5, scope: !6)
105 !12 = !DILocation(line: 12, column: 10, scope: !6)
106 !13 = !DILocation(line: 12, column: 7, scope: !6)
107 !14 = !DILocation(line: 13, column: 3, scope: !6)
108 !15 = distinct !DISubprogram(name: "test2", scope: !1, file: !1, line: 16, type: !7, isLocal: false, isDefinition: true, scopeLine: 16, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
109 !16 = !DILocation(line: 17, scope: !15)
110 !17 = !DILocation(line: 18, scope: !15)