1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -loop-guard-widening < %s | FileCheck %s
3 ; RUN: opt -S -passes="loop(guard-widening)" < %s | FileCheck %s
5 declare void @llvm.experimental.guard(i1,...)
7 @G = external global i32
9 ; Show that we can widen into early checks within a loop, and in the process
10 ; expose optimization oppurtunities.
11 define void @widen_within_loop(i1 %cond_0, i1 %cond_1, i1 %cond_2) {
12 ; CHECK-LABEL: @widen_within_loop(
14 ; CHECK-NEXT: br label [[LOOP:%.*]]
16 ; CHECK-NEXT: store i32 0, i32* @G
17 ; CHECK-NEXT: [[WIDE_CHK:%.*]] = and i1 [[COND_0:%.*]], [[COND_1:%.*]]
18 ; CHECK-NEXT: [[WIDE_CHK1:%.*]] = and i1 [[WIDE_CHK]], [[COND_2:%.*]]
19 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[WIDE_CHK1]]) [ "deopt"(i32 0) ]
20 ; CHECK-NEXT: store i32 1, i32* @G
21 ; CHECK-NEXT: store i32 2, i32* @G
22 ; CHECK-NEXT: store i32 3, i32* @G
23 ; CHECK-NEXT: br label [[LOOP]]
30 call void(i1, ...) @llvm.experimental.guard(i1 %cond_0) [ "deopt"(i32 0) ]
32 call void(i1, ...) @llvm.experimental.guard(i1 %cond_1) [ "deopt"(i32 1) ]
34 call void(i1, ...) @llvm.experimental.guard(i1 %cond_2) [ "deopt"(i32 2) ]
39 define void @widen_into_preheader(i1 %cond_0, i1 %cond_1, i1 %cond_2) {
40 ; CHECK-LABEL: @widen_into_preheader(
42 ; CHECK-NEXT: store i32 0, i32* @G
43 ; CHECK-NEXT: [[WIDE_CHK:%.*]] = and i1 [[COND_0:%.*]], [[COND_1:%.*]]
44 ; CHECK-NEXT: [[WIDE_CHK1:%.*]] = and i1 [[WIDE_CHK]], [[COND_2:%.*]]
45 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[WIDE_CHK1]]) [ "deopt"(i32 0) ]
46 ; CHECK-NEXT: br label [[LOOP:%.*]]
48 ; CHECK-NEXT: store i32 1, i32* @G
49 ; CHECK-NEXT: store i32 2, i32* @G
50 ; CHECK-NEXT: store i32 3, i32* @G
51 ; CHECK-NEXT: br label [[LOOP]]
55 call void(i1, ...) @llvm.experimental.guard(i1 %cond_0) [ "deopt"(i32 0) ]
60 call void(i1, ...) @llvm.experimental.guard(i1 %cond_1) [ "deopt"(i32 1) ]
62 call void(i1, ...) @llvm.experimental.guard(i1 %cond_2) [ "deopt"(i32 2) ]
67 define void @dont_widen_over_common_exit(i1 %cond_0, i1 %cond_1, i1 %cond_2) {
68 ; CHECK-LABEL: @dont_widen_over_common_exit(
70 ; CHECK-NEXT: br label [[LOOP:%.*]]
72 ; CHECK-NEXT: store i32 0, i32* @G
73 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[COND_0:%.*]]) [ "deopt"(i32 0) ]
74 ; CHECK-NEXT: store i32 1, i32* @G
75 ; CHECK-NEXT: br i1 [[COND_1:%.*]], label [[BACKEDGE:%.*]], label [[EXIT:%.*]]
77 ; CHECK-NEXT: store i32 2, i32* @G
78 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[COND_2:%.*]]) [ "deopt"(i32 2) ]
79 ; CHECK-NEXT: store i32 3, i32* @G
80 ; CHECK-NEXT: br label [[LOOP]]
82 ; CHECK-NEXT: ret void
89 call void(i1, ...) @llvm.experimental.guard(i1 %cond_0) [ "deopt"(i32 0) ]
91 br i1 %cond_1, label %backedge, label %exit
95 call void(i1, ...) @llvm.experimental.guard(i1 %cond_2) [ "deopt"(i32 2) ]
103 define void @widen_over_common_exit_to_ph(i1 %cond_0, i1 %cond_1, i1 %cond_2) {
104 ; CHECK-LABEL: @widen_over_common_exit_to_ph(
106 ; CHECK-NEXT: store i32 0, i32* @G
107 ; CHECK-NEXT: [[WIDE_CHK:%.*]] = and i1 [[COND_0:%.*]], [[COND_2:%.*]]
108 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[WIDE_CHK]]) [ "deopt"(i32 0) ]
109 ; CHECK-NEXT: br label [[LOOP:%.*]]
111 ; CHECK-NEXT: store i32 1, i32* @G
112 ; CHECK-NEXT: br i1 [[COND_1:%.*]], label [[BACKEDGE:%.*]], label [[EXIT:%.*]]
114 ; CHECK-NEXT: store i32 2, i32* @G
115 ; CHECK-NEXT: store i32 3, i32* @G
116 ; CHECK-NEXT: br label [[LOOP]]
118 ; CHECK-NEXT: ret void
122 call void(i1, ...) @llvm.experimental.guard(i1 %cond_0) [ "deopt"(i32 0) ]
127 br i1 %cond_1, label %backedge, label %exit
131 call void(i1, ...) @llvm.experimental.guard(i1 %cond_2) [ "deopt"(i32 2) ]