Lower aborts (incl. panics) to "return from entry-point", instead of infinite loops. #1070
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We currently map the
abort
intrinsic (used almost exclusively for panic) to infinite loops, and they either:spirv-opt
or drivers (i.e. treated as UB)spirv-opt
and drivers, and cause a timeout when usedDebugPrintf
prevents panics' infinite loops from being (unsoundly) optimized away. #1048With infinite loops being so terrible, I propose we move towards a "well-defined invocation exit" approach, where we keep the "abort" as a custom instruction (using our "extended instruction set", added in #1064), and then effectively emulate the semantics of
OpTerminateInvocation
for it by:Abort
(either directly, or transitively through some functions it calls) - in the end, we should end up withAbort
s only used directly from entry-pointsAbort
s to a plainOpReturn
(from the entry-point, i.e. exiting the invocation)debugPrintf
call at this point, with the same inlining-aware "backtrace" we use elsewhere, so that the user gets some feedback if they have the validation layers enabled (and/or try to extract a panic message when we generate the abort in the first place, too)This PR implements that proposal (but without any
debugPrintf
conveniences), and so far it seems to work great, but I haven't tested the performance impact (i.e. where before the infinite loops were optimized away, now we're seeing an actual cost to various e.g. bounds checks, that need to do something at all).There are also other ways of implementing this, and we could do the
Abort
->OpReturn
rewriting very late (if we think it would be better than letting the SPIR-T structurizer see it), so there's some room to explore mitigations to perf issues, if they arise.(I will leave this PR as draft until we're sure about the perf aspects)