From 8db13de265a5f12d49147930da6d16a3ad7b40e3 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 31 Jul 2026 18:55:33 +0800 Subject: [PATCH] [VPlan] Remove redundant x && (y && x) -> x && y combine (#213219) It can be subsumed by making the combine above commutative. In theory this isn't NFC as it changes the order, in practice it doesn't make a difference. --- llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h | 5 +++++ llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 14 ++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h index cf6d5e1408fc..d575d1f150e7 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h +++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h @@ -199,6 +199,11 @@ inline bind_const_int m_ConstantInt(uint64_t &C) { return C; } /// Match a VPValue, capturing it if we match. inline match_bind m_VPValue(VPValue *&V) { return V; } +/// Match against the nested pattern, and capture the value if we match. +template inline auto m_VPValue(VPValue *&V, const Op_t &Op) { + return m_CombineAnd(Op, m_VPValue(V)); +} + /// Match a VPIRValue. inline match_bind m_VPIRValue(VPIRValue *&V) { return V; } diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index 348dbe514a56..4d6f40ec32a6 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -1188,16 +1188,10 @@ static bool simplifyLogicalRecipe(VPSingleDefRecipe *Def, VPBuilder &Builder, } // x && (x && y) -> x && y - if (match(Def, m_LogicalAnd(m_VPValue(X), - m_LogicalAnd(m_Deferred(X), m_VPValue())))) { - Def->replaceAllUsesWith(Def->getOperand(1)); - return true; - } - - // x && (y && x) -> x && y - if (match(Def, m_LogicalAnd(m_VPValue(X), - m_LogicalAnd(m_VPValue(Y), m_Deferred(X))))) { - Def->replaceAllUsesWith(Builder.createLogicalAnd(X, Y)); + if (match(Def, m_c_LogicalAnd(m_VPValue(X), + m_VPValue(Z, m_c_LogicalAnd(m_Deferred(X), + m_VPValue()))))) { + Def->replaceAllUsesWith(Z); return true; }