[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
Thu Nov 12 03:10:36 PST 2020


steven.zhang created this revision.
steven.zhang added reviewers: craig.topper, RKSimon, spatel, efriedma, ebevhan, PowerPC.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
steven.zhang requested review of this revision.

For operation like `y = fp_to_sint x` , PowerPC has to expand it if the type of 'x' is f128 on Power8, otherwise, it is legal. Current Legalizer only checks the legal action for the result type `y` for fp_to_sint and I find no way to achieve my goal. Also, it sometimes checks the legal action for operand type with other operations.

So, I propose a hook for target to specify if that operation is legal or not for the source type and dest type. Another solution might query both the source type and dest type with getOperationAction(), then, compare them and select the final one. I tried but as we will get too much conflict actions, I give up... Welcome for more comments.


Repository:
  rG LLVM Github Monorepo

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.getOperationAction(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,23 @@
     return OpActions[(unsigned)VT.getSimpleVT().SimpleTy][Op];
   }
 
+  /// Some 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 getOperationAction(unsigned Op, EVT SrcVT, EVT DestVT) const {
+    auto Action = getOperationAction(Op, DestVT);
+    if (Action != Legal && Action != Custom)
+      return Action;
+    return isSupportedOperation(Op, SrcVT, DestVT) ? Action : Expand;
+  }
+
+  /// Custom method defined by each target to indicate if an operation which
+  /// operate on \p SrcVT and produce \p DestVT is supported natively by the
+  /// target. If not, the operation is illegal.
+  virtual bool isSupportedOperation(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.304765.patch
Type: text/x-patch
Size: 2049 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201112/4cc99e8b/attachment.bin>


More information about the llvm-commits mailing list