• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -basicaa -licm -S | FileCheck %s
2; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s
3
4target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5target triple = "x86_64-unknown-linux-gnu"
6
7; Make sure we don't hoist the store out of the loop; %a would
8; have the wrong value if f() unwinds
9
10define void @test1(i32* nocapture noalias %a, i1 zeroext %y) uwtable {
11entry:
12  br label %for.body
13
14for.body:
15  %i.03 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
16  %0 = load i32, i32* %a, align 4
17  %add = add nsw i32 %0, 1
18  store i32 %add, i32* %a, align 4
19  br i1 %y, label %if.then, label %for.inc
20
21; CHECK: define void @test1
22; CHECK: load i32, i32*
23; CHECK-NEXT: add
24; CHECK-NEXT: store i32
25
26if.then:
27  tail call void @f()
28  br label %for.inc
29
30for.inc:
31  %inc = add nuw nsw i32 %i.03, 1
32  %exitcond = icmp eq i32 %inc, 10000
33  br i1 %exitcond, label %for.cond.cleanup, label %for.body
34
35for.cond.cleanup:
36  ret void
37}
38
39; We can hoist the store out of the loop here; if f() unwinds,
40; the lifetime of %a ends.
41
42define void @test2(i1 zeroext %y) uwtable {
43entry:
44  %a = alloca i32
45  br label %for.body
46
47for.body:
48  %i.03 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
49  %0 = load i32, i32* %a, align 4
50  %add = add nsw i32 %0, 1
51  store i32 %add, i32* %a, align 4
52  br i1 %y, label %if.then, label %for.inc
53
54if.then:
55  tail call void @f()
56  br label %for.inc
57
58for.inc:
59  %inc = add nuw nsw i32 %i.03, 1
60  %exitcond = icmp eq i32 %inc, 10000
61  br i1 %exitcond, label %for.cond.cleanup, label %for.body
62
63for.cond.cleanup:
64  ret void
65
66; CHECK: define void @test2
67; CHECK: store i32
68; CHECK-NEXT: ret void
69  ret void
70}
71
72declare void @f() uwtable
73