[llvm] [LV] Allow runtime checks for low trip count loops without scalar epilogues (PR #197391)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 21 03:42:15 PDT 2026


================
@@ -0,0 +1,87 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 6
+; RUN: opt -S < %s -passes=loop-vectorize -mtriple=aarch64-unknown-linux-gnu | FileCheck %s
+
+define void @low_trip_count_12_needs_runtime_check(ptr %dst, ptr %a, ptr %b, i32 %m) {
----------------
fhahn wrote:

Can you also add the variant below (`minsize`/`optsize` is important).

```
  define void @minsize(ptr %dst, ptr %a, ptr %b) minsize { 
  entry:
    br label %loop

  loop:
    %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
    %a.gep = getelementptr inbounds i32, ptr %a, i64 %iv
    %av = load i32, ptr %a.gep, align 4
    %b.gep = getelementptr inbounds i32, ptr %b, i64 %iv
    %bv = load i32, ptr %b.gep, align 4
    %sum = add i32 %av, %bv
    %d.gep = getelementptr inbounds i32, ptr %dst, i64 %iv
    store i32 %sum, ptr %d.gep, align 4
    %iv.next = add nuw nsw i64 %iv, 1
    %cmp = icmp ult i64 %iv.next, 12 
    br i1 %cmp, label %loop, label %exit

  exit:
    ret void
  }
```

I think this should trigger an assert in `attachRuntimeChecks`, specifically

```
     if (Config.OptForSize) {
      assert(
          CM.Hints->getForce() == LoopVectorizeHints::FK_Enabled &&
          "Cannot emit memory checks when optimizing for size, unless forced "
          "to vectorize.");
```

I think this is due to the fall through being removed.

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


More information about the llvm-commits mailing list