1 ; RUN: opt -passes='loop(simple-loop-unswitch),verify<loops>' -S < %s | FileCheck %s
2 ; RUN: opt -verify-memoryssa -passes='loop-mssa(simple-loop-unswitch),verify<loops>' -S < %s | FileCheck %s
4 declare void @unknown()
5 declare void @unknown2()
7 @y = global i64 0, align 8
9 ; The following is approximately:
11 ; for (int i = 0; i < 1; ++i) {
20 ; With MemorySanitizer, the loop can not be unswitched on "y", because "y" could
21 ; be uninitialized when x == false.
22 ; Test that the branch on "y" is inside the loop (after the first unconditional
25 define void @may_not_execute_trivial(i1* %x) sanitize_memory {
26 ; CHECK-LABEL: @may_not_execute_trivial(
28 %y = load i64, i64* @y, align 8
29 %y.cmp = icmp eq i64 %y, 0
31 ; CHECK: %[[Y:.*]] = load i64, i64* @y
32 ; CHECK: %[[YCMP:.*]] = icmp eq i64 %[[Y]], 0
34 ; CHECK: br label %for.body
37 %i = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
38 %x.load = load i1, i1* %x
39 br i1 %x.load, label %for.inc, label %if.then
40 ; CHECK: %[[XLOAD:.*]] = load i1, i1* %x
41 ; CHECK: br i1 %[[XLOAD]]
44 br i1 %y.cmp, label %for.end, label %if.then4
45 ; CHECK: br i1 %[[YCMP]]
52 %inc = add nsw i32 %i, 1
53 %cmp = icmp slt i32 %inc, 1
54 br i1 %cmp, label %for.body, label %for.end
61 ; The same as above, but "y" is a function parameter instead of a global.
62 ; This shows that it is not enough to suppress hoisting of load instructions,
63 ; the actual problem is in the speculative branching.
65 define void @may_not_execute2_trivial(i1* %x, i1 %y) sanitize_memory {
66 ; CHECK-LABEL: @may_not_execute2_trivial(
70 ; CHECK: br label %for.body
73 %i = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
74 %x.load = load i1, i1* %x
75 br i1 %x.load, label %for.inc, label %if.then
76 ; CHECK: %[[XLOAD:.*]] = load i1, i1* %x
77 ; CHECK: br i1 %[[XLOAD]]
80 br i1 %y, label %for.end, label %if.then4
88 %inc = add nsw i32 %i, 1
89 %cmp = icmp slt i32 %inc, 1
90 br i1 %cmp, label %for.body, label %for.end
97 ; The following is approximately:
99 ; for (int i = 0; i < 1; ++i) {
106 ; "if (y)" is guaranteed to execute; the loop can be unswitched.
108 define void @must_execute_trivial() sanitize_memory {
109 ; CHECK-LABEL: @must_execute_trivial(
111 %y = load i64, i64* @y, align 8
112 %y.cmp = icmp eq i64 %y, 0
114 ; CHECK: %[[Y:.*]] = load i64, i64* @y
115 ; CHECK: %[[YCMP:.*]] = icmp eq i64 %[[Y]], 0
116 ; CHECK: br i1 %[[YCMP]], label %[[EXIT_SPLIT:.*]], label %[[PH:.*]]
119 ; CHECK: br label %for.body
122 %i = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
123 br i1 %y.cmp, label %for.end, label %if.then4
124 ; CHECK: br label %if.then4
131 %inc = add nsw i32 %i, 1
132 %cmp = icmp slt i32 %inc, 1
133 br i1 %cmp, label %for.body, label %for.end
138 ; CHECK: br label %[[EXIT_SPLIT]]
140 ; CHECK: [[EXIT_SPLIT]]: