Skip to content
This repository was archived by the owner on May 27, 2021. It is now read-only.

Commit c728b49

Browse files
committed
Add assume LLVM intrinsic.
1 parent ea087b9 commit c728b49

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/device/llvm.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# wrappers for LLVM-specific functionality
22

33
@inline trap() = ccall("llvm.trap", llvmcall, Cvoid, ())
4+
5+
@inline assume(cond::Bool) =
6+
Base.llvmcall(("declare void @llvm.assume(i1)",
7+
"%cond = icmp eq i8 %0, 1
8+
call void @llvm.assume(i1 %cond)
9+
ret void"), Nothing, Tuple{Bool}, cond)

test/device/codegen.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ end
8585
@test cpu(input) == gpu(input)
8686
end
8787

88+
@testset "assume" begin
89+
foo(i) = cld(42, i)
90+
ir = sprint(io->CUDAnative.code_llvm(io, foo, Tuple{Int}))
91+
@test occursin("@ptx_report_exception", ir)
92+
93+
94+
bar(i) = (CUDAnative.assume(i > 0); cld(42, i))
95+
ir = sprint(io->CUDAnative.code_llvm(io, bar, Tuple{Int}))
96+
@test !occursin("@ptx_report_exception", ir)
97+
end
98+
8899
end
89100

90101
############################################################################################

0 commit comments

Comments
 (0)