[llvm] [LV] Rewrite UDiv A, B -> UDiv A, UMax(B, 1) in trip counts if needed. (PR #92177)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 16 17:30:45 PDT 2024


================
@@ -527,6 +528,76 @@ exit:
   ret i64 %p
 }
 
+define i64 @multi_exit_4_exit_count_with_udiv_by_frozen_value_in_latch(ptr %dst, i64 %N) {
----------------
efriedma-quic wrote:

I think SCEV is actually computing the trip count wrong here.  It currently produces `((42 /u %fr.N) umin (0 smax %N2))`... but I think it should actually be `((0 smax %N2) umin_seq (42 /u %fr.N))`.  And that should be a well-defined if %N2 is zero, even if we would divide by zero without the umin_seq.  (I don't think anyone was thinking about divide-by-zero when https://reviews.llvm.org/D116766 was originally proposed, but it seems like a natural extension.)

Under those semantics, we shouldn't need to modify VPlan to examine the exits.  SCEVExpander itself should enable SafeUDivMode when it evaluates operands of umin_seq after the first.

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


More information about the llvm-commits mailing list