blob: 56682c7cabf3bc62b9614a83a90b3c819c34aa6a [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
Misha Brukmane78760e2003-09-16 15:29:54 +00006; RUN: llvm-as < %s | opt -basicaa -licm --adce | llvm-dis | not grep Loop
Chris Lattner8673e442002-08-22 20:22:55 +00007
8%A = global int 7
9%B = global int 8
Chris Lattner1e6233a2003-03-03 23:27:15 +000010%C = global [2 x int ] [ int 4, int 8 ]
Chris Lattner8673e442002-08-22 20:22:55 +000011implementation
12
13int %test(bool %c) {
Chris Lattner92bab832002-09-07 22:48:30 +000014 %Atmp = load int* %A
Chris Lattner24a0bee2003-02-26 16:18:00 +000015 br label %Loop
Chris Lattnerbe677582003-02-24 23:14:07 +000016Loop:
17 %ToRemove = load int* %A
Chris Lattner92bab832002-09-07 22:48:30 +000018 store int %Atmp, int* %B ; Store cannot alias %A
Chris Lattner8673e442002-08-22 20:22:55 +000019
20 br bool %c, label %Out, label %Loop
21Out:
Chris Lattner4e313652003-02-24 03:52:13 +000022 %X = sub int %ToRemove, %Atmp
23 ret int %X
Chris Lattner8673e442002-08-22 20:22:55 +000024}
25
Chris Lattner1e6233a2003-03-03 23:27:15 +000026int %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