[llvm] [X86][SelectionDAG] - Add support for llvm.canonicalize intrinsic (PR #106370)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 29 01:37:50 PDT 2024


================
@@ -1275,6 +1275,56 @@ void SelectionDAGLegalize::LegalizeOp(SDNode *Node) {
       }
     }
     break;
+    case ISD::FCANONICALIZE: {
+      const Triple &TT = DAG.getTarget().getTargetTriple();
+      if (TT.getArch() == Triple::x86 || TT.getArch() == Triple::x86_64) {
----------------
arsenm wrote:

Your patch is mechanically broken. You shouldn't need to do any of this manual replacement you are trying to do, or inspect the values of the incoming operand. Please remove all attempts at handling constants from this patch. Constant folding is an optimization that should be entirely separate from legalization and selection. None of this code should be specially considering constants.

A patch to support canonicalize should only handle converting the intrinsic to either a strict_ node in the legalizer (such as strict_fmul * 1.0, or strict_fadd -0), or directly selecting to a target instruction. For the constant case, you should just end up emitting a multiply of a constant by a constant (which can be optimized later, in a separate optimization combine) 

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


More information about the llvm-commits mailing list