1 ; RUN: opt < %s -basicaa -sink -S | FileCheck %s
3 declare i32 @f_load_global() nounwind readonly
4 declare i32 @f_load_arg(i32*) nounwind readonly argmemonly
5 declare void @f_store_global(i32) nounwind
6 declare void @f_store_arg(i32*) nounwind argmemonly
7 declare void @f_readonly_arg(i32* readonly, i32*) nounwind argmemonly
8 declare i32 @f_readnone(i32) nounwind readnone
10 @A = external global i32
11 @B = external global i32
13 ; Sink readonly call if no stores are in the way.
15 ; CHECK-LABEL: @test_sink_no_stores(
17 ; CHECK-NEXT: %l = call i32 @f_load_global
18 ; CHECK-NEXT: ret i32 %l
19 define i32 @test_sink_no_stores(i1 %z) {
20 %l = call i32 @f_load_global()
21 br i1 %z, label %true, label %false
28 ; CHECK-LABEL: @test_sink_argmem_store(
30 ; CHECK-NEXT: %l = call i32 @f_load_arg
31 ; CHECK-NEXT: ret i32 %l
32 define i32 @test_sink_argmem_store(i1 %z) {
33 %l = call i32 @f_load_arg(i32* @A)
35 br i1 %z, label %true, label %false
42 ; CHECK-LABEL: @test_sink_argmem_call(
44 ; CHECK-NEXT: %l = call i32 @f_load_arg
45 ; CHECK-NEXT: ret i32 %l
46 define i32 @test_sink_argmem_call(i1 %z) {
47 %l = call i32 @f_load_arg(i32* @A)
48 call void @f_store_arg(i32* @B)
49 br i1 %z, label %true, label %false
56 ; CHECK-LABEL: @test_sink_argmem_multiple(
58 ; CHECK-NEXT: %l = call i32 @f_load_arg
59 ; CHECK-NEXT: ret i32 %l
60 define i32 @test_sink_argmem_multiple(i1 %z) {
61 %l = call i32 @f_load_arg(i32* @A)
62 call void @f_readonly_arg(i32* @A, i32* @B)
63 br i1 %z, label %true, label %false
70 ; But don't sink if there is a store.
72 ; CHECK-LABEL: @test_nosink_store(
73 ; CHECK: call i32 @f_load_global
74 ; CHECK-NEXT: store i32
75 define i32 @test_nosink_store(i1 %z) {
76 %l = call i32 @f_load_global()
78 br i1 %z, label %true, label %false
85 ; CHECK-LABEL: @test_nosink_call(
86 ; CHECK: call i32 @f_load_global
87 ; CHECK-NEXT: call void @f_store_global
88 define i32 @test_nosink_call(i1 %z) {
89 %l = call i32 @f_load_global()
90 call void @f_store_global(i32 0)
91 br i1 %z, label %true, label %false
98 ; readnone calls are sunk across stores.
100 ; CHECK-LABEL: @test_sink_readnone(
102 ; CHECK-NEXT: %l = call i32 @f_readnone(
103 ; CHECK-NEXT: ret i32 %l
104 define i32 @test_sink_readnone(i1 %z) {
105 %l = call i32 @f_readnone(i32 0)
107 br i1 %z, label %true, label %false