[all-commits] [llvm/llvm-project] 8afd83: ms inline asm: recognize case-insensitive JMP and ...

Fangrui Song via All-commits all-commits at lists.llvm.org
Fri May 5 15:32:47 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8afd831b456a46677e638cdf00dd649fbd5ca0a1
      https://github.com/llvm/llvm-project/commit/8afd831b456a46677e638cdf00dd649fbd5ca0a1
  Author: Fangrui Song <i at maskray.me>
  Date:   2023-05-05 (Fri, 05 May 2023)

  Changed paths:
    M clang/test/CodeGen/ms-inline-asm-functions.c
    M llvm/include/llvm/CodeGen/TargetLowering.h
    M llvm/lib/Target/X86/X86ISelLowering.cpp
    M llvm/test/CodeGen/X86/inline-asm-function-call-pic.ll

  Log Message:
  -----------
  ms inline asm: recognize case-insensitive JMP and CALL as TargetLowering::C_Address

In a `__asm` block, a symbol reference is usually a memory constraint
(indirect TargetLowering::C_Memory) [LOOP]. CALL and JUMP instructions are special
that `__asm call k` can be an address constraint, if `k` is a function.

Clang always gives us indirect TargetLowering::C_Memory and need to convert it
to direct TargetLowering::C_Address. D133914 implements this conversion, but
does not consider JMP or case-insensitive CALL. This patch implements the missing
cases, so that `__asm jmp k` (`jmp ${0:P}`) will correctly lower to `jmp _k`
instead of `jmp dword ptr [_k]`.

(`__asm call k` lowered to `call dword ptr ${0:P}` and is fixed by D149695 to
lower to `call ${0:P}` instead.)

[LOOP]: Some instructions like LOOP{,E,NE} and Jcc always use an address
constraint (`loop _k` instead of `loop dword ptr [_k]`).

After this patch and D149579, all the following cases will be correct.
```
int k(int);
int (*kptr)(int);
...
__asm call k; // correct without this patch
__asm CALL k; // correct, but needs this patch to be compatible with D149579
__asm jmp k;  // correct, but needs this patch to be compatible with D149579
__asm call kptr; // will be fixed by D149579.  "Broken case" in clang/test/CodeGen/ms-inline-asm-functions.c
__asm jmp kptr;  // will be fixed by this patch and D149579
```

Reviewed By: pengfei

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




More information about the All-commits mailing list