Skip to content

Commit

Permalink
[X86] detectAVGPattern - use matchUnaryPredicate helper. NFC.
Browse files Browse the repository at this point in the history
Use the ISD::matchUnaryPredicate helper to check for inrange constants.
  • Loading branch information
RKSimon committed May 3, 2020
1 parent 7cf0f85 commit 4d2b0eb
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Expand Up @@ -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.
Expand Down

0 comments on commit 4d2b0eb

Please sign in to comment.