blob: 1bd375cf4d2d40ee0a8ae6084375cb43cb6d8492 [file] [log] [blame]
Florian Hahnbee48682021-01-21 09:32:04 +00001; RUN: opt -loop-unswitch -loop-unswitch-memoryssa-threshold=0 -memssa-check-limit=1 -enable-new-pm=0 -S %s | FileCheck --check-prefix=THRESHOLD-0 %s
2; RUN: opt -loop-unswitch -memssa-check-limit=1 -S -enable-new-pm=0 %s | FileCheck --check-prefix=THRESHOLD-DEFAULT %s
3
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.
7
8declare void @clobber()
9
10; Partial unswitching is possible, because the store in %noclobber does not
11; alias the load of the condition.
12define i32 @partial_unswitch_true_successor_noclobber(i32* noalias %ptr.1, i32* noalias %ptr.2, i32 %N) {
13; THRESHOLD-0-LABEL: @partial_unswitch_true_successor
14; THRESHOLD-0: entry:
15; THRESHOLD-0: br label %loop.header
16;
17; THRESHOLD-DEFAULT-LABEL: @partial_unswitch_true_successor
18; THRESHOLD-DEFAULT-NEXT: entry:
19; THRESHOLD-DEFAULT-NEXT: [[LV:%[0-9]+]] = load i32, i32* %ptr.1, align 4
20; THRESHOLD-DEFAULT-NEXT: [[C:%[0-9]+]] = icmp eq i32 [[LV]], 100
21; THRESHOLD-DEFAULT-NEXT: br i1 [[C]]
22;
23entry:
24 br label %loop.header
25
26loop.header:
27 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
28 %lv = load i32, i32* %ptr.1
29 %sc = icmp eq i32 %lv, 100
30 br i1 %sc, label %noclobber, label %clobber
31
32noclobber:
33 %gep.1 = getelementptr i32, i32* %ptr.2, i32 %iv
34 store i32 %lv, i32* %gep.1
35 br label %loop.latch
36
37clobber:
38 call void @clobber()
39 br label %loop.latch
40
41loop.latch:
42 %c = icmp ult i32 %iv, %N
43 %iv.next = add i32 %iv, 1
44 br i1 %c, label %loop.header, label %exit
45
46exit:
47 ret i32 10
48}