blob: 585ac17ae92d482ccf568a16e997091bbeb65439 [file] [log] [blame]
Chris Lattner8673e442002-08-22 20:22:55 +00001; Test that LICM uses basicaa to do alias analysis, which is capable of
Chris Lattner24a0bee2003-02-26 16:18:00 +00002; disambiguating some obvious cases. If LICM is able to disambiguate the
3; two pointers, then the load should be hoisted, and the store sunk. Thus
4; the loop becomes empty and can be deleted by ADCE.
Chris Lattner8673e442002-08-22 20:22:55 +00005
Chris Lattner24a0bee2003-02-26 16:18:00 +00006; RUN: if as < %s | opt -basicaa -licm --adce | dis | grep Loop
Chris Lattner8673e442002-08-22 20:22:55 +00007; RUN: then exit 1
8; RUN: else exit 0
9; RUN: fi
10
11%A = global int 7
12%B = global int 8
Chris Lattner1e6233a2003-03-03 23:27:15 +000013%C = global [2 x int ] [ int 4, int 8 ]
Chris Lattner8673e442002-08-22 20:22:55 +000014implementation
15
16int %test(bool %c) {
Chris Lattner92bab832002-09-07 22:48:30 +000017 %Atmp = load int* %A
Chris Lattner24a0bee2003-02-26 16:18:00 +000018 br label %Loop
Chris Lattnerbe677582003-02-24 23:14:07 +000019Loop:
20 %ToRemove = load int* %A
Chris Lattner92bab832002-09-07 22:48:30 +000021 store int %Atmp, int* %B ; Store cannot alias %A
Chris Lattner8673e442002-08-22 20:22:55 +000022
23 br bool %c, label %Out, label %Loop
24Out:
Chris Lattner4e313652003-02-24 03:52:13 +000025 %X = sub int %ToRemove, %Atmp
26 ret int %X
Chris Lattner8673e442002-08-22 20:22:55 +000027}
28
Chris Lattner1e6233a2003-03-03 23:27:15 +000029int %test2(bool %c) {
30 br label %Loop
31Loop:
32 %AVal = load int* %A
33 %C0 = getelementptr [2 x int ]* %C, long 0, long 0
34 store int %AVal, int* %C0 ; Store cannot alias %A
35
36 %BVal = load int* %B
37 %C1 = getelementptr [2 x int ]* %C, long 0, long 1
38 store int %BVal, int* %C1 ; Store cannot alias %A, %B, or %C0
39
40 br bool %c, label %Out, label %Loop
41Out:
42 %X = sub int %AVal, %BVal
43 ret int %X
44}
45