1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 < %s | FileCheck %s
4 declare void @llvm.experimental.guard(i1, ...)
6 define i32 @f_0(i1 %c) {
9 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"() ]
10 ; CHECK-NEXT: unreachable
13 call void(i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"() ]
17 define i32 @f_1(i1 %c) {
18 ; Demonstrate that we (intentionally) do not simplify a guard on undef
21 ; CHECK-NEXT: br i1 [[C:%.*]], label [[TRUE:%.*]], label [[COMMON_RET:%.*]]
23 ; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i32 [ 10, [[TRUE]] ], [ 20, [[ENTRY:%.*]] ]
24 ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
26 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 undef) [ "deopt"() ]
27 ; CHECK-NEXT: br label [[COMMON_RET]]
31 br i1 %c, label %true, label %false
34 call void(i1, ...) @llvm.experimental.guard(i1 undef) [ "deopt"() ]
41 define i32 @f_2(i1 %c, ptr %buf) {
44 ; CHECK-NEXT: br i1 [[C:%.*]], label [[GUARD_BLOCK:%.*]], label [[MERGE_BLOCK:%.*]]
46 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"() ]
47 ; CHECK-NEXT: unreachable
49 ; CHECK-NEXT: ret i32 50
52 br i1 %c, label %guard_block, label %merge_block
55 call void(i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"() ]
56 %val = load i32, ptr %buf
60 %to.return = phi i32 [ %val, %guard_block ], [ 50, %entry ]
65 define i32 @f_3(ptr %c, ptr %buf) {
68 ; CHECK-NEXT: [[C0:%.*]] = load volatile i1, ptr [[C:%.*]], align 1
69 ; CHECK-NEXT: br i1 [[C0]], label [[GUARD_BLOCK:%.*]], label [[MERGE_BLOCK:%.*]]
71 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"() ]
72 ; CHECK-NEXT: unreachable
74 ; CHECK-NEXT: [[C1:%.*]] = load volatile i1, ptr [[C]], align 1
75 ; CHECK-NEXT: [[DOT:%.*]] = select i1 [[C1]], i32 50, i32 100
76 ; CHECK-NEXT: ret i32 [[DOT]]
79 %c0 = load volatile i1, ptr %c
80 br i1 %c0, label %guard_block, label %merge_block
83 call void(i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"() ]
84 %val = load i32, ptr %buf
85 %c2 = load volatile i1, ptr %c
86 br i1 %c2, label %left, label %right
89 %c1 = load volatile i1, ptr %c
90 br i1 %c1, label %left, label %right
93 %val.left = phi i32 [ %val, %guard_block ], [ 50, %merge_block ]
97 %val.right = phi i32 [ %val, %guard_block ], [ 100, %merge_block ]