[SCEV] Stop blindly propagating flags from inbound geps to SCEV nodes
authorPhilip Reames <listmail@philipreames.com>
Fri, 1 Oct 2021 23:30:44 +0000 (16:30 -0700)
committerPhilip Reames <listmail@philipreames.com>
Fri, 1 Oct 2021 23:30:44 +0000 (16:30 -0700)
commit2ca8a3f2132ec7d46151b4553ee166c4e635fd70
tree25db0a340262985c32a97f6dc18a3e750552a7ca
parent24cde2f6023a765b66923f4a4ac033a91878b856
[SCEV] Stop blindly propagating flags from inbound geps to SCEV nodes

This fixes a violation of the wrap flag rules introduced in c4048d8f. This was also noted in the (very old) PR23527.

The issue being fixed is that we assume the inbound flag on any GEP assumes that all users of *any* gep (or add) which happens to map to that SCEV would also be UB if the (other) gep overflowed. That's simply not true.

In terms of the test diffs, I don't see anything seriously problematic. The lost flags are expected (given the semantic restriction on when its legal to tag the SCEV), and there are several cases where the previously inferred flags are unsound per the new semantics.

The only common trend I noticed when looking at the deltas is that by not considering branch on poison as immediate UB in ValueTracking, we do miss a few cases we could reclaim. We may be able to claw some of these back with the follow ideas mentioned in PR51817.

It's worth noting that most of the changes are analysis result only changes. The two transform changes are pretty minimal. In one case, we miss the opportunity to infer a nuw (correctly). In the other, we fail to fold an exit and produce a loop invariant form instead. This one is probably over-reduced as the program appears to be undefined in practice, and neither before or after exploits that.

Differential Revision: https://reviews.llvm.org/D109789
16 files changed:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/LoopAccessAnalysis/memcheck-wrapping-pointers.ll
llvm/test/Analysis/LoopCacheAnalysis/PowerPC/stencil.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/no-wrap-symbolic-becount.ll
llvm/test/Analysis/ScalarEvolution/nsw.ll
llvm/test/Analysis/ScalarEvolution/ptrtoint.ll
llvm/test/Analysis/ScalarEvolution/sdiv.ll
llvm/test/Analysis/ScalarEvolution/srem.ll
llvm/test/Transforms/IndVarSimplify/eliminate-exit-no-dl.ll
llvm/test/Transforms/LoopStrengthReduce/X86/expander-crashes.ll
polly/test/ScopInfo/NonAffine/non-affine-loop-condition-dependent-access_2.ll
polly/test/ScopInfo/pointer-type-expressions.ll
polly/test/ScopInfo/unsigned-division-5.ll