OSDN Git Service

Only generate addcarry node when it is legal.
authorAmaury Sechet <deadalnix@gmail.com>
Thu, 1 Jun 2017 12:03:16 +0000 (12:03 +0000)
committerAmaury Sechet <deadalnix@gmail.com>
Thu, 1 Jun 2017 12:03:16 +0000 (12:03 +0000)
Summary:
This is a problem uncovered by stage2 testing. ADDCARRY end up being generated on target that do not support it.

The patch that introduced the problem has other patches layed on top of it, so we want to fix the issue rather than revert it to avoid creating a lor of churn.

A regression test will be added shortly, but this is committed as this in order to get the build back to green promptly.

Subscribers: llvm-commits

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

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

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

index 755d162..d6aec69 100644 (file)
@@ -2058,10 +2058,11 @@ SDValue DAGCombiner::visitADDLike(SDValue N0, SDValue N1, SDNode *LocReference)
                        N0, N1.getOperand(0), N1.getOperand(2));
 
   // (add X, Carry) -> (addcarry X, 0, Carry)
-  if (SDValue Carry = getAsCarry(TLI, N1))
-    return DAG.getNode(ISD::ADDCARRY, DL,
-                       DAG.getVTList(VT, Carry.getValueType()), N0,
-                       DAG.getConstant(0, DL, VT), Carry);
+  if (TLI.isOperationLegalOrCustom(ISD::ADDCARRY, VT))
+    if (SDValue Carry = getAsCarry(TLI, N1))
+      return DAG.getNode(ISD::ADDCARRY, DL,
+                         DAG.getVTList(VT, Carry.getValueType()), N0,
+                         DAG.getConstant(0, DL, VT), Carry);
 
   return SDValue();
 }
@@ -2136,6 +2137,8 @@ SDValue DAGCombiner::visitUADDO(SDNode *N) {
 }
 
 SDValue DAGCombiner::visitUADDOLike(SDValue N0, SDValue N1, SDNode *N) {
+  auto VT = N0.getValueType();
+
   // (uaddo X, (addcarry Y, 0, Carry)) -> (addcarry X, Y, Carry)
   // If Y + 1 cannot overflow.
   if (N1.getOpcode() == ISD::ADDCARRY && isNullConstant(N1.getOperand(1))) {
@@ -2147,9 +2150,10 @@ SDValue DAGCombiner::visitUADDOLike(SDValue N0, SDValue N1, SDNode *N) {
   }
 
   // (uaddo X, Carry) -> (addcarry X, 0, Carry)
-  if (SDValue Carry = getAsCarry(TLI, N1))
-    return DAG.getNode(ISD::ADDCARRY, SDLoc(N), N->getVTList(), N0,
-                       DAG.getConstant(0, SDLoc(N), N0.getValueType()), Carry);
+  if (TLI.isOperationLegalOrCustom(ISD::ADDCARRY, VT))
+    if (SDValue Carry = getAsCarry(TLI, N1))
+      return DAG.getNode(ISD::ADDCARRY, SDLoc(N), N->getVTList(), N0,
+                         DAG.getConstant(0, SDLoc(N), VT), Carry);
 
   return SDValue();
 }