This is an archive of the discontinued LLVM Phabricator instance.

[IRBuilder] Simplify 'or 0, RHS' -> RHS on creation.
AbandonedPublic

Authored by fhahn on Jan 7 2022, 9:14 AM.

Details

Summary

CreateOr already simplifies 'or LHS, 0' to LHS. Do the same, just for
LHS == 0.

Diff Detail

Event Timeline

fhahn requested review of this revision.Jan 7 2022, 9:14 AM
fhahn created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 7 2022, 9:14 AM

I believe we've disscussed and we should instead rip out all of such constant folding from IRBuilder.

nikic added a comment.Jan 7 2022, 9:46 AM

IRBuilder accepts a Folder that currently gives you the choice between no folding, target-independent constant folding and target-dependent constant folding. If we change the API to not be restricted to Constants, we could add a SimplifyFolder that calls into InstSimplify instead.

Maybe that would help more generally for what you're currently doing? We could generate code in the straightforward way, but let IRBuilder fold away trivial identities via simplification, without having to reimplement them.

fhahn added a comment.Jan 7 2022, 10:10 AM

IRBuilder accepts a Folder that currently gives you the choice between no folding, target-independent constant folding and target-dependent constant folding. If we change the API to not be restricted to Constants, we could add a SimplifyFolder that calls into InstSimplify instead.

Maybe that would help more generally for what you're currently doing? We could generate code in the straightforward way, but let IRBuilder fold away trivial identities via simplification, without having to reimplement them.

I think it might make sense to provide a InstSimplifyFolder in general, but it looks like this will require some larger changes, as at the moment all folders only seem to support constants.

fhahn added a comment.Jan 10 2022, 5:55 AM

IRBuilder accepts a Folder that currently gives you the choice between no folding, target-independent constant folding and target-dependent constant folding. If we change the API to not be restricted to Constants, we could add a SimplifyFolder that calls into InstSimplify instead.

Maybe that would help more generally for what you're currently doing? We could generate code in the straightforward way, but let IRBuilder fold away trivial identities via simplification, without having to reimplement them.

I think it might make sense to provide a InstSimplifyFolder in general, but it looks like this will require some larger changes, as at the moment all folders only seem to support constants.

I put up a patch that adds an inst-simplify based folder as an alternative: D116935. It is very much focused on transitioning one function at a time, starting with Or simplification. I'm not sure which other use cases people have in mind, it would be good to hear about them.

fhahn abandoned this revision.Jan 10 2022, 12:44 PM

Looks like D116935 is the way to go.