[llvm] [IR][NFC] Introduce Constant::containsMatchingVectorElement and corresponding matcher m_ContainsMatchingVectorElement (PR #200502)

Sean Clarke via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 5 08:25:07 PDT 2026


================
@@ -351,11 +344,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 {
----------------
xarkenz wrote:

Constant::getAggregateElement can only return a `Constant *`, so I'm not sure this is a good idea.

https://github.com/llvm/llvm-project/pull/200502


More information about the llvm-commits mailing list