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