-
Notifications
You must be signed in to change notification settings - Fork 3
Emit our intrinsics as :calls instead of :invoke. #85
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
base: main
Are you sure you want to change the base?
Conversation
That avoids CIs, allowing easier spoofing of effects through efuncs.
src/compiler/intrinsics/atomics.jl
Outdated
| @noinline function atomic_xchg(array::TileArray{T, N}, index, val, | ||
| memory_order::Int, memory_scope::Int) where {T, N} | ||
| donotdelete() | ||
| compilerbarrier(:const, zero(T)) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need to implement this method at all? Or can we leave it at function atomic_xchg end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me try for the ones with a compiler barrier, but for others we need a valid implementation
cuTile.jl/src/compiler/intrinsics.jl
Lines 15 to 21 in 84b14b5
| # NOTE: Due to JuliaLang/julia#60583, intrinsics may be called during constant evaluation. | |
| # Because of that, such intrinsics (such as basic arithmetic) need to provide an | |
| # implementation that actually computes a valid result using Julia intrinsics. | |
| # | |
| # Sometimes that's not possible, e.g., because the functionality required for that is | |
| # overlayed by methods calling back into the intrinsic (e.g. `sin`), so for those | |
| # intrinsics we disable constant folding using a `compilerbarrier(:const)` |
Or did this change break constprop? I should verify..
vchuravy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
|
Going to minimize some of the intrinsic definitions still, removing bodies where possible. |
|
Unsure if you need it, but if you add the lattice (the weird L) as an argument to your tfunc, you can also participate in the extended lattice and as an example implement the correct behavior when you get a PartialConst |
| function tfunc(𝕃, ::typeof(Intrinsics.cmpi), @nospecialize(x), @nospecialize(y), @nospecialize(pred), @nospecialize(s)) | ||
| t = CC.widenconst(x) | ||
| if t <: Tile | ||
| S = t.parameters[2] | ||
| return Tile{Bool, S} | ||
| end | ||
| return nothing | ||
| return Bool | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nospecs and_int_tfunc(𝕃::AbstractLattice, x, y) = and_int_tfunc(widenlattice(𝕃), x, y)
@nospecs function and_int_tfunc(𝕃::ConstsLattice, x, y)
if isa(x, Const) && x.val === false && widenconst(y) === Bool
return Const(false)
elseif isa(y, Const) && y.val === false && widenconst(x) === Bool
return Const(false)
end
return and_int_tfunc(widenlattice(𝕃), x, y)
end
@nospecs and_int_tfunc(::JLTypeLattice, x, y) = widenconst(x)
So you could use something similar perhaps to return Const(true) if the cmp predicate and the arguments are all const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Altough Julia seems to have gone away from that a bit, and instead is relying on concrete eval much more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, fair point. I was going to punt on constant propagation of the intrinsics themselves for now, since most of them are called by overlay methods, which Julia (should) constant propagate using the original, non-overlay definitions. So AFAIU having proper constant propagation tfuncs doesn't really matter much for cuTile intrinsics, no?
That avoids CIs, allowing easier spoofing of effects through efuncs.
Implements #79 (comment); credit to @vchuravy for the idea.