[llvm] [LV] Transform to handle exits in the scalar loop (PR #148626)

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 5 07:54:31 PST 2025


================
@@ -38,6 +39,29 @@ define i64 @same_exit_block_phi_of_consts() {
 ; CHECK-NEXT:    [[RETVAL:%.*]] = phi i64 [ 1, [[MIDDLE_BLOCK]] ], [ 0, [[VECTOR_EARLY_EXIT]] ]
 ; CHECK-NEXT:    ret i64 [[RETVAL]]
 ;
+; EE-SCALAR-LABEL: define i64 @same_exit_block_phi_of_consts() {
+; EE-SCALAR-NEXT:  entry:
+; EE-SCALAR-NEXT:    [[P1:%.*]] = alloca [1024 x i8], align 1
+; EE-SCALAR-NEXT:    [[P2:%.*]] = alloca [1024 x i8], align 1
+; EE-SCALAR-NEXT:    call void @init_mem(ptr [[P1]], i64 1024)
+; EE-SCALAR-NEXT:    call void @init_mem(ptr [[P2]], i64 1024)
+; EE-SCALAR-NEXT:    br label [[LOOP:%.*]]
+; EE-SCALAR:       loop:
+; EE-SCALAR-NEXT:    [[INDEX:%.*]] = phi i64 [ [[INDEX_NEXT:%.*]], [[LOOP_INC:%.*]] ], [ 3, [[ENTRY:%.*]] ]
----------------
huntergr-arm wrote:

Gaƫtan asked the same question earlier, but github no longer shows comments consistently :/

Anyway, the reason is that we have an extra recipe in the chain for the condition which we don't yet support. That's a "DERIVED-IV" recipe, which is created because in the scalar loop the IV is `%index = phi i64 [ %index.next, %loop.inc ], [ 3, %entry ]`, which starts at 3 instead of 0. We'll need to add a little bit of extra logic to support that in the transform.

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


More information about the llvm-commits mailing list