Skip to content

Commit 3293455

Browse files
committed
[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 llvm-svn: 357349
1 parent 7dd1c36 commit 3293455

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38203,12 +38203,23 @@ static SDValue detectAVGPattern(SDValue In, EVT VT, SelectionDAG &DAG,
3820338203
AVGBuilder);
3820438204
}
3820538205

38206-
if (Operands[0].getOpcode() == ISD::ADD)
38206+
// Matches 'add like' patterns.
38207+
// TODO: Extend this to include or/zext cases.
38208+
auto FindAddLike = [&](SDValue V, SDValue &Op0, SDValue &Op1) {
38209+
if (ISD::ADD != V.getOpcode())
38210+
return false;
38211+
Op0 = V.getOperand(0);
38212+
Op1 = V.getOperand(1);
38213+
return true;
38214+
};
38215+
38216+
SDValue Op0, Op1;
38217+
if (FindAddLike(Operands[0], Op0, Op1))
3820738218
std::swap(Operands[0], Operands[1]);
38208-
else if (Operands[1].getOpcode() != ISD::ADD)
38219+
else if (!FindAddLike(Operands[1], Op0, Op1))
3820938220
return SDValue();
38210-
Operands[2] = Operands[1].getOperand(0);
38211-
Operands[1] = Operands[1].getOperand(1);
38221+
Operands[2] = Op0;
38222+
Operands[1] = Op1;
3821238223

3821338224
// Now we have three operands of two additions. Check that one of them is a
3821438225
// constant vector with ones, and the other two are promoted from i8/i16.

0 commit comments

Comments
 (0)