[PATCH] D148931: [SCEV] Don't blindly transfer nowrap flags to pre-inc addrec

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 21 08:59:40 PDT 2023


nikic created this revision.
nikic added reviewers: reames, mkazantsev, fhahn, efriedma.
Herald added subscribers: kosarev, StephenFan, kerbowa, zzheng, hiraditya, jvesely.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

While writing a blog post I tried to explain why it is always safe to transfer IR nowrap flags to the pre-inc addrec, and ... couldn't, because I don't think it's correct. The most straightforward example would be two `{0,+,1}` addrecs, one of them has a `nuw` flag in IR but is never used, and the other doesn't have one and is used. We could incorrectly transfer the nuw flag from the former to the latter.

I believe we can transfer the nowrap flags only if either a) the addrec is known non-poison or b) the post-inc instruction being poison would cause UB in a latch-dominating instruction. In particular, this includes the IV being used in any exit condition.

This patch is still WIP because I need to properly update tests, but I wanted to put this up for some early feedback.


https://reviews.llvm.org/D148931

Files:
  llvm/include/llvm/Analysis/ScalarEvolution.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Analysis/ScalarEvolution/decrementing_addrecs.ll
  llvm/test/Analysis/ScalarEvolution/different-loops-recs.ll
  llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll
  llvm/test/Analysis/ScalarEvolution/infer-prestart-no-wrap.ll
  llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
  llvm/test/Analysis/ScalarEvolution/max-expr-cache.ll
  llvm/test/Analysis/ScalarEvolution/nowrap-preinc-limits.ll
  llvm/test/Analysis/ScalarEvolution/nsw.ll
  llvm/test/Analysis/ScalarEvolution/pr27315.ll
  llvm/test/Analysis/ScalarEvolution/range-signedness.ll
  llvm/test/Analysis/ScalarEvolution/smin-smax-folds.ll
  llvm/test/Analysis/ScalarEvolution/trip-count-andor-selectform.ll
  llvm/test/Transforms/IndVarSimplify/X86/pr27133.ll
  llvm/test/Transforms/IndVarSimplify/lftr-pr31181.ll
  llvm/test/Transforms/IndVarSimplify/lftr.ll
  llvm/test/Transforms/IndVarSimplify/pr25578.ll
  llvm/test/Transforms/IndVarSimplify/pr55925.ll
  llvm/test/Transforms/IndVarSimplify/scev-expander-preserve-lcssa.ll
  llvm/test/Transforms/LoopSimplifyCFG/invalidate-scev-dispositions.ll
  llvm/test/Transforms/LoopStrengthReduce/AMDGPU/lsr-invalid-ptr-extend.ll
  llvm/test/Transforms/LoopStrengthReduce/X86/sibling-loops.ll
  llvm/test/Transforms/LoopUnroll/wrong_assert_in_peeling.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148931.515758.patch
Type: text/x-patch
Size: 149069 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230421/452ffabb/attachment-0001.bin>


More information about the llvm-commits mailing list