-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[VectorUtils] Allow just poison in mask*All(Ones|Zero)OrUndef #168388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Use PatternMatch to improve code.
|
@llvm/pr-subscribers-llvm-analysis Author: Ramkumar Ramachandra (artagnon) ChangesUse PatternMatch to improve code. Full diff: https://github.com/llvm/llvm-project/pull/168388.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp
index 530fa9518f40e..b011dcafa1aec 100644
--- a/llvm/lib/Analysis/VectorUtils.cpp
+++ b/llvm/lib/Analysis/VectorUtils.cpp
@@ -1263,7 +1263,7 @@ bool llvm::maskIsAllZeroOrUndef(Value *Mask) {
auto *ConstMask = dyn_cast<Constant>(Mask);
if (!ConstMask)
return false;
- if (ConstMask->isNullValue() || isa<UndefValue>(ConstMask))
+ if (match(ConstMask, m_CombineOr(m_Zero(), m_Undef())))
return true;
if (isa<ScalableVectorType>(ConstMask->getType()))
return false;
@@ -1272,7 +1272,7 @@ bool llvm::maskIsAllZeroOrUndef(Value *Mask) {
E = cast<FixedVectorType>(ConstMask->getType())->getNumElements();
I != E; ++I) {
if (auto *MaskElt = ConstMask->getAggregateElement(I))
- if (MaskElt->isNullValue() || isa<UndefValue>(MaskElt))
+ if (match(MaskElt, m_CombineOr(m_Zero(), m_Undef())))
continue;
return false;
}
@@ -1289,7 +1289,7 @@ bool llvm::maskIsAllOneOrUndef(Value *Mask) {
auto *ConstMask = dyn_cast<Constant>(Mask);
if (!ConstMask)
return false;
- if (ConstMask->isAllOnesValue() || isa<UndefValue>(ConstMask))
+ if (match(ConstMask, m_CombineOr(m_AllOnes(), m_Undef())))
return true;
if (isa<ScalableVectorType>(ConstMask->getType()))
return false;
@@ -1298,7 +1298,7 @@ bool llvm::maskIsAllOneOrUndef(Value *Mask) {
E = cast<FixedVectorType>(ConstMask->getType())->getNumElements();
I != E; ++I) {
if (auto *MaskElt = ConstMask->getAggregateElement(I))
- if (MaskElt->isAllOnesValue() || isa<UndefValue>(MaskElt))
+ if (match(MaskElt, m_CombineOr(m_AllOnes(), m_Undef())))
continue;
return false;
}
@@ -1315,7 +1315,7 @@ bool llvm::maskContainsAllOneOrUndef(Value *Mask) {
auto *ConstMask = dyn_cast<Constant>(Mask);
if (!ConstMask)
return false;
- if (ConstMask->isAllOnesValue() || isa<UndefValue>(ConstMask))
+ if (match(ConstMask, m_CombineOr(m_AllOnes(), m_Undef())))
return true;
if (isa<ScalableVectorType>(ConstMask->getType()))
return false;
@@ -1324,7 +1324,7 @@ bool llvm::maskContainsAllOneOrUndef(Value *Mask) {
E = cast<FixedVectorType>(ConstMask->getType())->getNumElements();
I != E; ++I) {
if (auto *MaskElt = ConstMask->getAggregateElement(I))
- if (MaskElt->isAllOnesValue() || isa<UndefValue>(MaskElt))
+ if (match(MaskElt, m_CombineOr(m_AllOnes(), m_Undef())))
return true;
}
return false;
|
| if (!ConstMask) | ||
| return false; | ||
| if (ConstMask->isAllOnesValue() || isa<UndefValue>(ConstMask)) | ||
| if (match(ConstMask, m_CombineOr(m_AllOnes(), m_Undef()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isAllOnesValue can see through ConstantFP - can m_AllOnes()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! It can't; there are other issues with this patch including the fact that we're matching undef instead of just poison -- abandoning.
fhahn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there were no test changes with the patch. Are we missing some test coverage?
We sure are, but I think a more comprehensive patch would strip the touched functions, update callers to directly use PM, and s/undef/poison/ in tests. Not sure if it's really worth the effort for the moment. |
Use PatternMatch to improve code.