Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve llvmpasses test quality #49594

Merged
merged 5 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license
vchuravy marked this conversation as resolved.
Show resolved Hide resolved
; This file is a part of Julia. License is MIT: https://julialang.org/license

# RUN: julia --startup-file=no %s | opt -enable-new-pm=0 -load libjulia-codegen%shlibext -AllocOpt -S - | FileCheck %s
# RUN: julia --startup-file=no %s | opt -enable-new-pm=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='function(AllocOpt)' -S - | FileCheck %s
; RUN: opt -enable-new-pm=0 -load libjulia-codegen%shlibext -AllocOpt -S %s | FileCheck %s
; RUN: opt -enable-new-pm=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='function(AllocOpt)' -S %s | FileCheck %s

isz = sizeof(UInt) == 8 ? "i64" : "i32"

println("""
@tag = external addrspace(10) global {}
""")

# Test that the gc_preserve intrinsics are deleted directly.
; Test that the gc_preserve intrinsics are deleted directly.

# CHECK-LABEL: @preserve_branches
# CHECK: call {}*** @julia.ptls_states()
# CHECK: L1:
# CHECK-NOT: @llvm.julia.gc_preserve_begin
# CHECK-NEXT: @external_function()
# CHECK-NEXT: br i1 %b2, label %L2, label %L3
; CHECK-LABEL: @preserve_branches
; CHECK: call {}*** @julia.ptls_states()
; CHECK: L1:
; CHECK-NOT: @llvm.julia.gc_preserve_begin
; CHECK-NEXT: @external_function()
; CHECK-NEXT: br i1 %b2, label %L2, label %L3

# CHECK: L2:
# CHECK: @external_function()
# CHECK-NEXT: br label %L3
; CHECK: L2:
; CHECK: @external_function()
; CHECK-NEXT: br label %L3

# CHECK: L3:
println("""
; CHECK: L3:
define void @preserve_branches(i8* %fptr, i1 %b, i1 %b2) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
br i1 %b, label %L1, label %L3

L1:
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 8, {} addrspace(10)* @tag)
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, i64 8, {} addrspace(10)* @tag)
%tok = call token (...) @llvm.julia.gc_preserve_begin({} addrspace(10)* nonnull %v)
call void @external_function()
br i1 %b2, label %L2, label %L3
Expand All @@ -43,22 +38,20 @@ L2:
L3:
ret void
}
""")
# CHECK-LABEL: }{{$}}

# CHECK-LABEL: @preserve_branches2
# CHECK: call {}*** @julia.ptls_states()
# CHECK: L1:
# CHECK-NEXT: @llvm.julia.gc_preserve_begin{{.*}}{} addrspace(10)* %v2
# CHECK-NEXT: @external_function()
# CHECK-NEXT: br i1 %b2, label %L2, label %L3

# CHECK: L2:
# CHECK: @external_function()
# CHECK-NEXT: br label %L3

# CHECK: L3:
println("""
; CHECK-LABEL: }{{$}}

; CHECK-LABEL: @preserve_branches2
; CHECK: call {}*** @julia.ptls_states()
; CHECK: L1:
; CHECK-NEXT: @llvm.julia.gc_preserve_begin{{.*}}{} addrspace(10)* %v2
; CHECK-NEXT: @external_function()
; CHECK-NEXT: br i1 %b2, label %L2, label %L3

; CHECK: L2:
; CHECK: @external_function()
; CHECK-NEXT: br label %L3

; CHECK: L3:
define void @preserve_branches2(i8* %fptr, i1 %b, i1 %b2) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
Expand All @@ -67,7 +60,7 @@ define void @preserve_branches2(i8* %fptr, i1 %b, i1 %b2) {
br i1 %b, label %L1, label %L3

L1:
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 8, {} addrspace(10)* @tag)
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, i64 8, {} addrspace(10)* @tag)
%tok = call token (...) @llvm.julia.gc_preserve_begin({} addrspace(10)* %v, {} addrspace(10)* nonnull %v2)
call void @external_function()
br i1 %b2, label %L2, label %L3
Expand All @@ -79,57 +72,50 @@ L2:
L3:
ret void
}
""")
# CHECK-LABEL: }{{$}}

# CHECK-LABEL: @legal_int_types
# CHECK: alloca [12 x i8]
# CHECK-NOT: alloca i96
# CHECK: ret void
println("""
; CHECK-LABEL: }{{$}}

; CHECK-LABEL: @legal_int_types
; CHECK: alloca [12 x i8]
; CHECK-NOT: alloca i96
; CHECK: ret void
define void @legal_int_types() {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
%var1 = call {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 12, {} addrspace(10)* @tag)
%var1 = call {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, i64 12, {} addrspace(10)* @tag)
%var2 = addrspacecast {} addrspace(10)* %var1 to {} addrspace(11)*
%var3 = call {}* @julia.pointer_from_objref({} addrspace(11)* %var2)
ret void
}
""")
# CHECK-LABEL: }{{$}}

; CHECK-LABEL: }{{$}}


println("""
declare void @external_function()
declare {} addrspace(10)* @external_function2()
declare {}*** @julia.ptls_states()
declare {}*** @julia.get_pgcstack()
declare noalias {} addrspace(10)* @julia.gc_alloc_obj(i8*, $isz, {} addrspace(10)*)
declare noalias {} addrspace(10)* @julia.gc_alloc_obj(i8*, i64, {} addrspace(10)*)
declare {}* @julia.pointer_from_objref({} addrspace(11)*)
declare void @llvm.memcpy.p11i8.p0i8.i64(i8 addrspace(11)* nocapture writeonly, i8* nocapture readonly, i64, i32, i1)
declare token @llvm.julia.gc_preserve_begin(...)
declare void @llvm.julia.gc_preserve_end(token)
""")

# CHECK-LABEL: @memref_collision
# CHECK: call {}*** @julia.ptls_states()
# CHECK-NOT: store {}
# CHECK: store i
# CHECK-NOT: store {}
# CHECK: L1:
# CHECK: load {}
# CHECK: L2:
# CHECK: load i
println("""
define void @memref_collision($isz %x) {

; CHECK-LABEL: @memref_collision
; CHECK: call {}*** @julia.ptls_states()
; CHECK-NOT: store {}
; CHECK: store i
; CHECK-NOT: store {}
; CHECK: L1:
; CHECK: load {}
; CHECK: L2:
; CHECK: load i
define void @memref_collision(i64 %x) {
%pgcstack = call {}*** @julia.get_pgcstack()
%ptls = call {}*** @julia.ptls_states()
%ptls_i8 = bitcast {}*** %ptls to i8*
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, $isz 8, {} addrspace(10)* @tag)
%v_p = bitcast {} addrspace(10)* %v to $isz addrspace(10)*
store $isz %x, $isz addrspace(10)* %v_p
%v = call noalias {} addrspace(10)* @julia.gc_alloc_obj(i8* %ptls_i8, i64 8, {} addrspace(10)* @tag)
%v_p = bitcast {} addrspace(10)* %v to i64 addrspace(10)*
store i64 %x, i64 addrspace(10)* %v_p
br i1 0, label %L1, label %L2

L1:
Expand All @@ -138,9 +124,8 @@ L1:
ret void

L2:
%v2 = bitcast {} addrspace(10)* %v to $isz addrspace(10)*
%v2 = bitcast {} addrspace(10)* %v to i64 addrspace(10)*
%v2_x = load i64, i64 addrspace(10)* %v2
ret void
}
""")
# CHECK-LABEL: }{{$}}
; CHECK-LABEL: }{{$}}
2 changes: 2 additions & 0 deletions test/llvmpasses/alloc-opt-unsized.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
; This file is a part of Julia. License is MIT: https://julialang.org/license

; RUN: opt -enable-new-pm=0 -load libjulia-codegen%shlibext -AllocOpt -S %s | FileCheck %s

source_filename = "text"
Expand Down
2 changes: 2 additions & 0 deletions test/llvmpasses/cpu-features.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
; This file is a part of Julia. License is MIT: https://julialang.org/license

; RUN: opt -enable-new-pm=0 -load libjulia-codegen%shlibext -CPUFeatures -simplifycfg -S %s | FileCheck %s
; RUN: opt -enable-new-pm=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='CPUFeatures,simplifycfg' -S %s | FileCheck %s

Expand Down
2 changes: 2 additions & 0 deletions test/llvmpasses/final-lower-gc-addrspaces.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
; This file is a part of Julia. License is MIT: https://julialang.org/license

; RUN: opt -enable-new-pm=0 -load libjulia-codegen%shlibext -FinalLowerGC -S %s | FileCheck %s
; RUN: opt -enable-new-pm=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='FinalLowerGC' -S %s | FileCheck %s

Expand Down
2 changes: 2 additions & 0 deletions test/llvmpasses/final-lower-gc.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
; This file is a part of Julia. License is MIT: https://julialang.org/license

; RUN: opt -enable-new-pm=0 -load libjulia-codegen%shlibext -FinalLowerGC -S %s | FileCheck %s
; RUN: opt -enable-new-pm=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='FinalLowerGC' -S %s | FileCheck %s

Expand Down
2 changes: 2 additions & 0 deletions test/llvmpasses/gcroots.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
; This file is a part of Julia. License is MIT: https://julialang.org/license

; RUN: opt -enable-new-pm=0 -load libjulia-codegen%shlibext -LateLowerGCFrame -FinalLowerGC -S %s | FileCheck %s
; RUN: opt -enable-new-pm=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='function(LateLowerGCFrame),FinalLowerGC' -S %s | FileCheck %s

Expand Down
96 changes: 96 additions & 0 deletions test/llvmpasses/julia-licm-fail.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
; This file is a part of Julia. License is MIT: https://julialang.org/license

; RUN: opt -enable-new-pm=0 -load libjulia-codegen%shlibext -JuliaLICM -S %s | FileCheck %s
; RUN: opt -enable-new-pm=1 --load-pass-plugin=libjulia-codegen%shlibext -passes='JuliaLICM' -S %s | FileCheck %s

; COM: This file contains functions that should not trigger allocations to be hoisted out of loops
vchuravy marked this conversation as resolved.
Show resolved Hide resolved

@tag = external addrspace(10) global {}, align 16

; COM: Tests that an escape in a loop prevents hoisting of the allocation
; CHECK-LABEL: @julia_escape_alloc
define void @julia_escape_alloc(i1 %ret) {
top:
%pgcstack = call {}*** @julia.get_pgcstack()
%current_task = bitcast {}*** %pgcstack to {}**
; CHECK: br label %preheader
br label %preheader
; CHECK: preheader:
preheader:
; CHECK-NOT: julia.gc_alloc_obj
; CHECK-NEXT: br label %loop
br label %loop
; CHECK: loop:
loop:
; CHECK-NEXT: %alloc = call noalias nonnull {} addrspace(10)* @julia.gc_alloc_obj({}** nonnull %current_task, i64 8, {} addrspace(10)* @tag)
%alloc = call noalias nonnull {} addrspace(10)* @julia.gc_alloc_obj({}** nonnull %current_task, i64 8, {} addrspace(10)* @tag)
; CHECK-NEXT: %ignore = call {} addrspace(10)* @escape({} addrspace(10)* %alloc)
%ignore = call {} addrspace(10)* @escape({} addrspace(10)* %alloc)
br i1 %ret, label %return, label %loop
return:
ret void
}

; COM: Tests that addrescape in a loop prevents hoisting of the allocation
; CHECK-LABEL: @julia_addrescape_alloc
define void @julia_addrescape_alloc(i1 %ret) {
top:
%pgcstack = call {}*** @julia.get_pgcstack()
%current_task = bitcast {}*** %pgcstack to {}**
; CHECK: br label %preheader
br label %preheader
; CHECK: preheader:
preheader:
; CHECK-NOT: julia.gc_alloc_obj
; CHECK-NEXT: br label %loop
br label %loop
; CHECK: loop:
loop:
; CHECK-NEXT: %alloc = call noalias nonnull {} addrspace(10)* @julia.gc_alloc_obj({}** nonnull %current_task, i64 8, {} addrspace(10)* @tag)
%alloc = call noalias nonnull {} addrspace(10)* @julia.gc_alloc_obj({}** nonnull %current_task, i64 8, {} addrspace(10)* @tag)
; CHECK-NEXT: %cast = addrspacecast {} addrspace(10)* %alloc to {} addrspace(11)*
%cast = addrspacecast {} addrspace(10)* %alloc to {} addrspace(11)*
; CHECK-NEXT: %ptr = call nonnull {}* @julia.pointer_from_objref({} addrspace(11)* %cast)
%ptr = call nonnull {}* @julia.pointer_from_objref({} addrspace(11)* %cast)
br i1 %ret, label %return, label %loop
return:
ret void
}

declare void @julia.write_barrier({}*, ...)

declare {}*** @julia.get_pgcstack()

; Function Attrs: allocsize(1)
declare noalias nonnull {} addrspace(10)* @julia.gc_alloc_obj({}**, i64, {} addrspace(10)*) #1

; Function Attrs: argmemonly nofree nosync nounwind willreturn
declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #2

; Function Attrs: argmemonly nofree nosync nounwind willreturn
declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #2

; Function Attrs: inaccessiblemem_or_argmemonly
declare void @ijl_gc_queue_root({} addrspace(10)*) #3

; Function Attrs: allocsize(1)
declare noalias nonnull {} addrspace(10)* @ijl_gc_pool_alloc(i8*, i32, i32) #1

; Function Attrs: allocsize(1)
declare noalias nonnull {} addrspace(10)* @ijl_gc_big_alloc(i8*, i64) #1

; COM: escape to make it easy to find
declare nonnull {} addrspace(10)* @escape({} addrspace(10)*)

; COM: addrescape function
declare nonnull {}* @julia.pointer_from_objref({} addrspace(11)*)

attributes #0 = { "probe-stack"="inline-asm" }
attributes #1 = { allocsize(1) }
attributes #2 = { argmemonly nofree nosync nounwind willreturn }
attributes #3 = { inaccessiblemem_or_argmemonly }

!llvm.module.flags = !{!0, !1}

!0 = !{i32 2, !"Dwarf Version", i32 4}
!1 = !{i32 2, !"Debug Info Version", i32 3}
Loading