[all-commits] [llvm/llvm-project] eac3e5: [X86] Do not emit JCC to __x86_indirect_thunk

João Moreira via All-commits all-commits at lists.llvm.org
Thu Oct 6 11:09:43 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: eac3e5c3fb7c121158fc4ae5117e6acb7fb5220e
      https://github.com/llvm/llvm-project/commit/eac3e5c3fb7c121158fc4ae5117e6acb7fb5220e
  Author: Joao Moreira <joao.moreira at intel.com>
  Date:   2022-10-06 (Thu, 06 Oct 2022)

  Changed paths:
    M llvm/lib/Target/X86/X86InstrInfo.cpp
    A llvm/test/CodeGen/X86/jcc-indirect-thunk-kernel.ll

  Log Message:
  -----------
  [X86] Do not emit JCC to __x86_indirect_thunk

Clang may optimize conditional tailcall blocks with the following layout:

cmp <condition>
je  tailcall_target
ret

When retpoline is in place, indirect calls are converted into direct calls to a retpoline thunk. When these indirect calls are tail calls, they may be subject to the above described optimization (there is no indirect JCC, but since now the jump is direct it can be made conditional). The above layout is non-ideal for the Linux kernel scenario because the branches into thunks may be patched back into indirect branches during runtime depending on the underlying CPU features, what would not be feasible if the binary is emitted with the optimized layout above.

Thus, prevent clang from emitting this it if CodeModel is Kernel.

Feature request from the respective kernel mailing list: https://lore.kernel.org/llvm/Yv3uI%2FMoJVctmBCh@worktop.programming.kicks-ass.net/

Reviewed By: nickdesaulniers, pengfei

Differential Revision: https://reviews.llvm.org/D134915




More information about the All-commits mailing list