[llvm] [SPIR-V] Implement SPV_KHR_float_controls2 (PR #146941)
Marcos Maronas via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 16 12:11:13 PDT 2025
maarquitos14 wrote:
> Code seems a bit convoluted to me with parts that could definitely be refactored (ex the iteration on each type and MI construction for the decoration)
Indeed, your version is much easier to read and understand. I have changed that.
> Looks like the metadata gathering, flag conflict validation and only then decoration emission could be split into distinct, independent pieces.
That is what I tried to do, more specifically:
- `collectFPFastMathDefaults` iterates through `spirv.ExecutionMode` metadata to find `FPFastMathDefault`, `SignedZeroInfNanPreserve`, and `ContractionOff` execution modes, and stores the information in `FPFastMathDefaultInfoMap`.
- `addDecorations` calls `handleMIFlagDecoration`, where we use `FPFastMathDefaultInfo` to add `FPFastMathMode` decoration.
- `outputExecutionMode` skips `FPFastMathDefault`, `SignedZeroInfNanPreserve`, and `ContractionOff` execution modes, and calls `outputFPFastMathDefaultInfo` to handle them later.
- `outputFPFastMathDefaultInfo` emits `FPFastMathDefault` execution mode for each required function and type.
- `outputExecutionMode`, when there is no `spirv.ExecutionMode` metadata and no `opencl.enable.FP_CONTRACT` metadata needs to emit `ContractionOff` execution mode. However, when `SPV_KHR_float_controls2` is enabled, `ContractionOff` is deprecated, so we replace it with `FPFastMathDefault`. I understand this might be a little bit redundant, but it's not exactly the same as earlier, although they have common parts.
> Another question: reading the float_control2 spec, seems like it could be enabled for Shaders since the capability is not gated by the Kernel one. But looks like the SPIRVAsmPrinter part is gated on `ST->isKernel`
This is only for the specific branch taken when there is no `spirv.ExecutionMode` metadata and no `opencl.enable.FP_CONTRACT` metadata. I didn't change that condition, simply added a new branch to replace `ContractionOff` with `FPFastMathDefault` if `SPV_KHR_float_controls2` is enabled, because, like I said before, `ContractionOff` is deprecated with the extension enabled.
https://github.com/llvm/llvm-project/pull/146941
More information about the llvm-commits
mailing list