1 ; RUN: opt -O3 -S < %s -enable-new-pm=0 | FileCheck %s
2 ; RUN: opt -passes='default<O3>' -S < %s | FileCheck %s
3 target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
4 target triple = "aarch64"
6 @v = internal unnamed_addr global i32 0, align 4
7 @p = common global i32* null, align 8
10 ; This test checks that a number of loads and stores are eliminated,
11 ; that can only be eliminated based on GlobalsAA information. As such,
12 ; it tests that GlobalsAA information is retained until the passes
13 ; that perform this optimization, and it protects against accidentally
14 ; dropping the GlobalsAA information earlier in the pipeline, which
15 ; has happened a few times.
17 ; GlobalsAA invalidation might happen later in the FunctionPassManager
18 ; pipeline than the optimization eliminating unnecessary loads/stores.
19 ; Since GlobalsAA is a module-level analysis, any FunctionPass
20 ; invalidating the GlobalsAA information will affect FunctionPass
21 ; pipelines that execute later. For example, assume a FunctionPass1 |
22 ; FunctionPass2 pipeline and 2 functions to be processed: f1 and f2.
23 ; Assume furthermore that FunctionPass1 uses GlobalsAA info to do an
24 ; optimization, and FunctionPass2 invalidates GlobalsAA. Assume the
25 ; function passes run in the following order: FunctionPass1(f1),
26 ; FunctionPass2(f1), FunctionPass1(f2), FunctionPass2(f2). Then
27 ; FunctionPass1 will not be able to optimize f2, since GlobalsAA will
28 ; have been invalidated in FuntionPass2(f1).
30 ; To try and also test this scenario, there is an empty function
31 ; before and after the function we're checking so that one of them
32 ; will be processed by the whole set of FunctionPasses before @f. That
33 ; will ensure that if the invalidation happens, it happens before the
34 ; actual optimizations on @f start.
40 ; Function Attrs: norecurse nounwind
41 define void @f(i32 %n) {
43 %0 = load i32, i32* @v, align 4
44 %inc = add nsw i32 %0, 1
45 store i32 %inc, i32* @v, align 4
46 %1 = load i32*, i32** @p, align 8
47 store i32 %n, i32* %1, align 4
48 %2 = load i32, i32* @v, align 4
49 %inc1 = add nsw i32 %2, 1
50 store i32 %inc1, i32* @v, align 4
54 ; check variable v is loaded/stored only once after optimization,
55 ; which should be prove that globalsAA survives until the optimization
56 ; that can use it to optimize away the duplicate load/stores on
58 ; CHECK: load i32, i32* @v, align 4
59 ; CHECK: store i32 {{.*}}, i32* @v, align 4
60 ; CHECK-NOT: load i32, i32* @v, align 4
61 ; CHECK-NOT: store i32 {{.*}}, i32* @v, align 4
63 ; Same as @bar above, in case the functions are processed in reverse order.