Skip to content

Conversation

@MaskRay
Copy link
Member

@MaskRay MaskRay commented Sep 4, 2025

As noted in #156787

Created using spr 1.3.5-bogner
@llvmbot
Copy link
Member

llvmbot commented Sep 4, 2025

@llvm/pr-subscribers-backend-aarch64

Author: Fangrui Song (MaskRay)

Changes

As noted in #156787


Full diff: https://github.com/llvm/llvm-project/pull/156802.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64TargetMachine.cpp (+2-1)
diff --git a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
index e67bd5869ccd1..4650b2d0c8151 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -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());
       });
   if (getTargetTriple().isOSWindows())
     PB.registerPipelineEarlySimplificationEPCallback(

@madhur13490
Copy link
Contributor

I may be missing the broader context, while I do see the tagged issue. Is this purely because x86 does not run the pass? How do we decide what goes in O0?

.
Created using spr 1.3.5-bogner
@arsenm
Copy link
Contributor

arsenm commented Sep 4, 2025

I may be missing the broader context, while I do see the tagged issue. Is this purely because x86 does not run the pass? How do we decide what goes in O0?

As little was possible. The passes that are run at -O0 are maintaining historical semantic accidents, like always-inliner and should include no optimizations

I'd expect the pass builder to not call this hook in the first place, rather than requiring all targets to check this

@davemgreen
Copy link
Collaborator

Can we add a test that checks -mtriple aarch64 -print-pipeline-passes -O0? https://godbolt.org/z/Yf8ex6KMh

@davemgreen davemgreen requested a review from david-arm September 4, 2025 07:14
@arsenm arsenm requested a review from aeubanks September 4, 2025 07:21
[=](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.

Created using spr 1.3.5-bogner
Copy link
Member Author

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

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

Added llvm/test/CodeGen/AArch64/print-pipeline-passes.ll . CodeGen/AArch64 doesn't test this option before.

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.

Copy link
Collaborator

@davemgreen davemgreen left a comment

Choose a reason for hiding this comment

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

Thanks for adding the test. LGTM.

; RUN: opt -mtriple=aarch64 -S -passes='default<O2>' -print-pipeline-passes < %s | FileCheck %s

; CHECK: loop-idiom-vectorize
; O0-NOT: loop-idiom-vectorize
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was thinking of testing the entire pipeline for -O0 as it should be very small, and would prevent us from adding extra passes to it again. The other optimization levels are a bit long for that.

david-arm added a commit to david-arm/llvm-project that referenced this pull request Sep 5, 2025
Sometimes code depends upon the constant variables declared
in OptimizationLevel (e.g. see llvm#156802), which then requires
them to add a dependency on the Passes directory. Given that
code is much more likely to depend upon Support than Passes
I believe it makes sense to move OptimizationLevel to
Support. The Passes component already depends upon Support.
Created using spr 1.3.5-bogner
@MaskRay MaskRay merged commit 0d28b92 into main Sep 6, 2025
9 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/aarch64-dont-run-loop-idiom-vectorize-pass-in-the-o0-pipeline branch September 6, 2025 07:12
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 6, 2025

LLVM Buildbot has detected a new failure on builder lldb-aarch64-windows running on linaro-armv8-windows-msvc-05 while building llvm at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/141/builds/11337

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: tools/lldb-dap/breakpoint-assembly/TestDAP_breakpointAssembly.py (1192 of 2301)
UNSUPPORTED: lldb-api :: tools/lldb-dap/breakpoint-events/TestDAP_breakpointEvents.py (1193 of 2301)
UNSUPPORTED: lldb-api :: tools/lldb-dap/breakpoint/TestDAP_breakpointLocations.py (1194 of 2301)
UNSUPPORTED: lldb-api :: tools/lldb-dap/breakpoint/TestDAP_logpoints.py (1195 of 2301)
UNSUPPORTED: lldb-api :: tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py (1196 of 2301)
UNSUPPORTED: lldb-api :: tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py (1197 of 2301)
UNSUPPORTED: lldb-api :: tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py (1198 of 2301)
PASS: lldb-api :: tools/lldb-dap/cancel/TestDAP_cancel.py (1199 of 2301)
PASS: lldb-api :: tools/lldb-dap/commands/TestDAP_commands.py (1200 of 2301)
UNRESOLVED: lldb-api :: tools/lldb-dap/attach/TestDAP_attach.py (1201 of 2301)
******************** TEST 'lldb-api :: tools/lldb-dap/attach/TestDAP_attach.py' FAILED ********************
Script:
--
C:/Users/tcwg/scoop/apps/python/current/python.exe C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/llvm-project/lldb\test\API\dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./lib --env LLVM_INCLUDE_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/include --env LLVM_TOOLS_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin --arch aarch64 --build-dir C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex --lldb-module-cache-dir C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-lldb\lldb-api --clang-module-cache-dir C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-clang\lldb-api --executable C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/lldb.exe --compiler C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/clang.exe --dsymutil C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/dsymutil.exe --make C:/Users/tcwg/scoop/shims/make.exe --llvm-tools-dir C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin --lldb-obj-root C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/tools/lldb --lldb-libs-dir C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./lib --cmake-build-type Release --skip-category=watchpoint C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\API\tools\lldb-dap\attach -p TestDAP_attach.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 22.0.0git (https://github.com/llvm/llvm-project.git revision 0d28b925064e3b4e14555e137dd97651c1067b7c)
  clang revision 0d28b925064e3b4e14555e137dd97651c1067b7c
  llvm revision 0d28b925064e3b4e14555e137dd97651c1067b7c
Skipping the following test categories: ['watchpoint', 'libc++', 'libstdcxx', 'dwo', 'dsym', 'gmodules', 'debugserver', 'objc', 'fork', 'pexpect']


--
Command Output (stderr):
--
========= DEBUG ADAPTER PROTOCOL LOGS =========

1757144810.304636240 (stdio) --> {"command":"initialize","type":"request","arguments":{"adapterID":"lldb-native","clientID":"vscode","columnsStartAt1":true,"linesStartAt1":true,"locale":"en-us","pathFormat":"path","supportsRunInTerminalRequest":true,"supportsVariablePaging":true,"supportsVariableType":true,"supportsStartDebuggingRequest":true,"supportsProgressReporting":true,"$__lldb_sourceInitFile":false},"seq":1}

1757144810.304841995 (stdio) queued (command=initialize seq=1)

1757144810.316926479 (stdio) <-- {"body":{"$__lldb_version":"lldb version 22.0.0git (https://github.com/llvm/llvm-project.git revision 0d28b925064e3b4e14555e137dd97651c1067b7c)\n  clang revision 0d28b925064e3b4e14555e137dd97651c1067b7c\n  llvm revision 0d28b925064e3b4e14555e137dd97651c1067b7c","completionTriggerCharacters":["."," ","\t"],"exceptionBreakpointFilters":[{"description":"C++ Catch","filter":"cpp_catch","label":"C++ Catch","supportsCondition":true},{"description":"C++ Throw","filter":"cpp_throw","label":"C++ Throw","supportsCondition":true},{"description":"Objective-C Catch","filter":"objc_catch","label":"Objective-C Catch","supportsCondition":true},{"description":"Objective-C Throw","filter":"objc_throw","label":"Objective-C Throw","supportsCondition":true}],"supportTerminateDebuggee":true,"supportsBreakpointLocationsRequest":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsDisassembleRequest":true,"supportsEvaluateForHovers":true,"supportsExceptionFilterOptions":true,"supportsExceptionInfoRequest":true,"supportsFunctionBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsInstructionBreakpoints":true,"supportsLogPoints":true,"supportsModuleSymbolsRequest":true,"supportsModulesRequest":true,"supportsReadMemoryRequest":true,"supportsSetVariable":true,"supportsSteppingGranularity":true,"supportsValueFormattingOptions":true,"supportsWriteMemoryRequest":true},"command":"initialize","request_seq":1,"seq":0,"success":true,"type":"response"}

1757144810.317639112 (stdio) --> {"command":"attach","type":"request","arguments":{"program":"C:\\Users\\tcwg\\llvm-worker\\lldb-aarch64-windows\\build\\lldb-test-build.noindex\\tools\\lldb-dap\\attach\\TestDAP_attach.test_attach_command_process_failures\\0b05b926-2977-435e-87a3-fa6dbd5d2e00","initCommands":["settings clear --all","settings set symbols.enable-external-lookup false","settings set target.inherit-tcc true","settings set target.disable-aslr false","settings set target.detach-on-error false","settings set target.auto-apply-fixits false","settings set plugin.process.gdb-remote.packet-timeout 60","settings set symbols.clang-modules-cache-path \"C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-lldb\\lldb-api\"","settings set use-color false","settings set show-statusline false","settings set target.env-vars PATH="],"attachCommands":["script print(\"oops, forgot to attach to a process...\")"]},"seq":2}

1757144810.317708731 (stdio) queued (command=attach seq=2)

1757144810.318502903 (stdio) <-- {"body":{"category":"console","output":"Running initCommands:\n"},"event":"output","seq":0,"type":"event"}

1757144810.318553686 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings clear --all\n"},"event":"output","seq":0,"type":"event"}

1757144810.318585634 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set symbols.enable-external-lookup false\n"},"event":"output","seq":0,"type":"event"}

1757144810.318615675 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set target.inherit-tcc true\n"},"event":"output","seq":0,"type":"event"}

1757144810.318646431 (stdio) <-- {"body":{"category":"console","output":"(lldb) settings set target.disable-aslr false\n"},"event":"output","seq":0,"type":"event"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants