[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
Fri Jun 28 14:10:25 PDT 2024


================
@@ -418,6 +418,13 @@ class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> {
   BasicBlock::iterator findInsertPointAfter(Instruction *I,
                                             Instruction *MustDominate) const;
 
+  /// If \p L contains exits which may execute conditionally and contain UDiv
+  /// expressions with divisors that can be 0, expanding \p BTC may introduce
+  /// new UB. In that case, rewrite UDiv(A, B) to  UDiv(A, UMAX(1, B)). If B is
+  /// 0, that exit cannot be taken.
----------------
efriedma-quic wrote:

Does this assume the loop eventually exits?  If it does, probably worth explicitly noting.

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


More information about the llvm-commits mailing list