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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 20 05:12:51 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) {
----------------
fhahn wrote:

Updated the PR to use umin_seq in the cases as suggested I think; the main additional change is to forbid simplifying `A umin_seq B` -> `A umin B`, if `B` may trigger UB (at the moment just SCEVUDivExpr?). This could be split off separately + SCEV printing test. Just want to make sure this is what you had in mind before doing so.

(There are some redundant freezes of the UDiv result which we could get rid of)

Looking at this again, I am not sure if the divisor being poison in `@multi_exit_4_exit_count_with_udiv_by_value_in_latch` actually needs freezing; as the expanded expression is used for a branch, if `%N` is poison, the branch on poison will also trigger UB, just slightly later. Granted at the SCEV &  expander level, we don't really know if that will be the case. `@multi_exit_4_exit_count_with_udiv_by_value_in_latch_different_bound` uses 2 different bounds for the exits, so here the freeze of the divisor is definitely needed

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


More information about the llvm-commits mailing list