[PATCH] D145395: [SCEV] Also strengthen flags for post-increment.

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 7 00:20:16 PST 2023


nikic added inline comments.


================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:5673
   if (auto *AR = dyn_cast<SCEVAddRecExpr>(PHISCEV)) {
-    setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR),
-                   (SCEV::NoWrapFlags)(AR->getNoWrapFlags() |
-                                       proveNoWrapViaConstantRanges(AR)));
+    Flags = (SCEV::NoWrapFlags)(Flags | proveNoWrapViaConstantRanges(AR));
+    setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), Flags);
----------------
It's not really obvious to me why this is correct. Can't the extra addition of the post-inc addrec overflow, even if the pre-inc addrec can't? I believe the current reasoning for setting flags on the post-inc addrec is specifically about nowrap flags present in IR that would result in UB if violated. I don't think this would hold up for flags inferred from the pre-inc addrec range.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145395/new/

https://reviews.llvm.org/D145395



More information about the llvm-commits mailing list