[PATCH] D70230: [DAGCombine] Don't check the legality of type when combine the SIGN_EXTEND_INREG

qshanz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 14 03:34:59 PST 2019


steven.zhang created this revision.
steven.zhang added reviewers: efriedma, nemanjai, jsji, craig.topper, RKSimon, dmgreen, PowerPC.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
steven.zhang added parent revisions: D70000: [DAGCombine] Initialize the default operation action for SIGN_EXTEND_INREG for vector type as 'expand' instead of 'legal', D69601: [Power9] Implement the vector extend sign instruction pattern match.

This is the DAG node for SIGN_EXTEND_INREG :

  t21: v4i32 = sign_extend_inreg t18, ValueType:ch:v4i16

It has two operands. The first one is the value it want to extend, and the second one is the type to specify how to extend the value. For this example, it means that, it is signed extend the t18(v4i32) from v4i16 to v4i32. That is the semantics of c code:

  vector int foo(vector int m) {
     return m << 16 >> 16;
  }

And it could be any vector type that hardware support the operation, though the type 'v4i16' is NOT legal for the target. When we are trying to combine the srl + sra, what we did now is calling the TLI.isOperationLegal(), which will also check the legality of the type. That doesn't make sense.

Notice that, this patch is dependent on https://reviews.llvm.org/D69601 to expose the PowerPC missing opportunity. And it is also dependent on https://reviews.llvm.org/D70000, as we are relaxing the combine condition, which might hit the assertion for some targets if they are NOT set it as expand by default.


https://reviews.llvm.org/D70230

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/PowerPC/sext-vector-inreg.ll


Index: llvm/test/CodeGen/PowerPC/sext-vector-inreg.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/sext-vector-inreg.ll
+++ llvm/test/CodeGen/PowerPC/sext-vector-inreg.ll
@@ -4,11 +4,8 @@
 define <4 x i32> @test_signext_vector_inreg(<4 x i16> %n) {
 ; CHECK-P9-LABEL: test_signext_vector_inreg:
 ; CHECK-P9:       # %bb.0: # %entry
-; CHECK-P9-NEXT:    vspltisw 3, 8
 ; CHECK-P9-NEXT:    vmrglh 2, 2, 2
-; CHECK-P9-NEXT:    vadduwm 3, 3, 3
-; CHECK-P9-NEXT:    vslw 2, 2, 3
-; CHECK-P9-NEXT:    vsraw 2, 2, 3
+; CHECK-P9-NEXT:    vextsh2w 2, 2
 ; CHECK-P9-NEXT:    blr
 ;
 ; CHECK-P8-LABEL: test_signext_vector_inreg:
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -7567,8 +7567,9 @@
     if (VT.isVector())
       ExtVT = EVT::getVectorVT(*DAG.getContext(),
                                ExtVT, VT.getVectorNumElements());
-    if ((!LegalOperations ||
-         TLI.isOperationLegal(ISD::SIGN_EXTEND_INREG, ExtVT)))
+    if (!LegalOperations ||
+        TLI.getOperationAction(ISD::SIGN_EXTEND_INREG, ExtVT) ==
+        TargetLowering::Legal)
       return DAG.getNode(ISD::SIGN_EXTEND_INREG, SDLoc(N), VT,
                          N0.getOperand(0), DAG.getValueType(ExtVT));
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70230.229258.patch
Type: text/x-patch
Size: 1416 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191114/c626fd00/attachment.bin>


More information about the llvm-commits mailing list