]> granicus.if.org Git - llvm/commitdiff
[SelectionDAG] Add fpto[us]i(undef) --> undef constant fold
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 4 Jun 2019 10:04:55 +0000 (10:04 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 4 Jun 2019 10:04:55 +0000 (10:04 +0000)
Follow up to D62807.

Differential Revision: https://reviews.llvm.org/D62811

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362483 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
test/CodeGen/X86/vec_fp_to_int-widen.ll
test/CodeGen/X86/vec_fp_to_int.ll

index 8eeb4a70a53be7a520c02c93d57e439660eadb51..8f2e80853e8d1446324e4779b4f7ab535031d34f 100644 (file)
@@ -12770,6 +12770,10 @@ SDValue DAGCombiner::visitFP_TO_SINT(SDNode *N) {
   SDValue N0 = N->getOperand(0);
   EVT VT = N->getValueType(0);
 
+  // fold (fp_to_sint undef) -> undef
+  if (N0.isUndef())
+    return DAG.getUNDEF(VT);
+
   // fold (fp_to_sint c1fp) -> c1
   if (isConstantFPBuildVectorOrConstantFP(N0))
     return DAG.getNode(ISD::FP_TO_SINT, SDLoc(N), VT, N0);
@@ -12781,6 +12785,10 @@ SDValue DAGCombiner::visitFP_TO_UINT(SDNode *N) {
   SDValue N0 = N->getOperand(0);
   EVT VT = N->getValueType(0);
 
+  // fold (fp_to_uint undef) -> undef
+  if (N0.isUndef())
+    return DAG.getUNDEF(VT);
+
   // fold (fp_to_uint c1fp) -> c1
   if (isConstantFPBuildVectorOrConstantFP(N0))
     return DAG.getNode(ISD::FP_TO_UINT, SDLoc(N), VT, N0);
index 1dc9d7460f859187adc6f39fb73540feb3181a12..e30b702ac15632591e9114fa88efb5d5d5089f06 100644 (file)
@@ -4440,6 +4440,11 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     if (Operand.isUndef())
       return getUNDEF(VT);
     break;
+  case ISD::FP_TO_SINT:
+  case ISD::FP_TO_UINT:
+    if (Operand.isUndef())
+      return getUNDEF(VT);
+    break;
   case ISD::SINT_TO_FP:
   case ISD::UINT_TO_FP:
     // [us]itofp(undef) = 0, because the result value is bounded.
index 3c04c89cf51429a8dfb60579553cb8aab6fa661c..94b860cff19345b405793578f6426b1b74b0b3f7 100644 (file)
@@ -106,9 +106,7 @@ define <2 x i32> @fptosi_2f64_to_2i32(<2 x double> %a) {
 define <4 x i32> @fptosi_4f64_to_2i32(<2 x double> %a) {
 ; SSE-LABEL: fptosi_4f64_to_2i32:
 ; SSE:       # %bb.0:
-; SSE-NEXT:    cvttpd2dq %xmm0, %xmm1
 ; SSE-NEXT:    cvttpd2dq %xmm0, %xmm0
-; SSE-NEXT:    unpcklpd {{.*#+}} xmm0 = xmm0[0],xmm1[0]
 ; SSE-NEXT:    retq
 ;
 ; AVX-LABEL: fptosi_4f64_to_2i32:
index f7047a68f148abe4ef3f3573066ca648a2c39c65..e3c9a5491c1cde2ffbb4250544832ceeabd6894c 100644 (file)
@@ -108,9 +108,7 @@ define <2 x i32> @fptosi_2f64_to_2i32(<2 x double> %a) {
 define <4 x i32> @fptosi_4f64_to_2i32(<2 x double> %a) {
 ; SSE-LABEL: fptosi_4f64_to_2i32:
 ; SSE:       # %bb.0:
-; SSE-NEXT:    cvttpd2dq %xmm0, %xmm1
 ; SSE-NEXT:    cvttpd2dq %xmm0, %xmm0
-; SSE-NEXT:    unpcklpd {{.*#+}} xmm0 = xmm0[0],xmm1[0]
 ; SSE-NEXT:    retq
 ;
 ; AVX-LABEL: fptosi_4f64_to_2i32: