[llvm] [DAG] Add generic expansion for ISD::FCANONICALIZE nodes (PR #142105)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 26 07:03:14 PDT 2025


================
@@ -3356,6 +3356,28 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
     Results.push_back(Op);
     break;
   }
+  case ISD::FCANONICALIZE: {
+    // 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.
+
+    // Get operand x.
+    SDValue Operand = Node->getOperand(0);
+    // Get fp value type used.
+    EVT VT = Operand.getValueType();
+    // Produce appropriately-typed 1.0 constant.
+    SDValue One = DAG.getConstantFP(1.0, dl, VT);
+    // Produce multiplication node x * 1.0.
----------------
RKSimon wrote:

these individual comments look superfluous?

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


More information about the llvm-commits mailing list