[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 22:10:22 PST 2026


================
@@ -1390,6 +1390,18 @@ void SelectionDAGISel::DoInstructionSelection() {
           Node = CurDAG->mutateStrictFPToFP(Node);
       }
 
+      // Default lowering of llvm.fcanonicalize is to replace it with
+      // multiplication by 1.0. The replacement was postponed to avoid removing
+      // it due to optimizations.
+      if (Node->getOpcode() == ISD::FCANONICALIZE &&
+          Node->getNumOperands() == 2) {
+        SDValue Operand = Node->getOperand(0);
+        SDValue One = Node->getOperand(1);
+        EVT VT = Operand.getValueType();
+        Node = CurDAG->MorphNodeTo(Node, ISD::FMUL, CurDAG->getVTList(VT),
----------------
spavloff wrote:

Such target probably uses soft-floats, as RISCV without F extension does. In this case `FCANONICALIZE` would be converted to function during type legalization and two-operand `FCANONICALIZE` (or `FCANONICALIZE_MUL`) would not be created. If the target uses more fancy scheme where `FMUL` is created but then is lowered to something, it should take care about `FCANONICALIZE`.

There is no a big difference with using `STRICT_FMUL` here.

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


More information about the llvm-commits mailing list