[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:30 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 ]
+  %mul = mul i64 %j.015, %N
+  %gep = getelementptr [4 x i8], ptr %invariant.gep, i64 %mul
+  store i32 0, ptr %gep
+  %inc = add nuw i64 %j.015, 1
+  %exitcond.not = icmp eq i64 %inc, %N
+  br i1 %exitcond.not, label %outer.latch, label %inner.body
+
+outer.latch:                                ; preds = %inner.body
----------------
fhahn wrote:

```suggestion
outer.latch:
```

pleaase remove the stray `; preds =`. All LV tests should have been cleaned up and it would be good to keep it so

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


More information about the llvm-commits mailing list