Only perform DAG combine on FMAs of legal types.
[oota-llvm.git] / lib / Target / X86 / X86ISelLowering.cpp
index 9e1da147c9636a46a75402bf86a2d4d7ca2feccc..b2b30fe387c3675cccc2a0fffddc4aa56d6f1bec 100644 (file)
@@ -10045,10 +10045,6 @@ X86TargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const
   case Intrinsic::x86_fma_vfmaddsub_pd_256:
   case Intrinsic::x86_fma_vfmsubadd_ps_256:
   case Intrinsic::x86_fma_vfmsubadd_pd_256: {
-    // Only lower intrinsics if FMA is enabled. FMA4 still uses patterns.
-    if (!Subtarget->hasFMA())
-      return SDValue();
-
     unsigned Opc;
     switch (IntNo) {
     default: llvm_unreachable("Impossible intrinsic");  // Can't reach here.
@@ -14128,7 +14124,7 @@ static SDValue checkFlaggedOrCombine(SDValue Or, X86::CondCode &CC,
       Opnds.push_back(I->getOperand(0));
       Opnds.push_back(I->getOperand(1));
       // Re-evaluate the number of nodes to be traversed.
-      e = Opnds.size();
+      e += 2; // 2 more nodes (LHS and RHS) are pushed.
       continue;
     }
 
@@ -15605,6 +15601,10 @@ static SDValue PerformFMACombine(SDNode *N, SelectionDAG &DAG,
   DebugLoc dl = N->getDebugLoc();
   EVT VT = N->getValueType(0);
 
+  // Let legalize expand this if it isn't a legal type yet.
+  if (!DAG.getTargetLoweringInfo().isTypeLegal(VT))
+    return SDValue();
+
   EVT ScalarVT = VT.getScalarType();
   if ((ScalarVT != MVT::f32 && ScalarVT != MVT::f64) || !Subtarget->hasFMA())
     return SDValue();