[llvm] 4d2b0eb - [X86] detectAVGPattern - use matchUnaryPredicate helper. NFC.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sun May 3 03:29:31 PDT 2020
Author: Simon Pilgrim
Date: 2020-05-03T11:26:51+01:00
New Revision: 4d2b0ebd170d228a17a1096b14be55e22383ceb7
URL: https://github.com/llvm/llvm-project/commit/4d2b0ebd170d228a17a1096b14be55e22383ceb7
DIFF: https://github.com/llvm/llvm-project/commit/4d2b0ebd170d228a17a1096b14be55e22383ceb7.diff
LOG: [X86] detectAVGPattern - use matchUnaryPredicate helper. NFC.
Use the ISD::matchUnaryPredicate helper to check for inrange constants.
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 6e52f4cd6d47..ed1fd966a22b 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<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.
More information about the llvm-commits
mailing list