[llvm] [VPlan] Simplify reverse(reverse(x)) -> x (PR #199057)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 8 05:44:03 PDT 2026
================
@@ -1835,6 +1835,27 @@ void VPlanTransforms::simplifyRecipes(VPlan &Plan) {
}
}
+void VPlanTransforms::simplifyReverses(VPlan &Plan) {
+ auto m_ReverseReverse = [](auto X) {
+ VPValue *EVL;
+ return m_CombineOr(
+ m_Reverse(m_Reverse(X)),
+ m_vp_Reverse(m_vp_Reverse(X, m_VPValue(), m_VPValue(EVL)), m_VPValue(),
+ m_Deferred(EVL)));
+ };
+
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+ vp_depth_first_deep(Plan.getEntry()))) {
+ for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
+ VPValue *X;
+ if (match(&R, m_ReverseReverse(m_VPValue(X)))) {
----------------
lukel97 wrote:
Yeah the plan is to also simplify those away in VPlan after this PR by "pulling" reverses out of any elementwise operation, see #199234. So the `reverse(fadd(reverse x), 1.0)` becomes `reverse(reverse(fadd x, 1.0))`, and the reverses then cancel out. This is how InstCombine does the same simplification IIUC
https://github.com/llvm/llvm-project/pull/199057
More information about the llvm-commits
mailing list