1; RUN: opt < %s -loop-predication -S | FileCheck %s
2
3;; This is a simplified copy of @unswitch_exit_form test that should trigger loop-predication
4;; activity and properly bail out when discovering that widenable check does not lead to deopt.
5;;
6;; Error checking is rather silly here - it should pass compilation successfully,
7;; in bad case it will just timeout.
8;;
9define i32 @unswitch_exit_form_with_endless_loop(i32* %array, i32 %length, i32 %n, i1 %cond_0) {
10; CHECK-LABEL: @unswitch_exit_form_with_endless_loop
11entry:
12  %widenable_cond = call i1 @llvm.experimental.widenable.condition()
13  %exiplicit_guard_cond = and i1 %cond_0, %widenable_cond
14  br i1 %exiplicit_guard_cond, label %loop.preheader, label %not_really_a_deopt, !prof !0
15
16not_really_a_deopt:
17  br label %looping
18
19looping:
20  ;; synthetic corner case that demonstrates the need for more careful traversal
21  ;; of unique successors when walking through the exit for profitability checks.
22  br label %looping
23
24loop.preheader:
25  br label %loop
26
27loop:
28  %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
29  %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
30  %within.bounds = icmp ult i32 %i, %length
31  br i1 %within.bounds, label %guarded, label %not_really_a_deopt, !prof !0
32
33guarded:
34  %i.i64 = zext i32 %i to i64
35  %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
36  %array.i = load i32, i32* %array.i.ptr, align 4
37  store i32 0, i32* %array.i.ptr
38  %loop.acc.next = add i32 %loop.acc, %array.i
39  %i.next = add nuw i32 %i, 1
40  %continue = icmp ult i32 %i.next, %n
41  br i1 %continue, label %loop, label %exit
42
43exit:
44  %result = phi i32 [ %loop.acc.next, %guarded ]
45  ret i32 %result
46}
47
48declare void @unknown()
49
50declare i1 @llvm.experimental.widenable.condition()
51declare i32 @llvm.experimental.deoptimize.i32(...)
52
53!0 = !{!"branch_weights", i32 1048576, i32 1}
54!1 = !{i32 1, i32 -2147483648}
55!2 = !{i32 0, i32 50}
56