[all-commits] [llvm/llvm-project] e1e183: [CodeGen] Inline stack guard check on Windows (#13...

Omair Javaid via All-commits all-commits at lists.llvm.org
Thu Jun 12 07:39:03 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e1e1836bbd70e4f30bd0be97b9d81eabfd6b45c8
      https://github.com/llvm/llvm-project/commit/e1e1836bbd70e4f30bd0be97b9d81eabfd6b45c8
  Author: Omair Javaid <omair.javaid at linaro.org>
  Date:   2025-06-12 (Thu, 12 Jun 2025)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
    M llvm/lib/Target/X86/CMakeLists.txt
    M llvm/lib/Target/X86/X86.h
    M llvm/lib/Target/X86/X86TargetMachine.cpp
    R llvm/lib/Target/X86/X86WinFixupBufferSecurityCheck.cpp
    M llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stack-protector-windows.ll
    M llvm/test/CodeGen/X86/opt-pipeline.ll
    A llvm/test/CodeGen/X86/stack-protector-msvc-oz.ll
    M llvm/test/CodeGen/X86/stack-protector-msvc.ll
    M llvm/test/CodeGen/X86/tailcc-ssp.ll
    M llvm/test/DebugInfo/COFF/fpo-stack-protect.ll

  Log Message:
  -----------
  [CodeGen] Inline stack guard check on Windows (#136290)

This patch optimizes the Windows security cookie check mechanism by
moving the comparison inline and only calling __security_check_cookie
when the check fails. This reduces the overhead of making a DLL call 
for every function return.

Previously, we implemented this optimization through a machine pass
(X86WinFixupBufferSecurityCheckPass) in PR #95904 submitted by
@mahesh-attarde. We have reverted that pass in favor of this new 
approach. Also we have abandoned the AArch64 specific implementation 
of same pass in PR #121938 in favor of this more general solution.

The old machine instruction pass approach:
- Scanned the generated code to find __security_check_cookie calls
- Modified these calls by splitting basic blocks
- Added comparison logic and conditional branching
- Required complex block management and live register computation

The new approach:
- Implements the same optimization during instruction selection
- Directly emits the comparison and conditional branching
- No need for post-processing or basic block manipulation
- Disables optimization at -Oz.

Thanks @tamaspetz, @efriedma-quic and @arsenm for their help.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list