[llvm] [LoopVectorize] Loop-invariant backedge values prevent recognition of fixed-order recurrence (PR #228021)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 6 04:24:34 PDT 2026
================
@@ -0,0 +1,39 @@
+; RUN: opt -passes=loop-vectorize -force-vector-width=2 \
+; RUN: -force-vector-interleave=1 -S %s | FileCheck %s
+
+; GVN load PRE can create a recurrence whose latch value is loop invariant.
+; Make sure the recurrence is recognized and widened.
+
+; CHECK-LABEL: define void @invariant_backedge_phi(
+; CHECK: vector.ph:
+; CHECK: [[SPLATINSERT:%.*]] = insertelement <2 x double> poison, double %next, i64 0
+; CHECK: [[SPLAT:%.*]] = shufflevector <2 x double> [[SPLATINSERT]], <2 x double> poison, <2 x i32> zeroinitializer
+; CHECK: [[RECURINIT:%.*]] = insertelement <2 x double> poison, double %init, i32 1
+; CHECK: vector.body:
+; CHECK: [[RECUR:%.*]] = phi <2 x double> [ [[RECURINIT]], %vector.ph ], [ [[SPLAT]], %vector.body ]
+; CHECK: shufflevector <2 x double> [[RECUR]], <2 x double> [[SPLAT]], <2 x i32> <i32 1, i32 2>
+
+define void @invariant_backedge_phi(
----------------
yafet-a wrote:
I kept the patch limited to instruction valued backedges since that was the form produced in the regression.
I'm happy to add negative tests for argument and constant backedges to make clear that they remain unsupported. I'd also be happy to instead of that just generalise the implementation to support all loop-invariant values (so include constants + argument backedges) if that is the preferred solution.
https://github.com/llvm/llvm-project/pull/228021
More information about the llvm-commits
mailing list