1 ; RUN: opt < %s -S -basicaa -licm | FileCheck %s
3 ; Check that we can hoist unordered loads
4 define i32 @test1(i32* nocapture %y) nounwind uwtable ssp {
9 %i = phi i32 [ %inc, %loop ], [ 0, %entry ]
10 %val = load atomic i32, i32* %y unordered, align 4
11 %inc = add nsw i32 %i, 1
12 %exitcond = icmp eq i32 %inc, %val
13 br i1 %exitcond, label %end, label %loop
17 ; CHECK-LABEL: define i32 @test1(
19 ; CHECK-NEXT: br label %loop
22 ; Check that we don't sink/hoist monotonic loads
23 ; (Strictly speaking, it's not forbidden, but it's supposed to be possible to
24 ; use monotonic for spinlock-like constructs.)
25 define i32 @test2(i32* nocapture %y) nounwind uwtable ssp {
30 %val = load atomic i32, i32* %y monotonic, align 4
31 %exitcond = icmp ne i32 %val, 0
32 br i1 %exitcond, label %end, label %loop
36 ; CHECK-LABEL: define i32 @test2(
38 ; CHECK-NEXT: %exitcond = icmp ne
39 ; CHECK-NEXT: br i1 %exitcond, label %end, label %loop
42 ; Check that we hoist unordered around monotonic.
43 ; (The noalias shouldn't be necessary in theory, but LICM isn't quite that
45 define i32 @test3(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
50 %vala = load atomic i32, i32* %y monotonic, align 4
51 %valb = load atomic i32, i32* %x unordered, align 4
52 %exitcond = icmp ne i32 %vala, %valb
53 br i1 %exitcond, label %end, label %loop
57 ; CHECK-LABEL: define i32 @test3(
58 ; CHECK: load atomic i32, i32* %x unordered
59 ; CHECK-NEXT: br label %loop
62 ; Don't try to "sink" unordered stores yet; it is legal, but the machinery
64 define i32 @test4(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
69 %vala = load atomic i32, i32* %y monotonic, align 4
70 store atomic i32 %vala, i32* %x unordered, align 4
71 %exitcond = icmp ne i32 %vala, 0
72 br i1 %exitcond, label %end, label %loop
76 ; CHECK-LABEL: define i32 @test4(
77 ; CHECK: load atomic i32, i32* %y monotonic
78 ; CHECK-NEXT: store atomic