blob: 8d8e1cd3c0684679fb955fb5441e735b92c0b330 [file] [log] [blame]
Robert Lougher2428a402016-12-14 17:49:19 +00001; RUN: opt -instcombine -S < %s | FileCheck %s
2
3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4target triple = "x86_64-unknown-linux-gnu"
5
6; If all the operands to a phi node are of the same operation, instcombine
7; will try to pull them through the phi node, combining them into a single
8; operation. Check that when it does this the combined operation does not
9; have a debug location set.
10
11; Test folding of a binary operation. Generated from source:
12
13; extern int foo(void);
14; extern int bar(void);
15;
16; int binop(int a, int b) {
17; if(a)
18; b -= foo();
19; else
20; b -= bar();
21; return b;
22; }
23
24; CHECK: define i32 @binop
25; CHECK-LABEL: if.end:
26; CHECK: %[[PHI:.*]] = phi i32 [ %call, %if.then ], [ %call1, %if.else ]
27; CHECK: sub nsw i32 %b, %[[PHI]]
28; CHECK-NOT: !dbg
29; CHECK: ret i32
30
31define i32 @binop(i32 %a, i32 %b) !dbg !6 {
32entry:
33 %tobool = icmp ne i32 %a, 0, !dbg !8
34 br i1 %tobool, label %if.then, label %if.else, !dbg !8
35
36if.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
41if.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
46if.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
51declare i32 @foo()
52declare i32 @bar()
53
54!llvm.dbg.cu = !{!0}
55!llvm.module.flags = !{!3, !4}
56
57!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
58!1 = !DIFile(filename: "test.c", directory: "")
59!2 = !{}
60!3 = !{i32 2, !"Dwarf Version", i32 4}
61!4 = !{i32 2, !"Debug Info Version", i32 3}
62!6 = distinct !DISubprogram(name: "binop", scope: !1, file: !1, line: 8, type: !7, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
63!7 = !DISubroutineType(types: !2)
64!8 = !DILocation(line: 9, column: 6, scope: !6)
65!9 = !DILocation(line: 10, column: 10, scope: !6)
66!10 = !DILocation(line: 10, column: 7, scope: !6)
67!11 = !DILocation(line: 10, column: 5, scope: !6)
68!12 = !DILocation(line: 12, column: 10, scope: !6)
69!13 = !DILocation(line: 12, column: 7, scope: !6)
70!14 = !DILocation(line: 13, column: 3, scope: !6)