[SCEV] Use both known bits and sign bits when computing range of SCEV unknowns
authorPhilip Reames <listmail@philipreames.com>
Fri, 19 Feb 2021 16:27:46 +0000 (08:27 -0800)
committerPhilip Reames <listmail@philipreames.com>
Fri, 19 Feb 2021 16:29:12 +0000 (08:29 -0800)
commit4a5edea1930ddbcd3af46827f6cc976cc1b30e2a
tree788cb56c1564469807bc562ea94de41a7cfe6a44
parentbcb5a124aea8ecba090ffe2815e357480830d53b
[SCEV] Use both known bits and sign bits when computing range of SCEV unknowns

When computing a range for a SCEVUnknown, today we use computeKnownBits for unsigned ranges, and computeNumSignBots for signed ranges. This means we miss opportunities to improve range results.

One common missed pattern is that we have a signed range of a value which CKB can determine is positive, but CNSB doesn't convey that information. The current range includes the negative part, and is thus double the size.

Per the removed comment, the original concern which delayed using both (after some code merging years back) was a compile time concern. CTMark results (provided by Nikita, thanks!) showed a geomean impact of about 0.1%. This doesn't seem large enough to avoid higher quality results.

Differential Revision: https://reviews.llvm.org/D96534
13 files changed:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/add-expr-pointer-operand-sorting.ll
llvm/test/Analysis/ScalarEvolution/ashr.ll
llvm/test/Analysis/ScalarEvolution/extract-highbits-sameconstmask.ll
llvm/test/Analysis/ScalarEvolution/increasing-or-decreasing-iv.ll
llvm/test/Analysis/ScalarEvolution/max-be-count-not-constant.ll
llvm/test/Analysis/ScalarEvolution/ptrtoint-constantexpr-loop.ll
llvm/test/Analysis/ScalarEvolution/ptrtoint.ll
llvm/test/Analysis/ScalarEvolution/ranges.ll
llvm/test/Analysis/ScalarEvolution/sext-to-zext.ll
llvm/test/Analysis/StackSafetyAnalysis/local.ll
llvm/test/Analysis/StackSafetyAnalysis/memintrin.ll
llvm/test/Transforms/PhaseOrdering/scev-custom-dl.ll