[clang] Workaround for MSVC ARM64 build performance regression (PR #65215)

Alexander Smarus via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 3 14:52:25 PDT 2023


================
@@ -30,6 +30,15 @@ set(LLVM_LINK_COMPONENTS
   TransformUtils
   )
 
+# Workaround for MSVC ARM64 performance regression: disable all optimizations (/Od)
+# and then enable back all /O2 options except one.
+if(NOT CMAKE_BUILD_TYPE MATCHES Debug 
+    AND MSVC 
+    AND MSVC_VERSION VERSION_GREATER_EQUAL 1932
+    AND CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64")
+  set_source_files_properties(CGBuiltin.cpp PROPERTIES COMPILE_FLAGS "/Od /Gw /Oi /Oy /Gy /Ob2 /Ot /GF")
----------------
lxbndr wrote:

Thanks for the review! I think I have to elaborate a little (and I apologize for not making this clear enough in the PR description). We're not going to just throw a bunch of optimization flags, of course.

The flag I actually intend to alter is `/O2`. According to the [reference](https://learn.microsoft.com/en-us/cpp/build/reference/o1-o2-minimize-size-maximize-speed?view=msvc-170), `/O2` is the equivalent of `/Og /Oi /Ot /Oy /Ob2 /GF /Gy` (I even see this in the compiler frontend invocation). I want to suppress the `/Og` and leave others in effect. This is done by adding `/Od` first (which cancels all `/O2` flags), and then adding "O2-minus-Og" flags back. Probably, the `/Gw` flag is the only unnecessary flag here, as it is not part of the `/O...` set (and it is not affected by `/Od` either).

It is also worth to mention that `set_source_files_properties` does not override flag set. It appends specified flags to other configured flags. That's why I had to use `/Od` to cancel already existing `/O2`.

I fully understand the intention to not break existing configuration. And I think I see how this can be improved. Instead of assuming all non-debug builds have optimizations enabled, we should seek for `/O2`/`/O1` flags directly, and adjust resulting flag set according to each case. @tru WDYT? Does this sound better?

https://github.com/llvm/llvm-project/pull/65215


More information about the cfe-commits mailing list