[X86] detectAVGPattern - use matchUnaryPredicate helper. NFC.

Use the ISD::matchUnaryPredicate helper to check for inrange constants.
This commit is contained in:
Simon Pilgrim 2020-05-03 09:54:54 +01:00
parent 7cf0f8568c
commit 4d2b0ebd17
1 changed files with 3 additions and 12 deletions

View File

@ -42492,18 +42492,9 @@ static SDValue detectAVGPattern(SDValue In, EVT VT, SelectionDAG &DAG,
// A lambda checking the given SDValue is a constant vector and each element
// is in the range [Min, Max].
auto IsConstVectorInRange = [](SDValue V, unsigned Min, unsigned Max) {
BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(V);
if (!BV || !BV->isConstant())
return false;
for (SDValue Op : V->ops()) {
ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op);
if (!C)
return false;
const APInt &Val = C->getAPIntValue();
if (Val.ult(Min) || Val.ugt(Max))
return false;
}
return true;
return ISD::matchUnaryPredicate(V, [Min, Max](ConstantSDNode *C) {
return !(C->getAPIntValue().ult(Min) || C->getAPIntValue().ugt(Max));
});
};
// Check if each element of the vector is right-shifted by one.