[llvm] [SPIR-V] Implement selection for llvm.canonicalize(x) as fmul(x, 1.0) (PR #178439)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 29 05:07:13 PST 2026
================
@@ -3007,6 +3012,33 @@ SPIRVInstructionSelector::buildI32Constant(uint32_t Val, MachineInstr &I,
return {NewReg, Result};
}
+bool SPIRVInstructionSelector::selectFCanonicalize(Register ResVReg,
+ const SPIRVType *ResType,
+ MachineInstr &I) const {
+ // There is no native fcanonicalize instruction in SPIRV. We can lower it to:
+ // - fmin(x, x) or
+ // - fmul(x, 1.0)
+ //
+ // We use fmul(x, 1.0) here, because:
+ // - llvm-spirv translates fmin to a function call, whereas
+ // fmul is translated to the LLVM fmul instruction.
----------------
arsenm wrote:
I have been questioning whether we should keep maintaining this system of permitting canonicalize dropping. However, that still would not imply mandating fmul flush under a flushing environment. At minimum I think we need to stop allowing canonicalize dropping in codegen
https://github.com/llvm/llvm-project/pull/178439
More information about the llvm-commits
mailing list