[all-commits] [llvm/llvm-project] af6c43: [LoongArch] Allow %pc_lo12 relocs in JIRL's immedi...

WÁNG Xuěruì via All-commits all-commits at lists.llvm.org
Sun Jan 22 02:51:07 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: af6c43c8e99b0263d8050d2a85a0fbc5bc8b45ed
      https://github.com/llvm/llvm-project/commit/af6c43c8e99b0263d8050d2a85a0fbc5bc8b45ed
  Author: WANG Xuerui <git at xen0n.name>
  Date:   2023-01-22 (Sun, 22 Jan 2023)

  Changed paths:
    M llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp
    M llvm/test/MC/LoongArch/Relocations/relocations.s

  Log Message:
  -----------
  [LoongArch] Allow %pc_lo12 relocs in JIRL's immediate operand position

Currently, gcc-13 will generate such assembly when `-mcmodel=medium`,
which is ostensibly a dirty hack to allow bigger offsets for extern
function calls without having to add more reloc types. This is not the
best way to accomplish the original goal, but such usages will appear
soon and we have to support it anyway.

Example:

```c
extern int foo(int);

int bar(int x) {
    return foo(x + 123);
}
```

will produce the following (simplified) assembly when compiled with
`-O2 -mcmodel=medium`:

```
    .globl  bar
    .type   bar, @function
bar:
    .cfi_startproc
    addi.w  $r4,$r4,123
    pcalau12i   $r12,%pc_hi20(foo)
    jirl    $r0,$r12,%pc_lo12(foo)
    .cfi_endproc
```

Reviewed By: SixWeining, wangleiat, MaskRay, xry111

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




More information about the All-commits mailing list