Skip to content

Commit 1bf1e6e

Browse files
[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.
1 parent b6521e8 commit 1bf1e6e

File tree

2 files changed

+2
-48
lines changed

2 files changed

+2
-48
lines changed

llvm/include/llvm/IR/PatternMatch.h

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3046,35 +3046,8 @@ inline InsertValue_match<Ind, Val_t, Elt_t> m_InsertValue(const Val_t &Val,
30463046
return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
30473047
}
30483048

3049-
/// Matches patterns for `vscale`. This can either be a call to `llvm.vscale` or
3050-
/// the constant expression
3051-
/// `ptrtoint(gep <vscale x 1 x i8>, <vscale x 1 x i8>* null, i32 1>`
3052-
/// under the right conditions determined by DataLayout.
3053-
struct VScaleVal_match {
3054-
template <typename ITy> bool match(ITy *V) const {
3055-
if (m_Intrinsic<Intrinsic::vscale>().match(V))
3056-
return true;
3057-
3058-
Value *Ptr;
3059-
if (m_PtrToInt(m_Value(Ptr)).match(V)) {
3060-
if (auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
3061-
auto *DerefTy =
3062-
dyn_cast<ScalableVectorType>(GEP->getSourceElementType());
3063-
if (GEP->getNumIndices() == 1 && DerefTy &&
3064-
DerefTy->getElementType()->isIntegerTy(8) &&
3065-
m_Zero().match(GEP->getPointerOperand()) &&
3066-
m_SpecificInt(1).match(GEP->idx_begin()->get()))
3067-
return true;
3068-
}
3069-
}
3070-
3071-
return false;
3072-
}
3073-
};
3074-
3075-
inline VScaleVal_match m_VScale() {
3076-
return VScaleVal_match();
3077-
}
3049+
/// Matches a call to `llvm.vscale()`.
3050+
inline IntrinsicID_match m_VScale() { return m_Intrinsic<Intrinsic::vscale>(); }
30783051

30793052
template <typename Opnd0, typename Opnd1>
30803053
inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty

llvm/unittests/IR/PatternMatch.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,25 +2355,6 @@ TEST_F(PatternMatchTest, VectorLogicalSelects) {
23552355
EXPECT_FALSE(match(MixedTypeOr, m_LogicalOr(m_Value(), m_Value())));
23562356
}
23572357

2358-
TEST_F(PatternMatchTest, VScale) {
2359-
DataLayout DL = M->getDataLayout();
2360-
2361-
Type *VecTy = ScalableVectorType::get(IRB.getInt8Ty(), 1);
2362-
Value *NullPtrVec =
2363-
Constant::getNullValue(PointerType::getUnqual(VecTy->getContext()));
2364-
Value *GEP = IRB.CreateGEP(VecTy, NullPtrVec, IRB.getInt64(1));
2365-
Value *PtrToInt = IRB.CreatePtrToInt(GEP, DL.getIntPtrType(GEP->getType()));
2366-
EXPECT_TRUE(match(PtrToInt, m_VScale()));
2367-
2368-
Type *VecTy2 = ScalableVectorType::get(IRB.getInt8Ty(), 2);
2369-
Value *NullPtrVec2 =
2370-
Constant::getNullValue(PointerType::getUnqual(VecTy2->getContext()));
2371-
Value *GEP2 = IRB.CreateGEP(VecTy, NullPtrVec2, IRB.getInt64(1));
2372-
Value *PtrToInt2 =
2373-
IRB.CreatePtrToInt(GEP2, DL.getIntPtrType(GEP2->getType()));
2374-
EXPECT_TRUE(match(PtrToInt2, m_VScale()));
2375-
}
2376-
23772358
TEST_F(PatternMatchTest, NotForbidPoison) {
23782359
Type *ScalarTy = IRB.getInt8Ty();
23792360
Type *VectorTy = FixedVectorType::get(ScalarTy, 3);

0 commit comments

Comments
 (0)