Page MenuHomePhabricator

[SCCP] Use constant ranges for binary operators.

Authored by fhahn on Dec 27 2019, 8:32 AM.



If one of the operands of a binary operator is a constant range, we can
use ConstantRange::binaryOp to approximate the result.

We still handle single element constant ranges as we did previously,
with ConstantExpr::get(), because ConstantRange::binaryOp still gives
worse results in a few cases for single element ranges.

Also note that we bail out early if any of the operands is still unknown.

Diff Detail

Event Timeline

fhahn created this revision.Dec 27 2019, 8:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 27 2019, 8:32 AM
Herald added a subscriber: hiraditya. · View Herald Transcript

Unit tests: unknown.

clang-tidy: unknown.

clang-format: unknown.

Build artifacts: diff.json, console-log.txt

fhahn updated this revision to Diff 250902.Mar 17 2020, 2:21 PM

Ping. I think all required patches should have landed over the last week or so.


efriedma added inline comments.Mar 17 2020, 2:59 PM

Can we also use this codepath if one of the operands is overdefined/notconstant? We aren't using any interesting information about the "constant" operand anyway.

fhahn updated this revision to Diff 251042.Mar 18 2020, 4:54 AM

Use constant range logic also for overdefined/notconstant operands. It covers almost all special cases as before, excluding when vector constants are involved. In practice those do not seem to matter much. With the special logic enabled just for vectors, there are no changes in the result binaries. But we can generalize the constant handling to also support simplifying based on special constants, by using SimplifyInstruction for example.

This also makes D75054 obsolete.

fhahn marked an inline comment as done.Mar 18 2020, 4:56 AM
fhahn added inline comments.

Yes! we only miss out on some vector cases, but they do not seem to matter much in practice. I plan to better support those cases by using SimplifyBinOp for constants and overdefined operands.

Much cleaner. :)


Please change the CHECK line and add a TODO, instead of XFAIL'ing it.

fhahn updated this revision to Diff 251135.Mar 18 2020, 11:18 AM

Remove XFAIL, update check line instead, add FIXME.

fhahn marked an inline comment as done.Mar 18 2020, 11:19 AM
This revision is now accepted and ready to land.Mar 18 2020, 11:43 AM
This revision was automatically updated to reflect the committed changes.