[PATCH] D31077: Improve DAGTypeLegalizer::PromoteIntRes_TRUNCATE() to handle widening.

Jonas Paulsson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 20 00:54:15 PDT 2017


jonpa updated this revision to Diff 92305.
jonpa added a comment.

Thanks for review.

I changed the name in the test case per Simons suggestion.

I tried also making this even smaller, but found that the problem didn't trigger if I removed the control flow, and my guess is that the DAG optimizations then hide this problem since it's now all just one DAG.

Is this test acceptable, or if not, what is the problem?


https://reviews.llvm.org/D31077

Files:
  lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
  test/CodeGen/SystemZ/vec-trunc-to-i1.ll


Index: test/CodeGen/SystemZ/vec-trunc-to-i1.ll
===================================================================
--- /dev/null
+++ test/CodeGen/SystemZ/vec-trunc-to-i1.ll
@@ -0,0 +1,20 @@
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z13 | FileCheck %s
+;
+; Check that a widening truncate to a vector of i1 elements can be handled.
+
+
+define void @pr32275() {
+; CHECK: .text
+BB:
+  %B15 = sub <4 x i8> undef, zeroinitializer
+  br label %CF34
+
+CF34:                                             ; preds = %CF34, %BB
+  %Tr24 = trunc <4 x i8> %B15 to <4 x i1>
+  %Cmp26 = icmp slt <4 x i1> %Tr24, undef
+  %E28 = extractelement <4 x i1> %Cmp26, i32 3
+  br i1 %E28, label %CF34, label %CF36
+
+CF36:                                             ; preds = %CF34
+  ret void
+}
Index: lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -690,7 +690,7 @@
   case TargetLowering::TypePromoteInteger:
     Res = GetPromotedInteger(InOp);
     break;
-  case TargetLowering::TypeSplitVector:
+  case TargetLowering::TypeSplitVector: {
     EVT InVT = InOp.getValueType();
     assert(InVT.isVector() && "Cannot split scalar types");
     unsigned NumElts = InVT.getVectorNumElements();
@@ -709,6 +709,26 @@
 
     return DAG.getNode(ISD::CONCAT_VECTORS, dl, NVT, EOp1, EOp2);
   }
+  case TargetLowering::TypeWidenVector: {
+    SDValue WideInOp = GetWidenedVector(InOp);
+
+    // Truncate widened InOp.
+    unsigned NumElem = WideInOp.getValueType().getVectorNumElements();
+    EVT TruncVT = EVT::getVectorVT(*DAG.getContext(),
+                                   N->getValueType(0).getScalarType(), NumElem);
+    SDValue WideTrunc = DAG.getNode(ISD::TRUNCATE, dl, TruncVT, WideInOp);
+
+    // Zero extend so that the elements are of same type as those of NVT
+    EVT ExtVT = EVT::getVectorVT(*DAG.getContext(), NVT.getVectorElementType(),
+                                 NumElem);
+    SDValue WideExt = DAG.getNode(ISD::ZERO_EXTEND, dl, ExtVT, WideTrunc);
+
+    // Extract the low NVT subvector.
+    MVT IdxTy = TLI.getVectorIdxTy(DAG.getDataLayout());
+    SDValue ZeroIdx = DAG.getConstant(0, dl, IdxTy);
+    return DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, NVT, WideExt, ZeroIdx);
+  }
+  }
 
   // Truncate to NVT instead of VT
   return DAG.getNode(ISD::TRUNCATE, dl, NVT, Res);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31077.92305.patch
Type: text/x-patch
Size: 2475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170320/62f81f56/attachment.bin>


More information about the llvm-commits mailing list