[PATCH] D90648: [SCEV] Fix nsw flags for GEP expressions

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 2 14:25:41 PST 2020


nikic created this revision.
nikic added reviewers: mkazantsev, apilipenko, fhahn, efriedma, lebedev.ri.
Herald added subscribers: llvm-commits, javed.absar, hiraditya.
Herald added a project: LLVM.
nikic requested review of this revision.

The SCEV code for constructing GEP expressions currently assumes that the addition of the base and all the offsets is nsw if the GEP is inbounds. While the addition of the offsets is indeed nsw, the addition to the base address is not, as the base address is interpreted as an unsigned value (`gep inbounds 0x7fffffff, 1` is legal).

Fix the GEP expression code to not assume nsw for the base+offset calculation. However, do assume nuw if we know that the offset is non-negative. With this, we use the same behavior as the construction of GEP addrecs does. (Modulo the fact that we disregard SCEV unification, as the pre-existing FIXME points out).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90648

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Analysis/LoopAccessAnalysis/memcheck-wrapping-pointers.ll
  llvm/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll
  llvm/test/Analysis/LoopAccessAnalysis/reverse-memcheck-bounds.ll
  llvm/test/Analysis/LoopAccessAnalysis/wrapping-pointer-versioning.ll
  llvm/test/Analysis/ScalarEvolution/add-expr-pointer-operand-sorting.ll
  llvm/test/Analysis/ScalarEvolution/load.ll
  llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll
  llvm/test/Analysis/ScalarEvolution/no-wrap-add-exprs.ll
  llvm/test/Analysis/ScalarEvolution/nsw-offset-assume.ll
  llvm/test/Analysis/ScalarEvolution/nsw-offset.ll
  llvm/test/Analysis/ScalarEvolution/nsw.ll
  llvm/test/Analysis/ScalarEvolution/pr46786.ll
  llvm/test/Analysis/ScalarEvolution/ptrtoint.ll
  llvm/test/Analysis/ScalarEvolution/sdiv.ll
  llvm/test/Analysis/ScalarEvolution/srem.ll
  llvm/test/Transforms/LoopFusion/simple.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90648.302406.patch
Type: text/x-patch
Size: 45969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201102/8d6be798/attachment-0001.bin>


More information about the llvm-commits mailing list