[PATCH] D91331: [NFC] Add hook for target to customize different legalization action according to the input type

Qing Shan Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 16 01:39:21 PST 2020


steven.zhang updated this revision to Diff 305430.
steven.zhang added a comment.

I have to reopen this revision as the custom way still cannot meet PowerPC's requirement, because it will try to expand it first. From the implementation, it seems that we are trying our best to expand the node without checking the legalization of the expanded node, which results in several runtime call eventually. And sometimes, the expand never fall into libcall for some opcode ... See

  case ISD::SINT_TO_FP:
  case ISD::STRICT_SINT_TO_FP:
    Tmp1 = ExpandLegalINT_TO_FP(Node, Tmp2);
    Results.push_back(Tmp1);
    if (Node->isStrictFPOpcode())
      Results.push_back(Tmp2);
    break;

What we are trying to do is to call the runtime call for such operations.

Address Reviewer's comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91331/new/

https://reviews.llvm.org/D91331

Files:
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -998,8 +998,16 @@
       Action = TLI.getOperationAction(Node->getOpcode(), MVT::Other);
     break;
   case ISD::FP_TO_FP16:
+  case ISD::FP_ROUND:
+  case ISD::FP_EXTEND:
   case ISD::SINT_TO_FP:
   case ISD::UINT_TO_FP:
+  case ISD::FP_TO_UINT:
+  case ISD::FP_TO_SINT:
+    Action = TLI.getCastOperationAction(Node->getOpcode(),
+                                        Node->getOperand(0).getValueType(),
+                                        Node->getValueType(0));
+    break;
   case ISD::EXTRACT_VECTOR_ELT:
   case ISD::LROUND:
   case ISD::LLROUND:
Index: llvm/include/llvm/CodeGen/TargetLowering.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetLowering.h
+++ llvm/include/llvm/CodeGen/TargetLowering.h
@@ -1042,6 +1042,25 @@
     return OpActions[(unsigned)VT.getSimpleVT().SimpleTy][Op];
   }
 
+  /// Some cast operations may be natively supported by the target but only for
+  /// specific \p SrcVT. This method allows for checking both the \p SrcVT and
+  /// \p DestVT for a given operation.
+  LegalizeAction getCastOperationAction(unsigned Op, EVT SrcVT,
+                                        EVT DestVT) const {
+    auto Action = getOperationAction(Op, DestVT);
+    if (Action != Legal && Action != Custom)
+      return Action;
+    return isSupportedCastOperation(Op, SrcVT, DestVT) ? Action : LibCall;
+  }
+
+  /// Custom method defined by each target to indicate if an cast operation
+  /// which cast from \p SrcVT to \p DestVT is supported natively by the
+  /// target. If not, the operation is illegal.
+  virtual bool isSupportedCastOperation(unsigned Op, EVT SrcVT,
+                                        EVT DestVT) const {
+    return true;
+  }
+
   /// Custom method defined by each target to indicate if an operation which
   /// may require a scale is supported natively by the target.
   /// If not, the operation is illegal.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91331.305430.patch
Type: text/x-patch
Size: 2156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201116/5a3c5dad/attachment.bin>


More information about the llvm-commits mailing list