[llvm] [VPlan] Simplify vp.merge true, (or x, y), x -> vp.merge y, true, x (PR #135017)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 11 07:20:50 PDT 2025
- Previous message: [llvm] [VPlan] Simplify vp.merge true, (or x, y), x -> vp.merge y, true, x (PR #135017)
- Next message: [llvm] [VPlan] Simplify vp.merge true, (or x, y), x -> vp.merge y, true, x (PR #135017)
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
================
@@ -439,6 +457,104 @@ m_DerivedIV(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
return VPDerivedIV_match<Op0_t, Op1_t, Op2_t>({Op0, Op1, Op2});
}
+template <typename Opnd_t> struct Argument_match {
+ unsigned OpI;
+ Opnd_t Val;
+
+ Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
+
+ template <typename OpTy> bool match(OpTy *V) const {
+ if (const auto *R = dyn_cast<VPWidenIntrinsicRecipe>(V))
+ return Val.match(R->getOperand(OpI));
+ if (const auto *R = dyn_cast<VPWidenCallRecipe>(V))
+ return Val.match(R->getOperand(OpI));
+ if (const auto *R = dyn_cast<VPReplicateRecipe>(V))
+ if (isa<CallInst>(R->getUnderlyingInstr()))
+ return Val.match(R->getOperand(OpI + 1));
+ return false;
+ }
+};
+
+/// Match an argument.
+template <unsigned OpI, typename Opnd_t>
+inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
+ return Argument_match<Opnd_t>(OpI, Op);
+}
+
+/// Intrinsic matchers.
+struct IntrinsicID_match {
+ unsigned ID;
+
+ IntrinsicID_match(Intrinsic::ID IntrID) : ID(IntrID) {}
+
+ template <typename OpTy> bool match(OpTy *V) const {
+ if (const auto *R = dyn_cast<VPWidenIntrinsicRecipe>(V))
+ return R->getVectorIntrinsicID() == ID;
+ if (const auto *R = dyn_cast<VPWidenCallRecipe>(V))
+ return R->getCalledScalarFunction()->getIntrinsicID() == ID;
----------------
lukel97 wrote:
Annoyingly we can't merge these dyn_casts together because it'll complain that there's no cast from VPRecipeBase:
```
llvm/include/llvm/Support/Casting.h:661:37: note: candidate function template not viable: cannot convert from base class pointer 'llvm::VPRecipeBase *' to derived class pointer 'VPWidenCallRecipe *' for 1st argument
```
https://github.com/llvm/llvm-project/pull/135017
- Previous message: [llvm] [VPlan] Simplify vp.merge true, (or x, y), x -> vp.merge y, true, x (PR #135017)
- Next message: [llvm] [VPlan] Simplify vp.merge true, (or x, y), x -> vp.merge y, true, x (PR #135017)
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the llvm-commits
mailing list