[llvm] 1bf1e6e - [LLVM][PatternMatch] Simplify m_VScale to only match against llvm.vscale(). (#142773)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 5 04:18:31 PDT 2025
Author: Paul Walker
Date: 2025-06-05T12:18:27+01:00
New Revision: 1bf1e6e40e79ad5dee42081bb153154f6e168d90
URL: https://github.com/llvm/llvm-project/commit/1bf1e6e40e79ad5dee42081bb153154f6e168d90
DIFF: https://github.com/llvm/llvm-project/commit/1bf1e6e40e79ad5dee42081bb153154f6e168d90.diff
LOG: [LLVM][PatternMatch] Simplify m_VScale to only match against llvm.vscale(). (#142773)
The getelementptr based representation of vscale only existed to allow a
constant representation of vscale, which has long since been removed.
Added:
Modified:
llvm/include/llvm/IR/PatternMatch.h
llvm/unittests/IR/PatternMatch.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 6242a686e7bc0..2eaa7d0faabc1 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -3046,35 +3046,8 @@ inline InsertValue_match<Ind, Val_t, Elt_t> m_InsertValue(const Val_t &Val,
return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
}
-/// Matches patterns for `vscale`. This can either be a call to `llvm.vscale` or
-/// the constant expression
-/// `ptrtoint(gep <vscale x 1 x i8>, <vscale x 1 x i8>* null, i32 1>`
-/// under the right conditions determined by DataLayout.
-struct VScaleVal_match {
- template <typename ITy> bool match(ITy *V) const {
- if (m_Intrinsic<Intrinsic::vscale>().match(V))
- return true;
-
- Value *Ptr;
- if (m_PtrToInt(m_Value(Ptr)).match(V)) {
- if (auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
- auto *DerefTy =
- dyn_cast<ScalableVectorType>(GEP->getSourceElementType());
- if (GEP->getNumIndices() == 1 && DerefTy &&
- DerefTy->getElementType()->isIntegerTy(8) &&
- m_Zero().match(GEP->getPointerOperand()) &&
- m_SpecificInt(1).match(GEP->idx_begin()->get()))
- return true;
- }
- }
-
- return false;
- }
-};
-
-inline VScaleVal_match m_VScale() {
- return VScaleVal_match();
-}
+/// Matches a call to `llvm.vscale()`.
+inline IntrinsicID_match m_VScale() { return m_Intrinsic<Intrinsic::vscale>(); }
template <typename Opnd0, typename Opnd1>
inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty
diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp
index 7b3a4ce365453..bb7cc0802b1df 100644
--- a/llvm/unittests/IR/PatternMatch.cpp
+++ b/llvm/unittests/IR/PatternMatch.cpp
@@ -2355,25 +2355,6 @@ TEST_F(PatternMatchTest, VectorLogicalSelects) {
EXPECT_FALSE(match(MixedTypeOr, m_LogicalOr(m_Value(), m_Value())));
}
-TEST_F(PatternMatchTest, VScale) {
- DataLayout DL = M->getDataLayout();
-
- Type *VecTy = ScalableVectorType::get(IRB.getInt8Ty(), 1);
- Value *NullPtrVec =
- Constant::getNullValue(PointerType::getUnqual(VecTy->getContext()));
- Value *GEP = IRB.CreateGEP(VecTy, NullPtrVec, IRB.getInt64(1));
- Value *PtrToInt = IRB.CreatePtrToInt(GEP, DL.getIntPtrType(GEP->getType()));
- EXPECT_TRUE(match(PtrToInt, m_VScale()));
-
- Type *VecTy2 = ScalableVectorType::get(IRB.getInt8Ty(), 2);
- Value *NullPtrVec2 =
- Constant::getNullValue(PointerType::getUnqual(VecTy2->getContext()));
- Value *GEP2 = IRB.CreateGEP(VecTy, NullPtrVec2, IRB.getInt64(1));
- Value *PtrToInt2 =
- IRB.CreatePtrToInt(GEP2, DL.getIntPtrType(GEP2->getType()));
- EXPECT_TRUE(match(PtrToInt2, m_VScale()));
-}
-
TEST_F(PatternMatchTest, NotForbidPoison) {
Type *ScalarTy = IRB.getInt8Ty();
Type *VectorTy = FixedVectorType::get(ScalarTy, 3);
More information about the llvm-commits
mailing list