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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 10 08:22:31 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>(
----------------
lukel97 wrote:

If EVL > the number of elements in x then per the langref the result is poison, so the transform should be safe: https://llvm.org/docs/LangRef.html#id981

We end up with stray vector.splices on RISC-V without this, and InstCombine doesn't fold the splices away. So unfortunately I think we will end up with regressions since the reverses that are currently emitted are folded away by InstCombine

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


More information about the llvm-commits mailing list