[llvm] [VPlan] Simplify reverse(reverse(x)) -> x (PR #199057)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 8 05:37:11 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)))) {
----------------
david-arm wrote:
In general I have also seen IR generated the vectoriser like this:
%rev1 = reverse %a
%fadd = fadd fast %rev1, splat (float 1.0e+00)
%rev2 = reverse %fadd
where there is only one use of %rev1 and one use of %fadd. I think these pair-reverse simplifications could be used in more places to reduce the cost, since instcombine would fold away these reverses.
https://github.com/llvm/llvm-project/pull/199057
More information about the llvm-commits
mailing list