[all-commits] [llvm/llvm-project] bb2844: [CodeGen][X86] Fix lowering of tailcalls when `-ms...

Alexandre Ganea via All-commits all-commits at lists.llvm.org
Mon Jan 22 11:19:20 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: bb28442c0b9790473363cbca2867630262358018
      https://github.com/llvm/llvm-project/commit/bb28442c0b9790473363cbca2867630262358018
  Author: Alexandre Ganea <37383324+aganea at users.noreply.github.com>
  Date:   2024-01-22 (Mon, 22 Jan 2024)

  Changed paths:
    M llvm/include/llvm/Support/TargetOpcodes.def
    M llvm/lib/CodeGen/PatchableFunction.cpp
    M llvm/lib/Target/X86/X86MCInstLower.cpp
    A llvm/test/CodeGen/X86/patchable-prologue-tailcall.ll
    M llvm/test/CodeGen/X86/patchable-prologue.ll

  Log Message:
  -----------
  [CodeGen][X86] Fix lowering of tailcalls when `-ms-hotpatch` is used (#77245)

Previously, tail jump pseudo-opcodes were skipped by the
`encodeInstruction()` call inside `X86AsmPrinter::LowerPATCHABLE_OP`.
This caused emission of a 2-byte NOP and dropping of the tail jump.

With this PR, we change `PATCHABLE_OP` to not wrap the first
`MachineInstr` anymore, but inserting itself before,
leaving the instruction unaltered. At lowering time in `X86AsmPrinter`,
we now "look ahead" for the next non-pseudo `MachineInstr` and
lower+encode it, to inspect its size. If the size is below what
`PATCHABLE_OP` expects, it inserts NOPs; otherwise it does nothing. That
way, now the first `MachineInstr` is always lowered as usual even if
`"patchable-function"="prologue-short-redirect"` is used.

Fixes https://github.com/llvm/llvm-project/issues/76879,
https://github.com/llvm/llvm-project/issues/76958 and
https://github.com/llvm/llvm-project/issues/59039




More information about the All-commits mailing list