• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -S -loop-unswitch -enable-new-pm=0 < %s | FileCheck %s
2; RUN: opt -S -loop-unswitch -enable-new-pm=0 -enable-mssa-loop-dependency=true -verify-memoryssa < %s | FileCheck %s
3
4declare void @llvm.experimental.guard(i1, ...)
5
6define void @f_0(i32 %n, i32* %ptr, i1 %c) {
7; CHECK-LABEL: @f_0(
8; CHECK: loop.us:
9; CHECK-NOT: guard
10; CHECK: loop:
11; CHECK: call void (i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"() ]
12entry:
13  br label %loop
14
15loop:
16  %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]
17  %iv.inc = add i32 %iv, 1
18  call void(i1, ...) @llvm.experimental.guard(i1 %c) [ "deopt"() ]
19  store volatile i32 0, i32* %ptr
20  %becond = icmp ult i32 %iv.inc, %n
21  br i1 %becond, label %leave, label %loop
22
23leave:
24  ret void
25}
26
27define void @f_1(i32 %n, i32* %ptr, i1 %c_0, i1 %c_1) {
28; CHECK-LABEL: @f_1(
29; CHECK: loop.us.us:
30; CHECK-NOT: guard
31; CHECK: loop.us:
32; CHECK: call void (i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"(i32 2) ]
33; CHECK-NOT: guard
34; CHECK: loop.us1:
35; CHECK: call void (i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"(i32 1) ]
36; CHECK-NOT: guard
37; CHECK: loop:
38; CHECK: call void (i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"(i32 1) ]
39; CHECK: call void (i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"(i32 2) ]
40entry:
41  br label %loop
42
43loop:
44  %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]
45  %iv.inc = add i32 %iv, 1
46  call void(i1, ...) @llvm.experimental.guard(i1 %c_0) [ "deopt"(i32 1) ]
47  store volatile i32 0, i32* %ptr
48  call void(i1, ...) @llvm.experimental.guard(i1 %c_1) [ "deopt"(i32 2) ]
49  %becond = icmp ult i32 %iv.inc, %n
50  br i1 %becond, label %leave, label %loop
51
52leave:
53  ret void
54}
55
56; Basic negative test
57
58define void @f_3(i32 %n, i32* %ptr, i1* %c_ptr) {
59; CHECK-LABEL: @f_3(
60; CHECK-NOT: loop.us:
61entry:
62  br label %loop
63
64loop:
65  %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]
66  %iv.inc = add i32 %iv, 1
67  %c = load volatile i1, i1* %c_ptr
68  call void(i1, ...) @llvm.experimental.guard(i1 %c) [ "deopt"() ]
69  store volatile i32 0, i32* %ptr
70  %becond = icmp ult i32 %iv.inc, %n
71  br i1 %becond, label %leave, label %loop
72
73leave:
74  ret void
75}
76
77define void @f_4(i32 %n, i32* %ptr, i1 %c) {
78; CHECK-LABEL: @f_4(
79;
80; Demonstrate that unswitching on one guard can cause another guard to
81; be erased (this has implications on what guards we can keep raw
82; pointers to).
83entry:
84  br label %loop
85
86loop:
87  %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]
88  %iv.inc = add i32 %iv, 1
89  call void(i1, ...) @llvm.experimental.guard(i1 %c) [ "deopt"(i32 1) ]
90  store volatile i32 0, i32* %ptr
91  %neg = xor i1 %c, 1
92  call void(i1, ...) @llvm.experimental.guard(i1 %neg) [ "deopt"(i32 2) ]
93  %becond = icmp ult i32 %iv.inc, %n
94  br i1 %becond, label %leave, label %loop
95
96leave:
97  ret void
98}
99