67 lines · plain
1; RUN: opt -passes="default<O3>" -S < %s | FileCheck %s2target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"3target triple = "aarch64"4 5@v = internal unnamed_addr global i32 0, align 46@p = common global ptr null, align 87 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 passes12; that perform this optimization, and it protects against accidentally13; dropping the GlobalsAA information earlier in the pipeline, which14; has happened a few times.15 16; GlobalsAA invalidation might happen later in the FunctionPassManager17; pipeline than the optimization eliminating unnecessary loads/stores.18; Since GlobalsAA is a module-level analysis, any FunctionPass19; invalidating the GlobalsAA information will affect FunctionPass20; 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 an23; optimization, and FunctionPass2 invalidates GlobalsAA. Assume the24; function passes run in the following order: FunctionPass1(f1),25; FunctionPass2(f1), FunctionPass1(f2), FunctionPass2(f2). Then26; FunctionPass1 will not be able to optimize f2, since GlobalsAA will27; have been invalidated in FuntionPass2(f1).28 29; To try and also test this scenario, there is an empty function30; before and after the function we're checking so that one of them31; will be processed by the whole set of FunctionPasses before @f. That32; will ensure that if the invalidation happens, it happens before the33; actual optimizations on @f start.34define void @bar() {35entry:36 ret void37}38 39; Function Attrs: norecurse nounwind40define void @f(i32 %n) {41entry:42 %0 = load i32, ptr @v, align 443 %inc = add nsw i32 %0, 144 store i32 %inc, ptr @v, align 445 %1 = load ptr, ptr @p, align 846 store i32 %n, ptr %1, align 447 %2 = load i32, ptr @v, align 448 %inc1 = add nsw i32 %2, 149 store i32 %inc1, ptr @v, align 450 ret void51}52 53; check variable v is loaded/stored only once after optimization,54; which should be prove that globalsAA survives until the optimization55; that can use it to optimize away the duplicate load/stores on56; variable v.57; CHECK: load i32, ptr @v, align 458; CHECK: store i32 {{.*}}, ptr @v, align 459; CHECK-NOT: load i32, ptr @v, align 460; CHECK-NOT: store i32 {{.*}}, ptr @v, align 461 62; Same as @bar above, in case the functions are processed in reverse order.63define void @bar2() {64entry:65 ret void66}67