[SCCP] Turn sext into zext for non-negative ranges.
authorFlorian Hahn <flo@fhahn.com>
Fri, 19 Jun 2020 08:27:52 +0000 (09:27 +0100)
committerFlorian Hahn <flo@fhahn.com>
Fri, 19 Jun 2020 09:17:55 +0000 (10:17 +0100)
commitf9d8e33c324de95f868dbe50d0e1e475ef2d3beb
tree2e8dd58c338b27c813364ecc4b4aea7e0b836d7c
parent7cdf4326a8f290da3804cc92b9dccf45195079dc
[SCCP] Turn sext into zext for non-negative ranges.

This patch updates SCCP/IPSCCP to use the computed range info to turn
sexts into zexts, if the value is known to be non-negative. We already
to a similar transform in CorrelatedValuePropagation, but it seems like
we can catch a lot of additional cases by doing it in SCCP/IPSCCP as
well.

The transform is limited to ranges that are known to not include undef.

Currently constant ranges from conditions are treated as potentially
containing undef, due to PR46144. Once we flip this, the transform will
be more effective in practice.

Reviewers: efriedma, davide

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D81756
llvm/lib/Transforms/Scalar/SCCP.cpp
llvm/test/Transforms/SCCP/ip-ranges-casts.ll
llvm/test/Transforms/SCCP/ip-ranges-sext.ll
llvm/test/Transforms/SCCP/ranges-sext.ll
llvm/test/Transforms/SCCP/widening.ll