This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Make new pass manager's OptimizationLevel a class
ClosedPublic

Authored by mtrofin on Jan 10 2020, 4:47 PM.

Details

Summary

The old pass manager separated speed optimization and size optimization
levels into two unsigned values. Coallescing both in an enum in the new
pass manager may lead to unintentional casts and comparisons.

In particular, taking a look at how the loop unroll passes were constructed
previously, the Os/Oz are now (==new pass manager) treated just like O3,
likely unintentionally.

This change disallows raw comparisons between optimization levels, to
avoid such unintended effects. As an effect, the O{s|z} behavior changes
for loop unrolling and loop unroll and jam, matching O2 rather than O3.

The change also parameterizes the threshold values used for loop
unrolling, primarily to aid testing.

Diff Detail

Event Timeline

mtrofin created this revision.Jan 10 2020, 4:47 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 10 2020, 4:47 PM
This comment was removed by mtrofin.
mtrofin updated this revision to Diff 237464.Jan 10 2020, 5:31 PM

Speedup level is actually '2' for Os and Oz

I just have a few high level comments from looking through it just now. The summary needs a fix since Os/Oz are in fact O2 so OptLevel > 1 was not doing the wrong thing.

llvm/include/llvm/Passes/PassBuilder.h
234

Can you add a comment as to why Os and Oz are considered as optimizing for speed? I know this is for compatibility with the current code, but would be good to document (and consider changing in the future).

235

This one is a little confusing to read, since at this point there is no correlation between the values 4 and 5, and the Os and Oz static variables. Consider making some constexpr values for each level, used in the methods here and in the static variable initializations?

236

Since (as discussed off-patch), in the old PM Os and Oz are also opt level 2, this should presumably return true for those as well. That should obviate the need for many places in the patch where you are currently checking isO2Or3 || isOptimizingForSize, and you can just check isO2Or3.

281

There are a lot of formatting changes throughout the patch that are unrelated to your changes - it seems like you might have clang formatted the whole files? Can you only include the changes related to the patch here, it's harder to review with lots of spurious diffs.

ychen added a subscriber: ychen.Jan 10 2020, 10:23 PM
mtrofin updated this revision to Diff 238107.Jan 14 2020, 2:44 PM
mtrofin marked 2 inline comments as done.

Alternative: expose speedup/size components to more closely align with legacy PM

Overall I like this approach.

llvm/lib/Passes/PassBuilder.cpp
247–264

Nit, it would be good to document the constant parameters, e.g. {/*SpeedLevel*/0, /*SizeLevel*/0}

414

Nit, all similar checks below are Level.getSpeedupLevel() > 1, make this one consistent.

494–495

This results in a behavior, change, right? I.e. we used to inadvertently get the O3 threshold for full unrolling with Oz/Os but no longer will. If so, make sure you note this in the patch summary. Also add a test.

980

This one and the loop unrolling pass below will also get a change in behavior for Os/Oz, correct? That seems reasonable, but needs to be noted in summary and tested.

mtrofin updated this revision to Diff 238352.Jan 15 2020, 1:20 PM
mtrofin marked 4 inline comments as done.

Incorporated feedback:

  • tests
  • updated patch description
mtrofin edited the summary of this revision. (Show Details)Jan 15 2020, 1:27 PM
tejohnson accepted this revision.Jan 15 2020, 10:01 PM

LGTM

One thing to consider changing/removing in the summary is this comment:
"For example, (enum) "Level > 1" captures not only O2 and O3, but also Os, and Oz."
since that is actually correct (Os/Oz should be included in Level>1 as they are O2).

This revision is now accepted and ready to land.Jan 15 2020, 10:01 PM
mtrofin edited the summary of this revision. (Show Details)Jan 16 2020, 8:53 AM
This revision was automatically updated to reflect the committed changes.