113 lines · plain
1; RUN: opt -passes=simplifycfg -sink-common-insts -S < %s | FileCheck %s2 3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"4target triple = "x86_64-unknown-linux-gnu"5 6; Simplify CFG will try to sink the last instruction in a series of basic7; blocks, creating a "common" instruction in the successor block. If the8; debug locations of the commoned instructions have different file/line9; numbers the debug location of the common instruction should be a merged10; location.11 12; Generated from source:13 14; extern int foo(void);15; extern int bar(void);16;17; int test(int a, int b) {18; if(a)19; b -= foo();20; else21; b -= bar();22; return b;23; }24 25; CHECK: define i32 @test26; CHECK-LABEL: if.end:27; CHECK: %[[PHI:.*]] = phi i32 [ %call1, %if.else ], [ %call, %if.then ]28; CHECK: sub nsw i32 %b, %[[PHI]], !dbg [[testMergedLoc:![0-9]+]]29; CHECK: ret i3230 31define i32 @test(i32 %a, i32 %b) !dbg !6 {32entry:33 %tobool = icmp ne i32 %a, 0, !dbg !834 br i1 %tobool, label %if.then, label %if.else, !dbg !835 36if.then: ; preds = %entry37 %call = call i32 @foo(), !dbg !938 %sub = sub nsw i32 %b, %call, !dbg !1039 br label %if.end, !dbg !1140 41if.else: ; preds = %entry42 %call1 = call i32 @bar(), !dbg !1243 %sub2 = sub nsw i32 %b, %call1, !dbg !1344 br label %if.end45 46if.end: ; preds = %if.else, %if.then47 %b.addr.0 = phi i32 [ %sub, %if.then ], [ %sub2, %if.else ]48 ret i32 %b.addr.0, !dbg !1449}50 51; When the commoned instructions have the same debug location, this location52; 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 @test262; CHECK-LABEL: if.end:63; CHECK: %[[PHI:.*]] = phi i32 [ %call1, %if.else ], [ %call, %if.then ]64; CHECK: sub nsw i32 %b, %[[PHI]], !dbg [[test2Loc:![0-9]+]]65; CHECK: ret i3266 67define i32 @test2(i32 %a, i32 %b) !dbg !15 {68entry:69 %tobool = icmp ne i32 %a, 0, !dbg !1670 br i1 %tobool, label %if.then, label %if.else, !dbg !1671 72if.then: ; preds = %entry73 %call = call i32 @foo(), !dbg !1674 %sub = sub nsw i32 %b, %call, !dbg !1675 br label %if.end, !dbg !1676 77if.else: ; preds = %entry78 %call1 = call i32 @bar(), !dbg !1679 %sub2 = sub nsw i32 %b, %call1, !dbg !1680 br label %if.end81 82if.end: ; preds = %if.else, %if.then83 %b.addr.0 = phi i32 [ %sub, %if.then ], [ %sub2, %if.else ]84 ret i32 %b.addr.0, !dbg !1785}86 87; CHECK: [[testMergedLoc]] = !DILocation(line: 088; CHECK: [[test2Loc]] = !DILocation(line: 1789 90declare i32 @foo()91declare i32 @bar()92 93!llvm.dbg.cu = !{!0}94!llvm.module.flags = !{!3, !4}95 96!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)97!1 = !DIFile(filename: "test.c", directory: "")98!2 = !{}99!3 = !{i32 2, !"Dwarf Version", i32 4}100!4 = !{i32 2, !"Debug Info Version", i32 3}101!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, retainedNodes: !2)102!7 = !DISubroutineType(types: !2)103!8 = !DILocation(line: 9, column: 6, scope: !6)104!9 = !DILocation(line: 10, column: 10, scope: !6)105!10 = !DILocation(line: 10, column: 7, scope: !6)106!11 = !DILocation(line: 10, column: 5, scope: !6)107!12 = !DILocation(line: 12, column: 10, scope: !6)108!13 = !DILocation(line: 12, column: 7, scope: !6)109!14 = !DILocation(line: 13, column: 3, scope: !6)110!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, retainedNodes: !2)111!16 = !DILocation(line: 17, scope: !15)112!17 = !DILocation(line: 18, scope: !15)113