-
Notifications
You must be signed in to change notification settings - Fork 567
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
Don't inline function containing OpKill #2842
Conversation
If an OpKill instruction is inlined into a continue construct, then the spir-v is no longer valid. To avoid this issue, we do inline into an OpKill at all. This method was chosen because it is difficult to keep track of whether or not you are in a continue construct while changing the function that is being inlined into. This will work well with wrap OpKill because every will still be inlined except for the OpKill instruction itself. Fixes KhronosGroup#2554 Fixes KhronosGroup#2433 This reverts commit aa9e8f5.
I am having trouble parsing this sentence.
I am having trouble parsing this sentence too. |
Sorry, I should proof read better. I've updated it. |
I am sorry I didn't jump in on the triggering issue sooner. My biggest concern with this solution is that we are going to require folks who roll their own optimization to know about this restriction, a restriction which to me seems fairly unintuitive. It will also require them to invoke a separate function wrapping pass to get the optimization that they would normally expect from an inliner. It seems strange to me that a valid program can be made invalid through inlining, and that an invalid programming can be made valid by wrapping an instruction in a function. Judging by the threads coming from the triggering issue, I think everyone involved shares this concern to a certain extent. The current situation suggests to me that our definition of what a valid program is a little out of whack. As such, it seems to me that it might be better to fix the problem by changing the definition of a valid program rather than changing the optimizer. Given that, with this solution, we are allowing OpKill to be executed within a continue construct, albeit wrapped in its own function, it seems that outlawing OpKill within the call tree of a continue construct is not the way to go. I would rather suggest the following: where the spec says the merge block must post-dominate the continue target, we add "ignoring OpKill". That is, for the purposes of continue target validation, an OpKill in a continue construct is treated as, for example, an unconditional branch to the merge block. Given this, we would no longer need people to be aware that we don't inline functions with OpKill, which is somewhat unintuitive, and require them to preventatively call a separate pass to wrap OpKill in a function. If we think this all makes sense, for consistency we will probably want to actually add "ignoring OpKill and OpReturn", since OpReturn has a similar effect on a continue construct, though it lacks the interaction with inlining and function wrapping that OpKill has. Thoughts? |
I already brought this up with the spir-v committee. See the gitlab issue https://gitlab.khronos.org/spirv/SPIR-V/issues/459. |
Thanks for the link. It is very helpful to know what has already been discussed. FWIW, my proposal was not one of the alternatives that were considered, so I still feel it might be worth bringing up. While I agree allowing OpKill to appear in a continue construct is not a highly used capability, it would allow us to easily remove the unintuitive and draconian restriction that functions with OpKill cannot be inlined, so that is something. Still, there may be another alternative which is not quite as good but would probably be acceptable in terms of code quality, would let us remove this restriction and wouldn't require us to go back through the SPIR-V WG: Have the inliner do the OpKill wrapping itself. It would do the wrapping pass as the first thing before any inlining. A slight variation would be to have the inliner do the wrapping as part of the inlining process. The advantage here is that the user does not have to know anything about OpKill, inlining, and wrapping. Thoughts? |
Yes that could work. In general, I prefer keeping each pass as simple as possible. That is why I separated them. So I don't know how you were thinking of implementing this, but if we were to do something like that, I would want the options and api calls to imply both passes instead of having a single pass. If you have concerns about this, open another issue to discuss it. |
How does this PR fix #2554 ? |
Typo. Updated to #2454. |
Roll third_party/effcee/ 6527fb254..cd25ec17e (2 commits) google/effcee@6527fb2...cd25ec1 $ git log 6527fb254..cd25ec17e --date=short --no-merges --format='%ad %ae %s' 2019-09-18 dneto Start v2019.1-dev 2019-09-18 dneto Finalize v2019.0 Roll third_party/glslang/ 664ad41..caca1d1 (12 commits) KhronosGroup/glslang@664ad41...caca1d1 $ git log 664ad41..caca1d1 --date=short --no-merges --format='%ad %ae %s' 2019-09-17 cepheus SPV_KHR_physical_storage_buffer/SPV: Add GL_EXT_buffer_reference_uvec2 2019-09-16 digit Fix Fuchsia build. 2019-09-18 cepheus README: Fix WASM typos. 2019-09-18 cepheus HLSL: Fix KhronosGroup#1903 Catch 0-argument case to constructors. 2019-09-08 jbolz Add GL_EXT_shader_subgroup_extended_types support 2019-08-28 cepheus GLSL: Only require constant for subgroupBroadcast when SPV < 1.5. 2019-08-18 cepheus SPV: Support SPIR-V 1.5; five extensions no longer need OpExtension. 2019-09-09 laddoc Add flags for local size values ( compute shader ) 2019-09-13 cepheus SPV 1.5: Switch to the 1.5 header, for SPIR-V 1.5. 2019-09-11 dsinclair Comment out params instead of removing 2019-09-10 dsinclair Remove unused params 2019-09-09 rex.xu Fix incorrect function prototypes of 64-bit findLSB/findMSB Roll third_party/googletest/ 3f05f651a..f2fb48c3b (9 commits) google/googletest@3f05f65...f2fb48c $ git log 3f05f651a..f2fb48c3b --date=short --no-merges --format='%ad %ae %s' 2019-09-16 krystian.kuzniarek Googletest export 2019-09-13 misterg Googletest export 2019-09-12 hgsilverman Googletest export 2019-09-11 absl-team Googletest export 2019-09-10 absl-team Googletest export 2019-09-09 absl-team Googletest export 2019-09-06 absl-team Googletest export 2019-09-06 absl-team Googletest export 2019-08-12 krystian.kuzniarek restore mistakenly removed iffs in their explicit form Roll third_party/spirv-cross/ b32a1b415..5431e1da2 (7 commits) KhronosGroup/SPIRV-Cross@b32a1b4...5431e1d $ git log b32a1b415..5431e1da2 --date=short --no-merges --format='%ad %ae %s' 2019-09-19 post Update SPIR-V headers. 2019-09-19 post MSL: Fix 16-bit integer literals. 2019-09-18 rharrison Update external/ to SPIR-V 1.5 2019-09-18 post CMake: Add option to force -fPIC. 2019-09-17 post Fix -Wshorten-64-to-32 warnings. 2019-09-16 post CMake: Add option to skip installation targets. 2019-09-12 post Consider discard and demote as impure statements. Roll third_party/spirv-headers/ 38cafab..601d738 (2 commits) KhronosGroup/SPIRV-Headers@38cafab...601d738 $ git log 38cafab..601d738 --date=short --no-merges --format='%ad %ae %s' 2019-09-18 cepheus Add SPV_KHR_physical_storage_buffer. 2019-09-13 cepheus SPIR-V 1.5. Roll third_party/spirv-tools/ 76261e2..08fcf8a (28 commits) KhronosGroup/SPIRV-Tools@76261e2...08fcf8a $ git log 76261e2..08fcf8a --date=short --no-merges --format='%ad %ae %s' 2019-09-19 ehsannas Fix header include syntax. (KhronosGroup#2882) 2019-09-19 stevenperron Handle OpConstantNull in copy-prop-arrays. (KhronosGroup#2870) 2019-09-19 dneto Fix comment typo found by protobufs linter (KhronosGroup#2884) 2019-09-19 dsinclair Move docs into docs/ folder (KhronosGroup#2872) 2019-09-18 dsinclair Add WebGPU SPIR-V Assembler in JavaScript. (KhronosGroup#2876) 2019-09-18 dneto Android.mk: Add dependency from optimizer file to amd-shader-ballot-insts.inc (KhronosGroup#2883) 2019-09-18 dneto Update SPIRV-Headers in DEPS (KhronosGroup#2880) 2019-09-18 afdx Fix detection of blocks bypassed by new edge (KhronosGroup#2874) 2019-09-18 afdx Fix CMake issue related to spirv-fuzz (KhronosGroup#2877) 2019-09-18 afdx Add fuzzer pass to replace ids with synonyms (KhronosGroup#2857) 2019-09-18 alanbaker Relaxed bitcast with pointers (KhronosGroup#2878) 2019-09-17 52076061+digit-google Fix Fuchsia build. (KhronosGroup#2868) 2019-09-16 raun.krisch Adding valilidation checks for OpEntryPoint duplicate names and execution mode (KhronosGroup#2862) 2019-09-16 alanbaker Extra resource interface validation (KhronosGroup#2864) 2019-09-13 alanbaker Split capability tests (KhronosGroup#2866) 2019-09-13 alanbaker SPIRV-Tools support for SPIR-V 1.5 (KhronosGroup#2865) 2019-09-11 afdx Add fuzzer pass to copy objects (KhronosGroup#2853) 2019-09-11 rharrison Handle another case where creating a constant can fail (KhronosGroup#2854) 2019-09-11 stevenperron Don't inline function containing OpKill (KhronosGroup#2842) 2019-09-11 stevenperron Handle id overflow in wrap op kill. (KhronosGroup#2851) 2019-09-11 dneto Assembler: Can't set an ID in instruction without result ID (KhronosGroup#2852) 2019-09-10 zoddicus Handle creating a new constant failing gracefully (KhronosGroup#2848) 2019-09-10 afdx Rework management of probabilities in spirv-fuzz (KhronosGroup#2839) 2019-09-10 afdx Fix add-dead-break and add-dead-continue passes to respect dominance (KhronosGroup#2838) 2019-09-10 stevenperron Handle id overflow in the ssa rewriter. (KhronosGroup#2845) 2019-09-09 stevenperron Handle id overflow in the constant manager. (KhronosGroup#2844) 2019-09-09 alanbaker Add generic builtin validation of target (KhronosGroup#2843) 2019-09-09 stevenperron Don't register duplicate decoration in validator. (KhronosGroup#2841) Created with: roll-dep third_party/effcee third_party/glslang third_party/googletest third_party/re2 third_party/spirv-cross third_party/spirv-headers third_party/spirv-tools
If an OpKill instruction is inlined into a continue construct, then the
spir-v is no longer valid. To avoid this issue, we do not inline functions containing an
OpKill at all. This method was chosen because it is difficult to keep
track of whether or not you are in a continue construct while changing
the function that is being inlined into. This will work well with wrap
OpKill because all other instructions will still be inlined.
Fixes #2454
Fixes #2433