[llvm] [IR] Handle Scalable Vectors for 0 (PR #102205)
Rose Silicon via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 6 12:42:56 PDT 2024
https://github.com/RSilicon created https://github.com/llvm/llvm-project/pull/102205
None
>From 8ad8e9550b89d1d97fd4c9886386c15897ac06ca Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Tue, 6 Aug 2024 15:42:15 -0400
Subject: [PATCH] [IR] Handle Scalable Vectors for 0
---
llvm/include/llvm/IR/PatternMatch.h | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 9c70a60bf50c7..e56153169d97c 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -603,8 +603,23 @@ inline cst_pred_ty<is_zero_int> m_ZeroInt() {
struct is_zero {
template <typename ITy> bool match(ITy *V) {
auto *C = dyn_cast<Constant>(V);
- // FIXME: this should be able to do something for scalable vectors
- return C && (C->isNullValue() || cst_pred_ty<is_zero_int>().match(C));
+ if (C) {
+ if (C->isNullValue() || cst_pred_ty<is_zero_int>().match(C)) {
+ return true;
+ }
+ }
+
+ // Handle scalable vectors
+ if (auto *SV = dyn_cast<ScalableVectorType>(V->getType())) {
+ for (unsigned i = 0; i < SV->getNumElements(); ++i) {
+ if (!match(SV->getElementAsConstant(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ return false;
}
};
/// Match any null constant or a vector with all elements equal to 0.
More information about the llvm-commits
mailing list