[llvm] r357349 - [X86][SSE] detectAVGPattern - begin generalizing ADD matches

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 30 08:31:53 PDT 2019


Author: rksimon
Date: Sat Mar 30 08:31:53 2019
New Revision: 357349

URL: http://llvm.org/viewvc/llvm-project?rev=357349&view=rev
Log:
[X86][SSE] detectAVGPattern - begin generalizing ADD matches

Move the ADD matching into a helper - first NFC stage towards supporting 'ADD like' cases such as in PR41316

Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=357349&r1=357348&r2=357349&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Sat Mar 30 08:31:53 2019
@@ -38203,12 +38203,23 @@ static SDValue detectAVGPattern(SDValue
                             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.




More information about the llvm-commits mailing list