Skip to content

Commit 8347ca7

Browse files
committed
[PatternMatch] Don't require DataLayout for m_VScale()
The m_VScale() matcher is unusual in that it requires a DataLayout. It is currently used to determine the size of the GEP type. However, I believe it is sufficient to check for the canonical <vscale x 1 x i8> form here -- I don't think there's a need to recognize exotic variations like <vscale x 1 x i4> as a vscale constant representation as well. Differential Revision: https://reviews.llvm.org/D144566
1 parent 34abc5b commit 8347ca7

File tree

5 files changed

+15
-24
lines changed

5 files changed

+15
-24
lines changed

llvm/include/llvm/IR/PatternMatch.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,21 +2476,19 @@ inline InsertValue_match<Ind, Val_t, Elt_t> m_InsertValue(const Val_t &Val,
24762476
/// `ptrtoint(gep <vscale x 1 x i8>, <vscale x 1 x i8>* null, i32 1>`
24772477
/// under the right conditions determined by DataLayout.
24782478
struct VScaleVal_match {
2479-
const DataLayout &DL;
2480-
VScaleVal_match(const DataLayout &DL) : DL(DL) {}
2481-
24822479
template <typename ITy> bool match(ITy *V) {
24832480
if (m_Intrinsic<Intrinsic::vscale>().match(V))
24842481
return true;
24852482

24862483
Value *Ptr;
24872484
if (m_PtrToInt(m_Value(Ptr)).match(V)) {
24882485
if (auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
2489-
auto *DerefTy = GEP->getSourceElementType();
2490-
if (GEP->getNumIndices() == 1 && isa<ScalableVectorType>(DerefTy) &&
2486+
auto *DerefTy =
2487+
dyn_cast<ScalableVectorType>(GEP->getSourceElementType());
2488+
if (GEP->getNumIndices() == 1 && DerefTy &&
2489+
DerefTy->getElementType()->isIntegerTy(8) &&
24912490
m_Zero().match(GEP->getPointerOperand()) &&
2492-
m_SpecificInt(1).match(GEP->idx_begin()->get()) &&
2493-
DL.getTypeAllocSizeInBits(DerefTy).getKnownMinValue() == 8)
2491+
m_SpecificInt(1).match(GEP->idx_begin()->get()))
24942492
return true;
24952493
}
24962494
}
@@ -2499,8 +2497,8 @@ struct VScaleVal_match {
24992497
}
25002498
};
25012499

2502-
inline VScaleVal_match m_VScale(const DataLayout &DL) {
2503-
return VScaleVal_match(DL);
2500+
inline VScaleVal_match m_VScale() {
2501+
return VScaleVal_match();
25042502
}
25052503

25062504
template <typename LHS, typename RHS, unsigned Opcode, bool Commutable = false>

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {
16071607
TLI.getPointerTy(DAG.getDataLayout(), AS));
16081608
}
16091609

1610-
if (match(C, m_VScale(DAG.getDataLayout())))
1610+
if (match(C, m_VScale()))
16111611
return DAG.getVScale(getCurSDLoc(), VT, APInt(VT.getSizeInBits(), 1));
16121612

16131613
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
@@ -5868,7 +5868,6 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
58685868
visitTargetIntrinsic(I, Intrinsic);
58695869
return;
58705870
case Intrinsic::vscale: {
5871-
match(&I, m_VScale(DAG.getDataLayout()));
58725871
EVT VT = TLI.getValueType(DAG.getDataLayout(), I.getType());
58735872
setValue(&I, DAG.getVScale(sdl, VT, APInt(VT.getSizeInBits(), 1)));
58745873
return;

llvm/lib/IR/IntrinsicInst.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,17 +554,11 @@ bool VPIntrinsic::canIgnoreVectorLengthParam() const {
554554

555555
// Check whether "W == vscale * EC.getKnownMinValue()"
556556
if (EC.isScalable()) {
557-
// Undig the DL
558-
const auto *ParMod = this->getModule();
559-
if (!ParMod)
560-
return false;
561-
const auto &DL = ParMod->getDataLayout();
562-
563557
// Compare vscale patterns
564558
uint64_t VScaleFactor;
565-
if (match(VLParam, m_c_Mul(m_ConstantInt(VScaleFactor), m_VScale(DL))))
559+
if (match(VLParam, m_c_Mul(m_ConstantInt(VScaleFactor), m_VScale())))
566560
return VScaleFactor >= EC.getKnownMinValue();
567-
return (EC.getKnownMinValue() == 1) && match(VLParam, m_VScale(DL));
561+
return (EC.getKnownMinValue() == 1) && match(VLParam, m_VScale());
568562
}
569563

570564
// standard SIMD operation

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
10121012
}
10131013
}
10141014

1015-
if (match(Src, m_VScale(DL))) {
1015+
if (match(Src, m_VScale())) {
10161016
if (Trunc.getFunction() &&
10171017
Trunc.getFunction()->hasFnAttribute(Attribute::VScaleRange)) {
10181018
Attribute Attr =
@@ -1361,7 +1361,7 @@ Instruction *InstCombinerImpl::visitZExt(ZExtInst &Zext) {
13611361
return BinaryOperator::CreateAnd(X, ZextC);
13621362
}
13631363

1364-
if (match(Src, m_VScale(DL))) {
1364+
if (match(Src, m_VScale())) {
13651365
if (Zext.getFunction() &&
13661366
Zext.getFunction()->hasFnAttribute(Attribute::VScaleRange)) {
13671367
Attribute Attr =
@@ -1632,7 +1632,7 @@ Instruction *InstCombinerImpl::visitSExt(SExtInst &Sext) {
16321632
}
16331633
}
16341634

1635-
if (match(Src, m_VScale(DL))) {
1635+
if (match(Src, m_VScale())) {
16361636
if (Sext.getFunction() &&
16371637
Sext.getFunction()->hasFnAttribute(Attribute::VScaleRange)) {
16381638
Attribute Attr =

llvm/unittests/IR/PatternMatch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ TEST_F(PatternMatchTest, VScale) {
17601760
Value *NullPtrVec = Constant::getNullValue(VecPtrTy);
17611761
Value *GEP = IRB.CreateGEP(VecTy, NullPtrVec, IRB.getInt64(1));
17621762
Value *PtrToInt = IRB.CreatePtrToInt(GEP, DL.getIntPtrType(GEP->getType()));
1763-
EXPECT_TRUE(match(PtrToInt, m_VScale(DL)));
1763+
EXPECT_TRUE(match(PtrToInt, m_VScale()));
17641764

17651765
// This used to cause assertion failures when attempting to match m_VScale.
17661766
// With opaque pointers the bitcast is no longer present.
@@ -1770,7 +1770,7 @@ TEST_F(PatternMatchTest, VScale) {
17701770
Value *GEP2 = IRB.CreateGEP(VecTy, BitCast, IRB.getInt64(1));
17711771
Value *PtrToInt2 =
17721772
IRB.CreatePtrToInt(GEP2, DL.getIntPtrType(GEP2->getType()));
1773-
EXPECT_TRUE(match(PtrToInt2, m_VScale(DL)));
1773+
EXPECT_TRUE(match(PtrToInt2, m_VScale()));
17741774
}
17751775

17761776
TEST_F(PatternMatchTest, NotForbidUndef) {

0 commit comments

Comments
 (0)