[llvm] [VPlan] Simplify (X && Y) || (X && !Y) -> X. (PR #89386)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun May 12 13:05:11 PDT 2024
================
@@ -192,6 +191,47 @@ using AllBinaryRecipe_match =
BinaryRecipe_match<Op0_t, Op1_t, Opcode, VPWidenRecipe, VPReplicateRecipe,
VPWidenCastRecipe, VPInstruction>;
+template <typename Op0_t, typename Op1_t, unsigned Opcode, bool Commutable,
+ typename... RecipeTys>
+struct LogicalRecipe_match {
+ Op0_t LHS;
+ Op1_t RHS;
+
+ LogicalRecipe_match(Op0_t LHS, Op1_t RHS) : LHS(LHS), RHS(RHS) {}
+
+ bool match(const VPValue *V) {
+ auto *DefR = V->getDefiningRecipe();
+ return DefR && match(DefR);
+ }
+
+ bool match(const VPSingleDefRecipe *R) {
+ return match(static_cast<const VPRecipeBase *>(R));
+ }
+
+ bool match(const VPRecipeBase *R) {
+ if (!detail::MatchRecipeAndOpcode<Opcode, RecipeTys...>::match(R)) {
+ if (!detail::MatchRecipeAndOpcode<Instruction::Select,
+ RecipeTys...>::match(R))
+ return false;
+ if (Opcode == Instruction::And) {
+ if (!m_False().match(R->getOperand(2)))
----------------
fhahn wrote:
Put up to add a logical-and opcode and use that when creating edge masks: https://github.com/llvm/llvm-project/pull/91897
> Independently, should createBlockInMask() generate logical OR's using selects as well, possibly by recipes that target IRBuilder::CreateLogicalOr(), rather than plain bitwise OR's via IRBuilder's CreateBinOp()?
Hmm, I am not sure. Would probably warrant a separate look.
> The only AND/OR VPInstructions currently in use are those generated by create[Edge,BlockIn]Mask(), which are logical(ly dealing with masks), right? Actually, VPBuilder::createAnd() appears to be useless, after createEdgeMask() switched to calling VPBuilder::createSelect() instead, so no AND VPInstructions appear to exist, neither bitwise nor logical.
I think so yes, let me clean this up separately.
https://github.com/llvm/llvm-project/pull/89386
More information about the llvm-commits
mailing list