• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -S -basicaa -licm | FileCheck %s
2; RUN: opt -aa-pipeline=basic-aa -passes='lcssa,require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' < %s -S | FileCheck %s
3
4; Check that we can hoist unordered loads
5define i32 @test1(i32* nocapture %y) nounwind uwtable ssp {
6entry:
7  br label %loop
8
9loop:
10  %i = phi i32 [ %inc, %loop ], [ 0, %entry ]
11  %val = load atomic i32, i32* %y unordered, align 4
12  %inc = add nsw i32 %i, 1
13  %exitcond = icmp eq i32 %inc, %val
14  br i1 %exitcond, label %end, label %loop
15
16end:
17  ret i32 %val
18; CHECK-LABEL: define i32 @test1(
19; CHECK: load atomic
20; CHECK-NEXT: br label %loop
21}
22
23; Check that we don't sink/hoist monotonic loads
24; (Strictly speaking, it's not forbidden, but it's supposed to be possible to
25; use monotonic for spinlock-like constructs.)
26define i32 @test2(i32* nocapture %y) nounwind uwtable ssp {
27entry:
28  br label %loop
29
30loop:
31  %val = load atomic i32, i32* %y monotonic, align 4
32  %exitcond = icmp ne i32 %val, 0
33  br i1 %exitcond, label %end, label %loop
34
35end:
36  ret i32 %val
37; CHECK-LABEL: define i32 @test2(
38; CHECK: load atomic
39; CHECK-NEXT: %exitcond = icmp ne
40; CHECK-NEXT: br i1 %exitcond, label %end, label %loop
41}
42
43; Check that we hoist unordered around monotonic.
44; (The noalias shouldn't be necessary in theory, but LICM isn't quite that
45; smart yet.)
46define i32 @test3(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
47entry:
48  br label %loop
49
50loop:
51  %vala = load atomic i32, i32* %y monotonic, align 4
52  %valb = load atomic i32, i32* %x unordered, align 4
53  %exitcond = icmp ne i32 %vala, %valb
54  br i1 %exitcond, label %end, label %loop
55
56end:
57  ret i32 %vala
58; CHECK-LABEL: define i32 @test3(
59; CHECK: load atomic i32, i32* %x unordered
60; CHECK-NEXT: br label %loop
61}
62
63; Don't try to "sink" unordered stores yet; it is legal, but the machinery
64; isn't there.
65define i32 @test4(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
66entry:
67  br label %loop
68
69loop:
70  %vala = load atomic i32, i32* %y monotonic, align 4
71  store atomic i32 %vala, i32* %x unordered, align 4
72  %exitcond = icmp ne i32 %vala, 0
73  br i1 %exitcond, label %end, label %loop
74
75end:
76  ret i32 %vala
77; CHECK-LABEL: define i32 @test4(
78; CHECK: load atomic i32, i32* %y monotonic
79; CHECK-NEXT: store atomic
80}
81