[llvm] [IR][NFC] Introduce Constant::containsMatchingVectorElement and corresponding matcher (PR #200502)
Sean Clarke via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 08:45:26 PDT 2026
================
@@ -351,11 +351,20 @@ bool Constant::containsConstantExpression() const {
if (isa<ConstantInt>(this) || isa<ConstantFP>(this))
return false;
- if (auto *VTy = dyn_cast<FixedVectorType>(getType())) {
- for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
- if (isa<ConstantExpr>(getAggregateElement(i)))
- return true;
+ return match(this, m_ContainsMatchingVectorElement(m_Isa<ConstantExpr>()));
+}
+
+bool Constant::containsMatchingVectorElement(
+ function_ref<bool(Constant *)> PredFn) const {
+ if (auto *FVTy = dyn_cast<FixedVectorType>(getType())) {
+ unsigned NumElts = FVTy->getNumElements();
+ for (unsigned I = 0; I != NumElts; ++I) {
+ if (Constant *Elem = getAggregateElement(I))
+ if (PredFn(Elem))
+ return true;
+ }
}
+
----------------
xarkenz wrote:
I think it was mostly a byproduct of how the diff is trying to line up the end of containsConstantExpression with the new function. Can remove if desired.
https://github.com/llvm/llvm-project/pull/200502
More information about the llvm-commits
mailing list