1; RUN: opt -S -basicaa -licm < %s | FileCheck %s
2; RUN: opt -aa-pipeline=basic-aa -passes='lcssa,require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s
3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4target triple = "x86_64-unknown-linux-gnu"
5
6declare void @f() nounwind
7
8; Don't hoist load past nounwind call.
9define i32 @test1(i32* noalias nocapture readonly %a) nounwind uwtable {
10; CHECK-LABEL: @test1(
11entry:
12  br label %for.body
13
14; CHECK: tail call void @f()
15; CHECK-NEXT: load i32
16for.body:
17  %i.06 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
18  %x.05 = phi i32 [ 0, %entry ], [ %add, %for.body ]
19  tail call void @f() nounwind
20  %i1 = load i32, i32* %a, align 4
21  %add = add nsw i32 %i1, %x.05
22  %inc = add nuw nsw i32 %i.06, 1
23  %exitcond = icmp eq i32 %inc, 1000
24  br i1 %exitcond, label %for.cond.cleanup, label %for.body
25
26for.cond.cleanup:
27  ret i32 %add
28}
29
30; Don't hoist division past nounwind call.
31define i32 @test2(i32 %N, i32 %c) nounwind uwtable {
32; CHECK-LABEL: @test2(
33entry:
34  %cmp4 = icmp sgt i32 %N, 0
35  br i1 %cmp4, label %for.body, label %for.cond.cleanup
36
37; CHECK: tail call void @f()
38; CHECK-NEXT: sdiv i32
39for.body:
40  %i.05 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
41  tail call void @f() nounwind
42  %div = sdiv i32 5, %c
43  %add = add i32 %i.05, 1
44  %inc = add i32 %add, %div
45  %cmp = icmp slt i32 %inc, %N
46  br i1 %cmp, label %for.body, label %for.cond.cleanup
47
48for.cond.cleanup:
49  ret i32 0
50}
51
52; Don't hoist load past volatile load.
53define i32 @test3(i32* noalias nocapture readonly %a, i32* %v) nounwind uwtable {
54; CHECK-LABEL: @test3(
55entry:
56  br label %for.body
57
58; CHECK: load volatile i32
59; CHECK-NEXT: load i32
60for.body:
61  %i.06 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
62  %x.05 = phi i32 [ 0, %entry ], [ %add, %for.body ]
63  %xxx = load volatile i32, i32* %v, align 4
64  %i1 = load i32, i32* %a, align 4
65  %add = add nsw i32 %i1, %x.05
66  %inc = add nuw nsw i32 %i.06, 1
67  %exitcond = icmp eq i32 %inc, 1000
68  br i1 %exitcond, label %for.cond.cleanup, label %for.body
69
70for.cond.cleanup:
71  ret i32 %add
72}
73