Skip to content

Conversation

@maleadt
Copy link
Member

@maleadt maleadt commented Feb 9, 2026

That avoids CIs, allowing easier spoofing of effects through efuncs.

Implements #79 (comment); credit to @vchuravy for the idea.

That avoids CIs, allowing easier spoofing of effects through efuncs.
Comment on lines 181 to 184
@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
Copy link
Member

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

Copy link
Member Author

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

# 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..

Copy link
Member

@vchuravy vchuravy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

@maleadt
Copy link
Member Author

maleadt commented Feb 10, 2026

Going to minimize some of the intrinsic definitions still, removing bodies where possible.

@vchuravy
Copy link
Member

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

Comment on lines 128 to 135
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
Copy link
Member

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

Copy link
Member

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

https://github.com/JuliaLang/julia/blob/9484a9202916ab6e23e058ce9bbb1d91ab75c867/Compiler/src/tfuncs.jl#L275C1-L292C45

Copy link
Member Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants