]> granicus.if.org Git - llvm/commitdiff
[X86][SSE] detectAVGPattern - begin generalizing ADD matches
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Sat, 30 Mar 2019 15:31:53 +0000 (15:31 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Sat, 30 Mar 2019 15:31:53 +0000 (15:31 +0000)
Move the ADD matching into a helper - first NFC stage towards supporting 'ADD like' cases such as in PR41316

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

lib/Target/X86/X86ISelLowering.cpp

index 6f9caf1d0bbd97a76fa90b6ca71a88c956445f9d..6c62e661b5a74080eff2c189da752390b2e4b3e3 100644 (file)
@@ -38203,12 +38203,23 @@ static SDValue detectAVGPattern(SDValue In, EVT VT, SelectionDAG &DAG,
                             AVGBuilder);
   }
 
-  if (Operands[0].getOpcode() == ISD::ADD)
+  // Matches 'add like' patterns.
+  // TODO: Extend this to include or/zext cases.
+  auto FindAddLike = [&](SDValue V, SDValue &Op0, SDValue &Op1) {
+    if (ISD::ADD != V.getOpcode())
+      return false;
+    Op0 = V.getOperand(0);
+    Op1 = V.getOperand(1);
+    return true;
+  };
+
+  SDValue Op0, Op1;
+  if (FindAddLike(Operands[0], Op0, Op1))
     std::swap(Operands[0], Operands[1]);
-  else if (Operands[1].getOpcode() != ISD::ADD)
+  else if (!FindAddLike(Operands[1], Op0, Op1))
     return SDValue();
-  Operands[2] = Operands[1].getOperand(0);
-  Operands[1] = Operands[1].getOperand(1);
+  Operands[2] = Op0;
+  Operands[1] = Op1;
 
   // Now we have three operands of two additions. Check that one of them is a
   // constant vector with ones, and the other two are promoted from i8/i16.