1 ; RUN: opt -simple-loop-unswitch-memoryssa-threshold=0 -memssa-check-limit=1 -passes='loop-mssa(simple-loop-unswitch<nontrivial>),verify<loops>' -S < %s | FileCheck --check-prefix=THRESHOLD-0 %s
2 ; RUN: opt -memssa-check-limit=1 -passes='loop-mssa(simple-loop-unswitch<nontrivial>),verify<loops>' -S < %s | FileCheck --check-prefix=THRESHOLD-DEFAULT %s
4 ; Make sure -loop-unswitch-memoryssa-threshold works. The test uses
5 ; -memssa-check-limit=1 to effectively disable any MemorySSA optimizations
6 ; on construction, so the test can be kept simple.
8 declare void @clobber()
10 ; Partial unswitching is possible, because the store in %noclobber does not
11 ; alias the load of the condition.
12 define i32 @partial_unswitch_true_successor_noclobber(ptr noalias %ptr.1, ptr noalias %ptr.2, i32 %N) {
13 ; THRESHOLD-0-LABEL: @partial_unswitch_true_successor
15 ; THRESHOLD-0: br label %loop.header
17 ; THRESHOLD-DEFAULT-LABEL: @partial_unswitch_true_successor
18 ; THRESHOLD-DEFAULT-NEXT: entry:
19 ; THRESHOLD-DEFAULT-NEXT: [[LV:%[0-9]+]] = load i32, ptr %ptr.1, align 4
20 ; THRESHOLD-DEFAULT-NEXT: [[C:%[0-9]+]] = icmp eq i32 [[LV]], 100
21 ; THRESHOLD-DEFAULT-NEXT: br i1 [[C]]
27 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
28 %lv = load i32, ptr %ptr.1
29 %sc = icmp eq i32 %lv, 100
30 br i1 %sc, label %noclobber, label %clobber
33 %gep.1 = getelementptr i32, ptr %ptr.2, i32 %iv
34 store i32 %lv, ptr %gep.1
42 %c = icmp ult i32 %iv, %N
43 %iv.next = add i32 %iv, 1
44 br i1 %c, label %loop.header, label %exit