[SCEV] Fix nsw flags for GEP expressions
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 2 Nov 2020 20:40:08 +0000 (21:40 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 13 Nov 2020 17:19:32 +0000 (18:19 +0100)
commitf3124a46c17e4683f96695aeceaf607920694710
treed36cd0ce105e85d104e67da6ccbb90334155099a
parentdf84941dcee5a38351412276c6a9f70ff5ee2957
[SCEV] Fix nsw flags for GEP expressions

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.

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).

Differential Revision: https://reviews.llvm.org/D90648
17 files changed:
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