blob: 0b1394394e9dd67743baf687aa631cc500b2f3ce [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001; Test that LICM uses basicaa to do alias analysis, which is capable of
2; 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.
5
6; RUN: llvm-upgrade < %s | llvm-as | opt -basicaa -licm --adce | llvm-dis | not grep Loop
7
8%A = global int 7
9%B = global int 8
10%C = global [2 x int ] [ int 4, int 8 ]
11implementation
12
13int %test(bool %c) {
14 %Atmp = load int* %A
15 br label %Loop
16Loop:
17 %ToRemove = load int* %A
18 store int %Atmp, int* %B ; Store cannot alias %A
19
20 br bool %c, label %Out, label %Loop
21Out:
22 %X = sub int %ToRemove, %Atmp
23 ret int %X
24}
25
26int %test2(bool %c) {
27 br label %Loop
28Loop:
29 %AVal = load int* %A
30 %C0 = getelementptr [2 x int ]* %C, long 0, long 0
31 store int %AVal, int* %C0 ; Store cannot alias %A
32
33 %BVal = load int* %B
34 %C1 = getelementptr [2 x int ]* %C, long 0, long 1
35 store int %BVal, int* %C1 ; Store cannot alias %A, %B, or %C0
36
37 br bool %c, label %Out, label %Loop
38Out:
39 %X = sub int %AVal, %BVal
40 ret int %X
41}
42