[llvm] [LV] Add -fold-epilogue-tail option for tail-folded epilogue (PR #190697)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sat May 2 03:17:42 PDT 2026


================
@@ -0,0 +1,87 @@
+; REQUIRES: asserts
+; RUN: opt -S < %s -p loop-vectorize -debug-only=loop-vectorize --disable-output \
+; RUN: -tail-folding-policy=prefer-fold-epilogue-tail 2>&1 | FileCheck %s
+
+; RUN: opt -S < %s -p loop-vectorize -debug-only=loop-vectorize -enable-epilogue-vectorization=false \
+; RUN: --disable-output -tail-folding-policy=prefer-fold-epilogue-tail 2>&1 \
+; RUN: | FileCheck %s --check-prefix=CHECK-DISABLED-EPILOG
+
+define void @test_epilogue_tf(ptr %A, i64 %n) {
+; CHECK: LV: Checking a loop in 'test_epilogue_tf'
+; CHECK: LV: epilogue tail-folding is not supported yet
+; CHECK: The tail-folding policy prefer-fold-epilogue-tail is not supported yet, fall back to a normal epilogue.
+entry:
+  br label %for.body
+
+for.body:
+  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
+  %arrayidx = getelementptr inbounds i8, ptr %A, i64 %iv
+  store i8 1, ptr %arrayidx, align 1
+  %iv.next = add nuw nsw i64 %iv, 1
+  %exitcond = icmp ne i64 %iv.next, %n
+  br i1 %exitcond, label %for.body, label %exit
+
+exit:
+  ret void
+}
+
+define void @epilogue_is_disabled(ptr %a, i64 %n) {
+; CHECK-DISABLED-EPILOG: LV: Checking a loop in 'epilogue_is_disabled'
+; CHECK-DISABLED-EPILOG: LV: Options conflict, epilogue vectorization is disallowed while epilogue tail-folding allowed!
+entry:
+  %cmp1 = icmp sgt i64 %n, 0
+  br i1 %cmp1, label %for.body, label %for.end
----------------
fhahn wrote:

do we need this check here?

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


More information about the llvm-commits mailing list