[llvm] [VPlan] Simplify reverse(reverse(x)) -> x (PR #199057)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 10 08:10:18 PDT 2026


================
@@ -3138,11 +3148,22 @@ void VPlanTransforms::optimizeEVLMasks(VPlan &Plan) {
     }
   }
 
-  // Fold the following splice patterns into vp.reverse for reverse accesses:
+  // Fold the following splice patterns:
+  //   splice.right(splice.left(poison, x, evl), poison, evl) -> x
   //   vector.reverse(splice.left(poison, x, evl))  -> vp.reverse(x, true, evl)
   //   splice.right(vector.reverse(x), poison, evl) -> vp.reverse(x, true, evl)
   for (VPUser *U : collectUsersRecursively(EVL)) {
+    auto *Def = cast<VPRecipeBase>(U);
     VPValue *X;
+    if (match(U, m_Intrinsic<Intrinsic::vector_splice_right>(
----------------
david-arm wrote:

Is this guaranteed to be safe? Is there something in the LangRef or intrinsic property of EVL that ensures EVL <= number of elements of x? If not, then you may end up permanently losing elements of x and so the transformation is unsafe.

Could this part of the PR be committed separately to the simplifyReverses bit?

https://github.com/llvm/llvm-project/pull/199057


More information about the llvm-commits mailing list