This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] create and use a pass options container
ClosedPublic

Authored by spatel on Feb 16 2023, 9:03 AM.

Details

Summary

This is a cleanup/modernization patch requested in D144045 to make loop analysis a proper optional parameter to the pass rather than a semi-arbitrary value inherited via the pass pipeline.

It's a bit more complicated than the recent patch I started copying from (D143980) because InstCombine already has an option for MaxIterations (added with D71145).

I debated just deleting that option, but it was used by a pair of existing tests, so I put it into a struct (code largely copied from SimplifyCFG's implementation) to make the code more flexible for future options enhancements.

I didn't alter the pass manager invocations of InstCombine in this patch because the patch was already getting big, but that could be a small follow-up.

Diff Detail

Event Timeline

spatel created this revision.Feb 16 2023, 9:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 16 2023, 9:03 AM
spatel requested review of this revision.Feb 16 2023, 9:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 16 2023, 9:03 AM
nikic added inline comments.Feb 17 2023, 12:12 AM
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
4664–4666

This should be initialized to nullptr. We should not use LoopInfo unless UseLoopInfo is set.

spatel added inline comments.Feb 17 2023, 5:20 AM
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
4664–4666

Make sure I am understanding correctly - if we do this:

LoopInfo *LI = nullptr;
if (Options.UseLoopInfo) {
  LI = AM.getCachedResult<LoopAnalysis>(F);
  if (!LI)
    LI = &AM.getResult<LoopAnalysis>(F);
}

...then we must update PassBuilderPipelines in this patch too to avoid regressions.
I was intentionally trying to keep this part functionally the same as before to reduce risk, and then change it in a follow-up patch.

nikic accepted this revision.Feb 17 2023, 5:28 AM

LGTM

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
4664–4666

I see, fine to do in a followup.

This revision is now accepted and ready to land.Feb 17 2023, 5:28 AM
This revision was landed with ongoing or failed builds.Feb 17 2023, 7:30 AM
This revision was automatically updated to reflect the committed changes.
fhahn added a subscriber: fhahn.Jun 28 2023, 6:11 AM

AFAICT the option is always disabled in the default pipeline. Are there any plans to enable it at some point?

nikic added a comment.Jun 28 2023, 6:14 AM

AFAICT the option is always disabled in the default pipeline. Are there any plans to enable it at some point?

No, the option and LoopInfo use in InstCombine will be removed. The relevant code has been moved to LICM.