[llvm] [LV] Add extra check for signed oveflow for SDiv/SRem (PR #170818)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 5 02:27:22 PST 2025


================
@@ -2878,11 +2886,13 @@ bool LoopVectorizationCostModel::isPredicatedInst(Instruction *I) const {
              TheLoop->isLoopInvariant(cast<StoreInst>(I)->getValueOperand()));
   }
   case Instruction::UDiv:
-  case Instruction::SDiv:
-  case Instruction::SRem:
   case Instruction::URem:
     // If the divisor is loop-invariant no predication is needed.
     return !Legal->isInvariant(I->getOperand(1));
+  case Instruction::SDiv:
+  case Instruction::SRem:
+    // Extra check for signed overflow.
+    return !Legal->isInvariant(I->getOperand(1)) || MayOverflow(I);
----------------
fhahn wrote:

the lambda is only used here, an you inline + and explanation of the UB this is preventing?


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


More information about the llvm-commits mailing list