llvm-project
0bb35f53 - [mlir][SCFToSPIRV] Do not convert scf.index_switch with case values outside the selector (#245868)

Commit
2 days ago
[mlir][SCFToSPIRV] Do not convert scf.index_switch with case values outside the selector (#245868) The conversion of scf.index_switch built each spirv.Switch literal as APInt(selectorWidth, caseValue, /*isSigned=*/true). The case values are int64_t, while the selector is the converted index type, usually i32. A case value outside the selector's range, such as 4294967296, hit the APInt assertion "Value is not an N-bit signed value" in builds with assertions, and was truncated without them: case 4294967296 became case 0, so an index of 0 ran that case instead of the default. Fail the pattern when a case value does not fit the selector as a signed integer, and leave the switch unconverted. The scf.yield pattern erased every yield whose parent was scf.if, scf.for, scf.while or scf.index_switch, also when that parent had not been converted. A converted parent has moved its regions into a SPIR-V op, so a yield whose parent is still in scf belongs to an op that was not converted. Leave such a yield in place, so that the unconverted switch stays valid. Add tests for a case value outside i32, for one that would truncate onto another case, and for the i32 bounds, which still convert. AI-assisted: this patch was prepared with Claude Code; I have reviewed and tested the change and take responsibility for it.
Author
Parents
Loading