[llvm] r369981 - [X86] Delay combineIncDecVector until after op legalization.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 26 15:17:54 PDT 2019


Author: ctopper
Date: Mon Aug 26 15:17:54 2019
New Revision: 369981

URL: http://llvm.org/viewvc/llvm-project?rev=369981&view=rev
Log:
[X86] Delay combineIncDecVector until after op legalization.

Probably better to keep add over sub in early DAG combines.

It might make sense to push this to lowering or delay it all
the way to isel. But this was the simplest change.

Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/test/CodeGen/X86/i128-add.ll

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=369981&r1=369980&r2=369981&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Mon Aug 26 15:17:54 2019
@@ -43712,10 +43712,18 @@ static SDValue combineLoopSADPattern(SDN
 /// The all-ones vector constant can be materialized using a pcmpeq instruction
 /// that is commonly recognized as an idiom (has no register dependency), so
 /// that's better/smaller than loading a splat 1 constant.
-static SDValue combineIncDecVector(SDNode *N, SelectionDAG &DAG) {
+static SDValue combineIncDecVector(SDNode *N, SelectionDAG &DAG,
+                                   TargetLowering::DAGCombinerInfo &DCI) {
   assert((N->getOpcode() == ISD::ADD || N->getOpcode() == ISD::SUB) &&
          "Unexpected opcode for increment/decrement transform");
 
+  // Delay this until legalize ops to avoid interfering with early DAG combines
+  // that may expect canonical adds.
+  // FIXME: We may want to consider moving this to custom lowering or all the
+  // way to isel, but lets start here.
+  if (DCI.isBeforeLegalizeOps())
+    return SDValue();
+
   // Pseudo-legality check: getOnesVector() expects one of these types, so bail
   // out and wait for legalization if we have an unsupported vector length.
   EVT VT = N->getValueType(0);
@@ -43962,6 +43970,7 @@ static SDValue matchPMADDWD_2(SelectionD
 }
 
 static SDValue combineAdd(SDNode *N, SelectionDAG &DAG,
+                          TargetLowering::DAGCombinerInfo &DCI,
                           const X86Subtarget &Subtarget) {
   const SDNodeFlags Flags = N->getFlags();
   if (Flags.hasVectorReduction()) {
@@ -43992,7 +44001,7 @@ static SDValue combineAdd(SDNode *N, Sel
                             HADDBuilder);
   }
 
-  if (SDValue V = combineIncDecVector(N, DAG))
+  if (SDValue V = combineIncDecVector(N, DAG, DCI))
     return V;
 
   return combineAddOrSubToADCOrSBB(N, DAG);
@@ -44086,6 +44095,7 @@ static SDValue combineSubToSubus(SDNode
 }
 
 static SDValue combineSub(SDNode *N, SelectionDAG &DAG,
+                          TargetLowering::DAGCombinerInfo &DCI,
                           const X86Subtarget &Subtarget) {
   SDValue Op0 = N->getOperand(0);
   SDValue Op1 = N->getOperand(1);
@@ -44122,7 +44132,7 @@ static SDValue combineSub(SDNode *N, Sel
                             HSUBBuilder);
   }
 
-  if (SDValue V = combineIncDecVector(N, DAG))
+  if (SDValue V = combineIncDecVector(N, DAG, DCI))
     return V;
 
   // Try to create PSUBUS if SUB's argument is max/min
@@ -44761,8 +44771,8 @@ SDValue X86TargetLowering::PerformDAGCom
   case ISD::BITCAST:        return combineBitcast(N, DAG, DCI, Subtarget);
   case X86ISD::CMOV:        return combineCMov(N, DAG, DCI, Subtarget);
   case X86ISD::CMP:         return combineCMP(N, DAG);
-  case ISD::ADD:            return combineAdd(N, DAG, Subtarget);
-  case ISD::SUB:            return combineSub(N, DAG, Subtarget);
+  case ISD::ADD:            return combineAdd(N, DAG, DCI, Subtarget);
+  case ISD::SUB:            return combineSub(N, DAG, DCI, Subtarget);
   case X86ISD::ADD:
   case X86ISD::SUB:         return combineX86AddSub(N, DAG, DCI);
   case X86ISD::SBB:         return combineSBB(N, DAG);

Modified: llvm/trunk/test/CodeGen/X86/i128-add.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/i128-add.ll?rev=369981&r1=369980&r2=369981&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/i128-add.ll (original)
+++ llvm/trunk/test/CodeGen/X86/i128-add.ll Mon Aug 26 15:17:54 2019
@@ -57,10 +57,10 @@ define <1 x i128> @add_v1i128(<1 x i128>
 ; X86-NEXT:    adcl {{[0-9]+}}(%esp), %edi
 ; X86-NEXT:    adcl {{[0-9]+}}(%esp), %edx
 ; X86-NEXT:    adcl {{[0-9]+}}(%esp), %ecx
-; X86-NEXT:    subl $-1, %esi
-; X86-NEXT:    sbbl $-1, %edi
-; X86-NEXT:    sbbl $-1, %edx
-; X86-NEXT:    sbbl $-1, %ecx
+; X86-NEXT:    addl $1, %esi
+; X86-NEXT:    adcl $0, %edi
+; X86-NEXT:    adcl $0, %edx
+; X86-NEXT:    adcl $0, %ecx
 ; X86-NEXT:    movl %esi, (%eax)
 ; X86-NEXT:    movl %edi, 4(%eax)
 ; X86-NEXT:    movl %edx, 8(%eax)




More information about the llvm-commits mailing list