Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ void AArch64TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {

PB.registerLateLoopOptimizationsEPCallback(
[=](LoopPassManager &LPM, OptimizationLevel Level) {
LPM.addPass(LoopIdiomVectorizePass());
if (Level != OptimizationLevel::O0)
LPM.addPass(LoopIdiomVectorizePass());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these are invoked from buildO0DefaultPipeline which is strange, but then we also call invokeCGSCCOptimizerLateEPCallbacks, invokeLoopOptimizerEndEPCallbacks and invokeScalarOptimizerLateEPCallbacks from there too.

Perhaps better to guard the entire register function with the check, i.e.

  if (Level != OptimizationLevel::O0) {
    PB.registerLateLoopOptimizationsEPCallback(
        [=](LoopPassManager &LPM, OptimizationLevel Level) {
          LPM.addPass(LoopIdiomVectorizePass());
        });
  }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Level variable is an argument to the lambda it doesn't exist outside.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that's true, but I just thought it must be easy enough to find out what the optimisation level is and just not bothering calling registerLateLoopOptimizationsEPCallback at all. I guess it's fine at the moment because we're only registering one pass.

});
if (getTargetTriple().isOSWindows())
PB.registerPipelineEarlySimplificationEPCallback(
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/AArch64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ add_llvm_target(AArch64CodeGen
Core
GlobalISel
MC
Passes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this adding a new dependency?

Copy link
Member Author

@MaskRay MaskRay Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OptimizationLevel::O0 is a variable defined by Passes .cpp file. This is needed to avoid an undefined symbol linker error. I don't find a way to move the definition from .cpp to .h as a static constexpr variable.

The class OptimizationLevel is not considered a literal class before }. Declararing a member constexpr variable of the same type is not allowed.

struct A {
    int a, b;
    constexpr A(int a, int b) : a(a), b(b) {}
    
    static constexpr A default_value{0, 0};
};

// would cause
error: constexpr variable cannot have non-literal type 'const A'
    6 |   static constexpr inline A default_value{0, 0};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it does seem a shame to add the extra dependency. Does #157057 help?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, it looks like #157057 may not go anywhere, so don't let me hold up this PR.

Scalar
SelectionDAG
Support
Expand Down