[SCCP] Use range info to prove AddInst has NSW flag.
authorFlorian Hahn <flo@fhahn.com>
Fri, 27 Jan 2023 14:09:25 +0000 (14:09 +0000)
committerFlorian Hahn <flo@fhahn.com>
Fri, 27 Jan 2023 14:09:26 +0000 (14:09 +0000)
commit72121a20cda4dc91d0ef5548f93046e71c5ec6f6
tree28efc2307bdc1a36874050a79301dd86c0d3c85f
parent977cddb95eac67a6dc6680a7d0fadee81114de11
[SCCP] Use range info to prove AddInst has NSW flag.

This patch updates SCCP to use the value ranges of AddInst operands to
try to prove the AddInst does not overflow in the signed sense and
adds the NSW flag. The reasoning is done with
makeGuaranteedNoWrapRegion (thanks @nikic for point it out!).

Follow-ups will include extending this to more
OverflowingBinaryOperators.

Depends on D142387.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D142390
14 files changed:
llvm/lib/Transforms/Utils/SCCPSolver.cpp
llvm/test/Transforms/SCCP/add-nuw-nsw-flags.ll
llvm/test/Transforms/SCCP/binaryops-constexprs.ll
llvm/test/Transforms/SCCP/conditions-ranges-with-undef.ll
llvm/test/Transforms/SCCP/conditions-ranges.ll
llvm/test/Transforms/SCCP/ip-add-range-to-call.ll
llvm/test/Transforms/SCCP/ip-constant-ranges.ll
llvm/test/Transforms/SCCP/ip-ranges-binaryops.ll
llvm/test/Transforms/SCCP/ip-ranges-casts.ll
llvm/test/Transforms/SCCP/ip-ranges-phis.ll
llvm/test/Transforms/SCCP/ip-ranges-select.ll
llvm/test/Transforms/SCCP/return-argument.ll
llvm/test/Transforms/SCCP/return-constants.ll
llvm/test/Transforms/SCCP/widening.ll