brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.1 KiB · e2eb4f6 Raw
199 lines · plain
1; RUN: opt < %s -aa-pipeline=basic-aa,globals-aa -passes='require<globals-aa>,gvn' -S | FileCheck %s2;3; This tests the safe no-alias conclusions of GMR -- when there is4; a non-escaping global as one indentified underlying object and some pointer5; that would inherently have escaped any other function as the other underlying6; pointer of an alias query.7 8@g1 = internal global i32 09 10define i32 @test1(ptr %param) {11; Ensure that we can fold a store to a load of a global across a store to12; a parameter when the global is non-escaping.13;14; CHECK-LABEL: @test1(15; CHECK: store i32 42, ptr @g116; CHECK-NOT: load i3217; CHECK: ret i32 4218entry:19  store i32 42, ptr @g120  store i32 7, ptr %param21  %v = load i32, ptr @g122  ret i32 %v23}24 25@g1_tls = internal thread_local global i32 026 27define i32 @test1_tls(ptr %param) {28; Ensure that we can fold a store to a load of a global across a store to29; a parameter when the global is non-escaping.30;31; CHECK-LABEL: define i32 @test1_tls(32; CHECK-SAME: ptr [[PARAM:%.*]]) {33; CHECK-NEXT:  entry:34; CHECK-NEXT:    [[P:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @g1_tls)35; CHECK-NEXT:    store i32 42, ptr [[P]], align 436; CHECK-NEXT:    store i32 7, ptr [[PARAM]], align 437; CHECK-NEXT:    ret i32 4238;39entry:40  %p = call ptr @llvm.threadlocal.address(ptr @g1_tls)41  store i32 42, ptr %p42  store i32 7, ptr %param43  %p2 = call ptr @llvm.threadlocal.address(ptr @g1_tls)44  %v = load i32, ptr %p245  ret i32 %v46}47 48define ptr @test1_tls_noopt(ptr %coro, ptr %param) presplitcoroutine {49; CHECK-LABEL: define ptr @test1_tls_noopt(50; CHECK-SAME: ptr [[CORO:%.*]], ptr [[PARAM:%.*]]) #[[ATTR0:[0-9]+]] {51; CHECK-NEXT:  entry:52; CHECK-NEXT:    [[P:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @g1_tls)53; CHECK-NEXT:    store i32 42, ptr [[P]], align 454; CHECK-NEXT:    [[TMP0:%.*]] = call i8 @llvm.coro.suspend(token none, i1 false)55; CHECK-NEXT:    switch i8 [[TMP0]], label [[SUSPEND:%.*]] [56; CHECK-NEXT:      i8 0, label [[RESUME:%.*]]57; CHECK-NEXT:      i8 1, label [[SUSPEND]]58; CHECK-NEXT:    ]59; CHECK:       resume:60; CHECK-NEXT:    [[P2:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @g1_tls)61; CHECK-NEXT:    [[V:%.*]] = load i32, ptr [[P2]], align 462; CHECK-NEXT:    store i32 [[V]], ptr [[PARAM]], align 463; CHECK-NEXT:    ret ptr [[CORO]]64; CHECK:       suspend:65; CHECK-NEXT:    call void @llvm.coro.end(ptr [[CORO]], i1 false, token none)66; CHECK-NEXT:    ret ptr [[CORO]]67;68entry:69  %p = call ptr @llvm.threadlocal.address(ptr @g1_tls)70  store i32 42, ptr %p71 72  %0 = call i8 @llvm.coro.suspend(token none, i1 false)73  switch i8 %0, label %suspend [i8 0, label %resume74  i8 1, label %suspend]75resume:76  %p2 = call ptr @llvm.threadlocal.address(ptr @g1_tls)77  %v = load i32, ptr %p278  store i32 %v, ptr %param, align 479  ret ptr %coro80 81suspend:82  call void @llvm.coro.end(ptr %coro, i1 0, token none)83  ret ptr %coro84}85 86declare ptr @f()87 88define i32 @test2() {89; Ensure that we can fold a store to a load of a global across a store to90; the pointer returned by a function call. Since the global could not escape,91; this function cannot be returning its address.92;93; CHECK-LABEL: @test2(94; CHECK: store i32 42, ptr @g195; CHECK-NOT: load i3296; CHECK: ret i32 4297entry:98  %ptr = call ptr @f() readnone99  store i32 42, ptr @g1100  store i32 7, ptr %ptr101  %v = load i32, ptr @g1102  ret i32 %v103}104 105@g2 = external global ptr106 107define i32 @test3() {108; Ensure that we can fold a store to a load of a global across a store to109; the pointer loaded from that global. Because the global does not escape, it110; cannot alias a pointer loaded out of a global.111;112; CHECK-LABEL: @test3(113; CHECK: store i32 42, ptr @g1114; CHECK: store i32 7, ptr115; CHECK-NOT: load i32116; CHECK: ret i32 42117entry:118  store i32 42, ptr @g1119  %ptr1 = load ptr, ptr @g2120  store i32 7, ptr %ptr1121  %v = load i32, ptr @g1122  ret i32 %v123}124 125@g3 = internal global i32 1126@g4 = internal global [10 x ptr] zeroinitializer127 128define i32 @test4(ptr %param, i32 %n, i1 %c1, i1 %c2, i1 %c3) {129; Ensure that we can fold a store to a load of a global across a store to130; the pointer loaded from that global even when the load is behind PHIs and131; selects, and there is a mixture of a load and another global or argument.132; Note that we can't eliminate the load here because it is used in a PHI and133; GVN doesn't try to do real DCE. The store is still forwarded by GVN though.134;135; CHECK-LABEL: @test4(136; CHECK: store i32 42, ptr @g1137; CHECK: store i32 7, ptr138; CHECK: ret i32 42139entry:140  %call = call ptr @f()141  store i32 42, ptr @g1142  %ptr1 = load ptr, ptr @g2143  %ptr2 = select i1 %c1, ptr %ptr1, ptr %param144  %ptr3 = select i1 %c3, ptr %ptr2, ptr @g3145  br label %loop146 147loop:148  %iv = phi i32 [ 0, %entry ], [ %inc, %loop ]149  %ptr = phi ptr [ %ptr3, %entry ], [ %ptr5, %loop ]150  store i32 7, ptr %ptr151  %ptr4 = load ptr, ptr getelementptr ([10 x ptr], ptr @g4, i32 0, i32 1)152  %ptr5 = select i1 %c2, ptr %ptr4, ptr %call153  %inc = add i32 %iv, 1154  %test = icmp slt i32 %inc, %n155  br i1 %test, label %loop, label %exit156 157exit:158  %v = load i32, ptr @g1159  ret i32 %v160}161 162define i32 @test5(ptr %param) {163; Ensure that we can fold a store to a load of a global across a store to164; a parameter that has been dereferenced when the global is non-escaping.165;166; CHECK-LABEL: @test5(167; CHECK: %p = load ptr168; CHECK: store i32 42, ptr @g1169; CHECK-NOT: load i32170; CHECK: ret i32 42171entry:172  %p = load ptr, ptr %param173  store i32 42, ptr @g1174  store i32 7, ptr %p175  %v = load i32, ptr @g1176  ret i32 %v177}178 179define i32 @test6(ptr %param) {180; Ensure that we can fold a store to a load of a global across a set of181; calls that cannot use in any way a non-escaping global.182;183; CHECK-LABEL: @test6(184; CHECK: store i32 42, ptr @g1185; CHECK-NOT: load i32186; CHECK: ret i32 42187entry:188  store i32 42, ptr @g1189  %1 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr null, i64 3, ptr null, i32 6, ptr null, i32 2)190  %2 = call i1 @_FortranAioOutputAscii(ptr %1, ptr null, i64 4)191  %3 = call i32 @_FortranAioEndIoStatement(ptr %1)192  %v = load i32, ptr @g1193  ret i32 %v194}195declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) #0196declare zeroext i1 @_FortranAioOutputAscii(ptr, ptr, i64) #0197declare i32 @_FortranAioEndIoStatement(ptr) #0198attributes #0 = { nocallback nosync }199