[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
Thu Sep 26 14:30:04 PDT 2024


================
@@ -1358,11 +1364,13 @@ Value *SCEVExpander::visitSignExtendExpr(const SCEVSignExtendExpr *S) {
 Value *SCEVExpander::expandMinMaxExpr(const SCEVNAryExpr *S,
                                       Intrinsic::ID IntrinID, Twine Name,
                                       bool IsSequential) {
+  SafeUDivMode = true;
   Value *LHS = expand(S->getOperand(S->getNumOperands() - 1));
   Type *Ty = LHS->getType();
   if (IsSequential)
     LHS = Builder.CreateFreeze(LHS);
   for (int i = S->getNumOperands() - 2; i >= 0; --i) {
+    SafeUDivMode = i != 0;
----------------
efriedma-quic wrote:

I think you need to save/restore the mode, in case you have nested min/max.

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


More information about the llvm-commits mailing list