Page MenuHomePhabricator

[SCCP] Use constant ranges for binary operators.
ClosedPublic

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

Details

Summary

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.Tue, Mar 17, 2:21 PM

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

Rebased.

efriedma added inline comments.Tue, Mar 17, 2:59 PM
llvm/lib/Transforms/Scalar/SCCP.cpp
1031

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.Wed, Mar 18, 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.Wed, Mar 18, 4:56 AM
fhahn added inline comments.
llvm/lib/Transforms/Scalar/SCCP.cpp
1031

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. :)

llvm/test/Transforms/SCCP/vector-bitcast.ll
2

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

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

Remove XFAIL, update check line instead, add FIXME.

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