1 ; Test CFG simplify removal of branch instructions.
3 ; RUN: opt < %s -simplifycfg -S | FileCheck %s
4 ; RUN: opt < %s -passes=simplify-cfg -S | FileCheck %s
10 ; CHECK-NEXT: ret void
13 define void @test2() {
16 ; CHECK-LABEL: @test2(
17 ; CHECK-NEXT: ret void
21 define void @test3(i1 %T) {
22 br i1 %T, label %1, label %1
24 ; CHECK-LABEL: @test3(
25 ; CHECK-NEXT: ret void
28 ; Folding branch to a common destination.
29 ; CHECK-LABEL: @test4_fold
30 ; CHECK: %cmp1 = icmp eq i32 %a, %b
31 ; CHECK: %cmp2 = icmp ugt i32 %a, 0
32 ; CHECK: %or.cond = and i1 %cmp1, %cmp2
33 ; CHECK: br i1 %or.cond, label %else, label %untaken
36 define void @test4_fold(i32 %a, i32 %b) {
37 %cmp1 = icmp eq i32 %a, %b
38 br i1 %cmp1, label %taken, label %untaken
41 %cmp2 = icmp ugt i32 %a, 0
42 br i1 %cmp2, label %else, label %untaken
52 ; Prefer a simplification based on a dominating condition rather than folding a
53 ; branch to a common destination.
59 define void @test4_no_fold(i32 %a, i32 %b) {
60 %cmp1 = icmp eq i32 %a, %b
61 br i1 %cmp1, label %taken, label %untaken
64 %cmp2 = icmp ugt i32 %a, %b
65 br i1 %cmp2, label %else, label %untaken
78 define void @test5(i32 %A) {
79 switch i32 %A, label %return [
88 return: ; preds = %entry
90 ; CHECK-LABEL: @test5(
91 ; CHECK-NEXT: ret void
97 ; CHECK-LABEL: @test6f
98 ; CHECK: alloca i8, align 1
99 ; CHECK-NEXT: call i8 @test6g
100 ; CHECK-NEXT: icmp eq i8 %tmp, 0
101 ; CHECK-NEXT: load i8, i8* %r, align 1, !dbg !{{[0-9]+$}}
104 %r = alloca i8, align 1
105 %tmp = call i8 @test6g(i8* %r)
106 %tmp1 = icmp eq i8 %tmp, 0
107 br i1 %tmp1, label %bb2, label %bb1
109 %tmp3 = load i8, i8* %r, align 1, !range !2, !tbaa !10, !dbg !5
110 %tmp4 = icmp eq i8 %tmp3, 1
111 br i1 %tmp4, label %bb2, label %bb3
115 %tmp6 = phi i8 [ 0, %bb2 ], [ 1, %bb1 ]
118 declare i8 @test6g(i8*)
121 !llvm.module.flags = !{!8, !9}
123 !0 = !{!10, !10, i64 0}
126 !3 = distinct !DICompileUnit(language: DW_LANG_C99, file: !7, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !4)
128 !5 = !DILocation(line: 23, scope: !6)
129 !6 = distinct !DISubprogram(name: "foo", scope: !3, file: !7, line: 1, type: !DISubroutineType(types: !4), isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !3, retainedNodes: !4)
130 !7 = !DIFile(filename: "foo.c", directory: "/")
131 !8 = !{i32 2, !"Dwarf Version", i32 2}
132 !9 = !{i32 2, !"Debug Info Version", i32 3}
133 !10 = !{!"scalar type", !1}