1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Test CFG simplify removal of branch instructions.
4 ; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
5 ; RUN: opt < %s -passes=simplifycfg -S | FileCheck %s
15 define void @test2() {
16 ; CHECK-LABEL: @test2(
17 ; CHECK-NEXT: ret void
23 define void @test3(i1 %T) {
24 ; CHECK-LABEL: @test3(
25 ; CHECK-NEXT: ret void
27 br i1 %T, label %1, label %1
31 ; Folding branch to a common destination.
32 define void @test4_fold(i32 %a, i32 %b) {
33 ; CHECK-LABEL: @test4_fold(
34 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
35 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt i32 [[A]], 0
36 ; CHECK-NEXT: [[OR_COND:%.*]] = and i1 [[CMP1]], [[CMP2]]
37 ; CHECK-NEXT: br i1 [[OR_COND]], label [[ELSE:%.*]], label [[COMMON_RET:%.*]]
39 ; CHECK-NEXT: ret void
41 ; CHECK-NEXT: call void @foo()
42 ; CHECK-NEXT: br label [[COMMON_RET]]
44 %cmp1 = icmp eq i32 %a, %b
45 br i1 %cmp1, label %taken, label %untaken
48 %cmp2 = icmp ugt i32 %a, 0
49 br i1 %cmp2, label %else, label %untaken
59 ; Prefer a simplification based on a dominating condition rather than folding a
60 ; branch to a common destination.
61 define void @test4_no_fold(i32 %a, i32 %b) {
62 ; CHECK-LABEL: @test4_no_fold(
63 ; CHECK-NEXT: untaken:
64 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
65 ; CHECK-NEXT: ret void
67 %cmp1 = icmp eq i32 %a, %b
68 br i1 %cmp1, label %taken, label %untaken
71 %cmp2 = icmp ugt i32 %a, %b
72 br i1 %cmp2, label %else, label %untaken
85 define void @test5(i32 %A) {
86 ; CHECK-LABEL: @test5(
87 ; CHECK-NEXT: common.ret:
88 ; CHECK-NEXT: ret void
90 switch i32 %A, label %return [
99 return: ; preds = %entry
105 define i8 @test6f() {
106 ; CHECK-LABEL: @test6f(
108 ; CHECK-NEXT: [[R:%.*]] = alloca i8, align 1
109 ; CHECK-NEXT: [[TMP:%.*]] = call i8 @test6g(ptr [[R]])
110 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[TMP]], 0
111 ; CHECK-NEXT: [[TMP3:%.*]] = load i8, ptr [[R]], align 1, !range [[RNG5:![0-9]+]]
112 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i8 [[TMP3]], 1
113 ; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[TMP1]], i1 true, i1 [[TMP4]]
114 ; CHECK-NEXT: [[TMP6:%.*]] = select i1 [[OR_COND]], i8 0, i8 1
115 ; CHECK-NEXT: ret i8 [[TMP6]]
119 %r = alloca i8, align 1
120 %tmp = call i8 @test6g(ptr %r)
121 %tmp1 = icmp eq i8 %tmp, 0
122 br i1 %tmp1, label %bb2, label %bb1
124 %tmp3 = load i8, ptr %r, align 1, !range !2, !tbaa !10, !dbg !5
125 %tmp4 = icmp eq i8 %tmp3, 1
126 br i1 %tmp4, label %bb2, label %bb3
130 %tmp6 = phi i8 [ 0, %bb2 ], [ 1, %bb1 ]
133 declare i8 @test6g(ptr)
136 !llvm.module.flags = !{!8, !9}
138 !0 = !{!10, !10, i64 0}
141 !3 = distinct !DICompileUnit(language: DW_LANG_C99, file: !7, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !4)
143 !5 = !DILocation(line: 23, scope: !6)
144 !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)
145 !7 = !DIFile(filename: "foo.c", directory: "/")
146 !8 = !{i32 2, !"Dwarf Version", i32 2}
147 !9 = !{i32 2, !"Debug Info Version", i32 3}
148 !10 = !{!"scalar type", !1}