You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Approach to pre-legalization of a switch statement is not able to generate correct OpSwitch instructions. It doesn't account for ranged comparisons which are always generated during IR translation step (see lib/CodeGen/GlobalISel/IRTranslator.cpp:715).
I attach a couple of example to this issue report. In brief, OpSwitch doesn't represent original CFG in cases when IRTranslator converts comparison is-equal to ranged comparisons. The corresponding case labels are getting lost in this case, including also default label. An attempt to rework this as a local patch of the pre-legalization step failed due to the general approach of the pre-legalization step itself. It's impossible to map values to basic blocks when some of values are hidden inside the ranged comparison, without more complicated semantically checks of the generated by IRTranslator dag.
because IR Translator just replaces case values with a if-style check, so that the pre-legalization step loses info needed to re-create CFG.
The proposed idea of a fix is to complicate emit-intrinsics step and get rid of the incorrect CFG re-creation during the pre-legalization step. The status of the proposed fix is "investigation of feasibility".
The text was updated successfully, but these errors were encountered:
…87823)
This PR fixes issue #87763
and preserves valid CFG in cases when previous scheme failed to generate
valid code for a switch statement. The PR hardens one existing test case
and adds one more test case as a validation of a new switch generation.
Tests are passing spirv-val now.
This PR also improves validation of forward calls.
Approach to pre-legalization of a switch statement is not able to generate correct OpSwitch instructions. It doesn't account for ranged comparisons which are always generated during IR translation step (see lib/CodeGen/GlobalISel/IRTranslator.cpp:715).
I attach a couple of example to this issue report. In brief, OpSwitch doesn't represent original CFG in cases when IRTranslator converts comparison is-equal to ranged comparisons. The corresponding case labels are getting lost in this case, including also default label. An attempt to rework this as a local patch of the pre-legalization step failed due to the general approach of the pre-legalization step itself. It's impossible to map values to basic blocks when some of values are hidden inside the ranged comparison, without more complicated semantically checks of the generated by IRTranslator dag.
will result into SPIR-V with CFG broken and -13, -14 and -15 labels lost and after reverse translation to LLVM IR you would see
Also, one of LIT tests of the project, test/CodeGen/SPIRV/branching/OpSwitchUnreachable.ll, demonstrates the same problem when it starts with
and results into
because IR Translator just replaces case values with a if-style check, so that the pre-legalization step loses info needed to re-create CFG.
The proposed idea of a fix is to complicate emit-intrinsics step and get rid of the incorrect CFG re-creation during the pre-legalization step. The status of the proposed fix is "investigation of feasibility".
The text was updated successfully, but these errors were encountered: