[llvm] [LV] Use SCEV loop-uniformity for outer-loop branch legality (PR #199632)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 04:09:32 PDT 2026


================
@@ -91,6 +91,41 @@ exit:
   ret void
 }
 
+; The inner loop's exit condition depends on the outer loop's induction
+; variable, so its backedge branch is divergent across outer-loop iterations
+; and the outer loop must not be vectorized.
+define void @inner_loop_divergence_exit(ptr %a, i64 %N) {
+; CHECK-LABEL: LV: Checking a loop in 'inner_loop_divergence_exit'
+; CHECK: LV: Not vectorizing: Outer loop contains divergent conditional branch.
+; CHECK: LV: Not vectorizing: Unsupported outer loop.
+; CHECK: LV: Not vectorizing: Cannot prove legality.
+entry:
+  %cmp16.not = icmp eq i64 %N, 0
+  br i1 %cmp16.not, label %exit, label %outer.body
+
+outer.body:                              ; preds = %entry, %outer.latch
+  %i.017 = phi i64 [ %inc6, %outer.latch ], [ 0, %entry ]
+  %invariant.gep = getelementptr [4 x i8], ptr %a, i64 %i.017
+  br label %inner.body
+
+inner.body:                                        ; preds = %outer.body, %inner.body
+  %j.015 = phi i64 [ %i.017, %outer.body ], [ %inc, %inner.body ]
----------------
fhahn wrote:

```suggestion
  %inner.iv = phi i64 [ %i.017, %outer.body ], [ %inc, %inner.body ]
```

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


More information about the llvm-commits mailing list