From 4d2b0ebd170d228a17a1096b14be55e22383ceb7 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Sun, 3 May 2020 09:54:54 +0100 Subject: [PATCH] [X86] detectAVGPattern - use matchUnaryPredicate helper. NFC. Use the ISD::matchUnaryPredicate helper to check for inrange constants. --- llvm/lib/Target/X86/X86ISelLowering.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 6e52f4cd6d47d..ed1fd966a22b5 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -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(V); - if (!BV || !BV->isConstant()) - return false; - for (SDValue Op : V->ops()) { - ConstantSDNode *C = dyn_cast(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.