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.
For it to be effective, we have to flip the MayIncludeUndef flag when
constructing ranges from predicates. That should be in line with the
recent LangRef updates, but may expose problems in other passes not
expecting branches on undef to be UB. But it might be good to start
making more aggressive use of the LangRef update and fix issues
uncovered. Alternatively we could wait until the 11.0 release branch is
taken.
Without this patch, CorrelatedValuePropagation turns ~6400 sexts into
zexts on MultiSource, SPEC2000 & SPEC2006. With this patch, CVP
transforms around 4000, while IPSCCP transforms around 10000.
This change impacts 90 binaries (147 unchanged). One interesting impact
is that this leads to a few more loops getting vectorized, probably
because reasoning about zexts is easier than about sexts in SCEV & co:
Program base patch3 diff
test-suite...T2000/256.bzip2/256.bzip2.test 20.00 21.00 5.0%
test-suite...T2006/401.bzip2/401.bzip2.test 22.00 23.00 4.5%
test-suite...0.perlbench/400.perlbench.test 84.00 87.00 3.6%
test-suite.../CINT2000/176.gcc/176.gcc.test 90.00 93.00 3.3%
test-suite...lications/ClamAV/clamscan.test 91.00 92.00 1.1%
test-suite.../CINT2006/403.gcc/403.gcc.test 220.00 222.00 0.9%
test-suite...pplications/oggenc/oggenc.test 126.00 127.00 0.8%
test-suite...arks/mafft/pairlocalalign.test 319.00 321.00 0.6%
test-suite...marks/7zip/7zip-benchmark.test 374.00 375.00 0.3%
I'm a little uncomfortable that flipping this from true to false impacted zero testcases...
I'm not sure how to judge exactly how risky it is to land this without fixes to various passes we know have issues. I'm particularly worried about loop unswitch, since we saw a real miscompile involving it in the past.