[llvm] [DAG] Avoid strictfp nodes in lowering of llvm.fcanonicalize (PR #177399)

Serge Pavlov via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 25 21:57:25 PST 2026


================
@@ -314,28 +314,18 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FABS(SDNode *N) {
 }
 
 SDValue DAGTypeLegalizer::SoftenFloatRes_FCANONICALIZE(SDNode *N) {
-  SDLoc dl(N);
-
   // This implements llvm.canonicalize.f* by multiplication with 1.0, as
   // suggested in
   // https://llvm.org/docs/LangRef.html#llvm-canonicalize-intrinsic.
-  // It uses strict_fp operations even outside a strict_fp context in order
-  // to guarantee that the canonicalization is not optimized away by later
-  // passes. The result chain introduced by that is intentionally ignored
-  // since no ordering requirement is intended here.
-
-  // Create strict multiplication by 1.0.
-  SDValue Operand = N->getOperand(0);
-  EVT VT = Operand.getValueType();
-  SDValue One = DAG.getConstantFP(1.0, dl, VT);
-  SDValue Chain = DAG.getEntryNode();
-  // Propagate existing flags on canonicalize, and additionally set
-  // NoFPExcept.
-  SDNodeFlags CanonicalizeFlags = N->getFlags();
-  CanonicalizeFlags.setNoFPExcept(true);
-  SDValue Mul = DAG.getNode(ISD::STRICT_FMUL, dl, {VT, MVT::Other},
-                            {Chain, Operand, One}, CanonicalizeFlags);
-  return BitConvertToInteger(Mul);
+  if (N->getNumOperands() == 1) {
+    SDLoc dl(N);
+    SDValue Operand = N->getOperand(0);
+    EVT VT = Operand.getValueType();
+    SDValue One = DAG.getConstantFP(1.0, dl, VT);
+    SDValue Mul = DAG.getNode(ISD::FCANONICALIZE, dl, VT, Operand, One);
----------------
spavloff wrote:

If fixed number of operands is a strict requirement, the patch should be reverted to use `FCANONICALIZE_MUL`. We need to distinguish between `FCANONICALIZE`, which is a generic opcode representing an operation, and `FCANONICALIZE_MUL`, which represent particular implementation of the operation. `FCANONICALIZE` can be lowered in a different way depending on the target, it can be custom or legal. `FCANONICALIZE_MUL` is a legal node, actually it is `FMUL`. It has the same purpose as `STRICT_FMUL` has now, - to prevent unwanted optimization.

https://github.com/llvm/llvm-project/pull/177399


More information about the llvm-commits mailing list