1 ; RUN: opt < %s -S -basicaa -licm | FileCheck %s 2 3 ; Check that we can hoist unordered loads 4 define i32 @test1(i32* nocapture %y) nounwind uwtable ssp { 5 entry: 6 br label %loop 7 8 loop: 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 14 15 end: 16 ret i32 %val 17 ; CHECK-LABEL: define i32 @test1( 18 ; CHECK: load atomic 19 ; CHECK-NEXT: br label %loop 20 } 21 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 { 26 entry: 27 br label %loop 28 29 loop: 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 33 34 end: 35 ret i32 %val 36 ; CHECK-LABEL: define i32 @test2( 37 ; CHECK: load atomic 38 ; CHECK-NEXT: %exitcond = icmp ne 39 ; CHECK-NEXT: br i1 %exitcond, label %end, label %loop 40 } 41 42 ; Check that we hoist unordered around monotonic. 43 ; (The noalias shouldn't be necessary in theory, but LICM isn't quite that 44 ; smart yet.) 45 define i32 @test3(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp { 46 entry: 47 br label %loop 48 49 loop: 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 54 55 end: 56 ret i32 %vala 57 ; CHECK-LABEL: define i32 @test3( 58 ; CHECK: load atomic i32, i32* %x unordered 59 ; CHECK-NEXT: br label %loop 60 } 61 62 ; Don't try to "sink" unordered stores yet; it is legal, but the machinery 63 ; isn't there. 64 define i32 @test4(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp { 65 entry: 66 br label %loop 67 68 loop: 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 73 74 end: 75 ret i32 %vala 76 ; CHECK-LABEL: define i32 @test4( 77 ; CHECK: load atomic i32, i32* %y monotonic 78 ; CHECK-NEXT: store atomic 79 } 80