diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -2476,9 +2476,6 @@ /// `ptrtoint(gep , * null, i32 1>` /// under the right conditions determined by DataLayout. struct VScaleVal_match { - const DataLayout &DL; - VScaleVal_match(const DataLayout &DL) : DL(DL) {} - template bool match(ITy *V) { if (m_Intrinsic().match(V)) return true; @@ -2486,11 +2483,12 @@ Value *Ptr; if (m_PtrToInt(m_Value(Ptr)).match(V)) { if (auto *GEP = dyn_cast(Ptr)) { - auto *DerefTy = GEP->getSourceElementType(); - if (GEP->getNumIndices() == 1 && isa(DerefTy) && + auto *DerefTy = + dyn_cast(GEP->getSourceElementType()); + if (GEP->getNumIndices() == 1 && DerefTy && + DerefTy->getElementType()->isIntegerTy(8) && m_Zero().match(GEP->getPointerOperand()) && - m_SpecificInt(1).match(GEP->idx_begin()->get()) && - DL.getTypeAllocSizeInBits(DerefTy).getKnownMinValue() == 8) + m_SpecificInt(1).match(GEP->idx_begin()->get())) return true; } } @@ -2499,8 +2497,8 @@ } }; -inline VScaleVal_match m_VScale(const DataLayout &DL) { - return VScaleVal_match(DL); +inline VScaleVal_match m_VScale() { + return VScaleVal_match(); } template diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1607,7 +1607,7 @@ TLI.getPointerTy(DAG.getDataLayout(), AS)); } - if (match(C, m_VScale(DAG.getDataLayout()))) + if (match(C, m_VScale())) return DAG.getVScale(getCurSDLoc(), VT, APInt(VT.getSizeInBits(), 1)); if (const ConstantFP *CFP = dyn_cast(C)) @@ -5868,7 +5868,6 @@ visitTargetIntrinsic(I, Intrinsic); return; case Intrinsic::vscale: { - match(&I, m_VScale(DAG.getDataLayout())); EVT VT = TLI.getValueType(DAG.getDataLayout(), I.getType()); setValue(&I, DAG.getVScale(sdl, VT, APInt(VT.getSizeInBits(), 1))); return; diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp --- a/llvm/lib/IR/IntrinsicInst.cpp +++ b/llvm/lib/IR/IntrinsicInst.cpp @@ -554,17 +554,11 @@ // Check whether "W == vscale * EC.getKnownMinValue()" if (EC.isScalable()) { - // Undig the DL - const auto *ParMod = this->getModule(); - if (!ParMod) - return false; - const auto &DL = ParMod->getDataLayout(); - // Compare vscale patterns uint64_t VScaleFactor; - if (match(VLParam, m_c_Mul(m_ConstantInt(VScaleFactor), m_VScale(DL)))) + if (match(VLParam, m_c_Mul(m_ConstantInt(VScaleFactor), m_VScale()))) return VScaleFactor >= EC.getKnownMinValue(); - return (EC.getKnownMinValue() == 1) && match(VLParam, m_VScale(DL)); + return (EC.getKnownMinValue() == 1) && match(VLParam, m_VScale()); } // standard SIMD operation diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1012,7 +1012,7 @@ } } - if (match(Src, m_VScale(DL))) { + if (match(Src, m_VScale())) { if (Trunc.getFunction() && Trunc.getFunction()->hasFnAttribute(Attribute::VScaleRange)) { Attribute Attr = @@ -1361,7 +1361,7 @@ return BinaryOperator::CreateAnd(X, ZextC); } - if (match(Src, m_VScale(DL))) { + if (match(Src, m_VScale())) { if (Zext.getFunction() && Zext.getFunction()->hasFnAttribute(Attribute::VScaleRange)) { Attribute Attr = @@ -1632,7 +1632,7 @@ } } - if (match(Src, m_VScale(DL))) { + if (match(Src, m_VScale())) { if (Sext.getFunction() && Sext.getFunction()->hasFnAttribute(Attribute::VScaleRange)) { Attribute Attr = diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp --- a/llvm/unittests/IR/PatternMatch.cpp +++ b/llvm/unittests/IR/PatternMatch.cpp @@ -1760,7 +1760,7 @@ Value *NullPtrVec = Constant::getNullValue(VecPtrTy); Value *GEP = IRB.CreateGEP(VecTy, NullPtrVec, IRB.getInt64(1)); Value *PtrToInt = IRB.CreatePtrToInt(GEP, DL.getIntPtrType(GEP->getType())); - EXPECT_TRUE(match(PtrToInt, m_VScale(DL))); + EXPECT_TRUE(match(PtrToInt, m_VScale())); // This used to cause assertion failures when attempting to match m_VScale. // With opaque pointers the bitcast is no longer present. @@ -1770,7 +1770,7 @@ Value *GEP2 = IRB.CreateGEP(VecTy, BitCast, IRB.getInt64(1)); Value *PtrToInt2 = IRB.CreatePtrToInt(GEP2, DL.getIntPtrType(GEP2->getType())); - EXPECT_TRUE(match(PtrToInt2, m_VScale(DL))); + EXPECT_TRUE(match(PtrToInt2, m_VScale())); } TEST_F(PatternMatchTest, NotForbidUndef) {