This is an archive of the discontinued LLVM Phabricator instance.

[ConstraintElim] Add reproducer remarks.
ClosedPublic

Authored by fhahn on Feb 4 2023, 9:10 AM.

Details

Summary

This patch adds an optimization remark for each performed optimization
containing a module that can be used to reproduce the transformation.

The reproducer function contains a series of @llvm.assume calls, one for
each condition currently in scope. For each condition, the operand
instruction are cloned until we reach operands that have an entry in the
constraint system. Those will then be added as function arguments.

The reproducer functions are minimal, that is, they only contain the
conditions required for a given simplification. The resulting IR is very
compact and can be used to verify each transformation individually.

It also provides a python script to extract the IR from the remarks and
create LLVM IR files from it.

Diff Detail

Event Timeline

fhahn created this revision.Feb 4 2023, 9:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 4 2023, 9:10 AM
fhahn requested review of this revision.Feb 4 2023, 9:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 4 2023, 9:10 AM
paquette added inline comments.Feb 6 2023, 10:52 AM
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
757–912

doxygen comments for this?

770

Can you document this parameter?

782

This lambda is long enough that I feel like it ought to just be a function (if possible)

825

These loops can be merged into one loop

tschuett added inline comments.
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
757–912

You can, may, or should wrap the struct with an anonymous namespace. You are very careful with static.

fhahn marked 5 inline comments as done.Feb 7 2023, 9:13 AM
fhahn added inline comments.
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
757–912

Added comment and moved to anon namespace, thanks!

770

Documented the missing arguments, thanks!

782

Hmm, it would be possible but would mean passing a bunch of extra parameters that can conveniently be captured here. Happy to move it out if you think it is strictly better, but IMO having the lambda keeps it a bit simpler and limits the scope to the function here.

825

Done, thanks!

fhahn updated this revision to Diff 495572.Feb 7 2023, 9:13 AM
fhahn marked 4 inline comments as done.

Address comments, thanks!

paquette accepted this revision.Feb 13 2023, 10:12 AM

Only things I can think of that would be nice to add are

  • Some debug output, if possible
  • Comments for the lambdas + some of the loops

Other than that, this LGTM.

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
786

Could this have a comment that outlines which part it plays in the overall algorithm?

828

A comment here would be useful for future readers as well.

838

This can use a comment too (even though the name is pretty descriptive, it does some other stuff such as sorting the instructions)

865

Comment on this loop too?

This revision is now accepted and ready to land.Feb 13 2023, 10:12 AM
This revision was automatically updated to reflect the committed changes.
fhahn marked 4 inline comments as done.
fhahn added a comment.Feb 14 2023, 7:16 AM

Thanks Jessica! The committed version should include additional comments, a bit of extra debug output + a test for the output.