[llvm] [SCEVDivision] Add SCEVDivisionPrinterPass with corresponding tests (PR #155832)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 28 07:12:39 PDT 2025


================
@@ -257,3 +261,31 @@ void SCEVDivision::cannotDivide(const SCEV *Numerator) {
   Quotient = Zero;
   Remainder = Numerator;
 }
+
+void SCEVDivisionPrinterPass::runImpl(Function &F, ScalarEvolution &SE) {
+  OS << "Printing analysis 'Scalar Evolution Division' for function '"
+     << F.getName() << "':\n";
+  for (Instruction &Inst : instructions(F)) {
+    BinaryOperator *Div = dyn_cast<BinaryOperator>(&Inst);
+    if (!Div || Div->getOpcode() != Instruction::SDiv)
+      continue;
+
+    const SCEV *Numerator = SE.getSCEV(Div->getOperand(0));
+    const SCEV *Denominator = SE.getSCEV(Div->getOperand(1));
+    const SCEV *Quotient, *Remainder;
+    SCEVDivision::divide(SE, Numerator, Denominator, &Quotient, &Remainder);
----------------
nikic wrote:

I guess it's kind of sign independent in the sense that this is not a proper division anyway, so either result is actually correct. The only part that is actually "signed" is division of constants.

So I guess this is a kind of abstract division with a weak hint towards signed...

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


More information about the llvm-commits mailing list