Skip to content

Conversation

@topperc
Copy link
Collaborator

@topperc topperc commented Jan 8, 2025

Every call should have regmask operand to indicate what registers are preserved or clobbered by the call. VirtRegRewriter uses this to tell MachineRegisterInfo what registers are clobbered by a function. If the mask isn't present the registers potentially clobbered by a tail called function aren't counted. I have checked ARM, AArch64, and X86 and they all have a regmask operand on their tail calls.

I believe this fixes an issue I'm seeing with IPRA.

Every call should have regmask operand to indicate what is preserved.
VirtRegRewriter uses this to tell MachineRegisterInfo what registers
are used by a function. If the mask isn't present the registers
potentially clobbered by a tail called function aren't counted. I
have checked ARM, AArch64, and X86 and they all have a regmask
operand on their tail calls.

I believe thie fixes an issue I'm seeing with IPRA.
@llvmbot
Copy link
Member

llvmbot commented Jan 8, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Craig Topper (topperc)

Changes

Every call should have regmask operand to indicate what registers are preserved or clobbered by the call. VirtRegRewriter uses this to tell MachineRegisterInfo what registers are clobbered by a function. If the mask isn't present the registers potentially clobbered by a tail called function aren't counted. I have checked ARM, AArch64, and X86 and they all have a regmask operand on their tail calls.

I believe this fixes an issue I'm seeing with IPRA.


Full diff: https://github.com/llvm/llvm-project/pull/122181.diff

3 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+5-7)
  • (modified) llvm/test/CodeGen/RISCV/kcfi-isel-mir.ll (+1-1)
  • (modified) llvm/test/CodeGen/RISCV/kcfi-mir.ll (+1-1)
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 2eeca45ac414bd..6c58989b1afb4c 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -20273,13 +20273,11 @@ SDValue RISCVTargetLowering::LowerCall(CallLoweringInfo &CLI,
   for (auto &Reg : RegsToPass)
     Ops.push_back(DAG.getRegister(Reg.first, Reg.second.getValueType()));
 
-  if (!IsTailCall) {
-    // Add a register mask operand representing the call-preserved registers.
-    const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
-    const uint32_t *Mask = TRI->getCallPreservedMask(MF, CallConv);
-    assert(Mask && "Missing call preserved mask for calling convention");
-    Ops.push_back(DAG.getRegisterMask(Mask));
-  }
+  // Add a register mask operand representing the call-preserved registers.
+  const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
+  const uint32_t *Mask = TRI->getCallPreservedMask(MF, CallConv);
+  assert(Mask && "Missing call preserved mask for calling convention");
+  Ops.push_back(DAG.getRegisterMask(Mask));
 
   // Glue the call to the argument copies, if any.
   if (Glue.getNode())
diff --git a/llvm/test/CodeGen/RISCV/kcfi-isel-mir.ll b/llvm/test/CodeGen/RISCV/kcfi-isel-mir.ll
index 4c47b5f741fa67..2c428cf4ac87c6 100644
--- a/llvm/test/CodeGen/RISCV/kcfi-isel-mir.ll
+++ b/llvm/test/CodeGen/RISCV/kcfi-isel-mir.ll
@@ -20,7 +20,7 @@ define void @f2(ptr noundef %x) #0 {
   ; CHECK-NEXT:   liveins: $x10
   ; CHECK-NEXT: {{  $}}
   ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gprtc = COPY $x10
-  ; CHECK-NEXT:   PseudoTAILIndirect [[COPY]], implicit $x2, cfi-type 12345678
+  ; CHECK-NEXT:   PseudoTAILIndirect [[COPY]], csr_ilp32_lp64, implicit $x2, cfi-type 12345678
   tail call void %x() [ "kcfi"(i32 12345678) ]
   ret void
 }
diff --git a/llvm/test/CodeGen/RISCV/kcfi-mir.ll b/llvm/test/CodeGen/RISCV/kcfi-mir.ll
index f9f383a35358c2..0c0d39a8bf87d3 100644
--- a/llvm/test/CodeGen/RISCV/kcfi-mir.ll
+++ b/llvm/test/CodeGen/RISCV/kcfi-mir.ll
@@ -30,7 +30,7 @@ define void @f2(ptr noundef %x) #0 {
   ; CHECK-NEXT: {{  $}}
   ; CHECK-NEXT:   BUNDLE implicit-def $x6, implicit-def $x6_w, implicit-def $x6_h, implicit-def $x7, implicit-def $x7_w, implicit-def $x7_h, implicit-def $x28, implicit-def $x28_w, implicit-def $x28_h, implicit-def $x29, implicit-def $x29_w, implicit-def $x29_h, implicit-def $x30, implicit-def $x30_w, implicit-def $x30_h, implicit-def $x31, implicit-def $x31_w, implicit-def $x31_h, implicit killed $x10, implicit $x2 {
   ; CHECK-NEXT:     KCFI_CHECK $x10, 12345678, implicit-def $x6, implicit-def $x7, implicit-def $x28, implicit-def $x29, implicit-def $x30, implicit-def $x31
-  ; CHECK-NEXT:     PseudoTAILIndirect killed $x10, implicit $x2
+  ; CHECK-NEXT:     PseudoTAILIndirect killed $x10, csr_ilp32_lp64, implicit $x2
   ; CHECK-NEXT:   }
   tail call void %x() [ "kcfi"(i32 12345678) ]
   ret void

Copy link
Collaborator

@preames preames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Spot checked the x86 and AArch64 code, this looks reasonable.

@topperc topperc merged commit b0f11df into llvm:main Jan 9, 2025
10 checks passed
@topperc topperc deleted the pr/tailcall-regmask branch January 9, 2025 00:19
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jan 9, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-libc-amdgpu-runtime running on omp-vega20-1 while building llvm at step 7 "Add check check-offload".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/11397

Here is the relevant piece of the build log for the reference
Step 7 (Add check check-offload) failure: 1200 seconds without output running [b'ninja', b'-j 32', b'check-offload'], attempting to kill
...
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug53727.cpp (986 of 999)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49779.cpp (987 of 999)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/test_libc.cpp (988 of 999)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug50022.cpp (989 of 999)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/wtime.c (990 of 999)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: offloading/bug49021.cpp (991 of 999)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: offloading/std_complex_arithmetic.cpp (992 of 999)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/complex_reduction.cpp (993 of 999)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49021.cpp (994 of 999)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/std_complex_arithmetic.cpp (995 of 999)
command timed out: 1200 seconds without output running [b'ninja', b'-j 32', b'check-offload'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1235.563819

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jan 9, 2025

LLVM Buildbot has detected a new failure on builder clang-debian-cpp20 running on clang-debian-cpp20 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/108/builds/7896

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: ExecutionEngine/JITLink/x86-64/COFF_addr32nb_reloc_neg_addend.test' FAILED ********************
Exit Code: 134

Command Output (stderr):
--
RUN: at line 1: /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/yaml2obj /vol/worker/clang-debian-cpp20/clang-debian-cpp20/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_addr32nb_reloc_neg_addend.test -o /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/test/ExecutionEngine/JITLink/x86-64/Output/COFF_addr32nb_reloc_neg_addend.test.tmp
+ /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/yaml2obj /vol/worker/clang-debian-cpp20/clang-debian-cpp20/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_addr32nb_reloc_neg_addend.test -o /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/test/ExecutionEngine/JITLink/x86-64/Output/COFF_addr32nb_reloc_neg_addend.test.tmp
RUN: at line 2: /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink -noexec -abs __ImageBase=0xfff00000  -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096  -check /vol/worker/clang-debian-cpp20/clang-debian-cpp20/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_addr32nb_reloc_neg_addend.test /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/test/ExecutionEngine/JITLink/x86-64/Output/COFF_addr32nb_reloc_neg_addend.test.tmp
+ /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink -noexec -abs __ImageBase=0xfff00000 -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 -check /vol/worker/clang-debian-cpp20/clang-debian-cpp20/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_addr32nb_reloc_neg_addend.test /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/test/ExecutionEngine/JITLink/x86-64/Output/COFF_addr32nb_reloc_neg_addend.test.tmp
llvm-jitlink error: Resource tracker 0x5c47b53dba30 became defunct
llvm-jitlink: /vol/worker/clang-debian-cpp20/clang-debian-cpp20/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/SymbolStringPool.h:285: llvm::orc::SymbolStringPool::~SymbolStringPool(): Assertion `Pool.empty() && "Dangling references at pool destruction time"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink -noexec -abs __ImageBase=0xfff00000 -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 -check /vol/worker/clang-debian-cpp20/clang-debian-cpp20/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_addr32nb_reloc_neg_addend.test /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/test/ExecutionEngine/JITLink/x86-64/Output/COFF_addr32nb_reloc_neg_addend.test.tmp
 #0 0x00005c47b1bd8e68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink+0xeade68)
 #1 0x00005c47b1bd695d llvm::sys::RunSignalHandlers() (/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink+0xeab95d)
 #2 0x00005c47b1bd9408 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007a825c636510 (/lib/x86_64-linux-gnu/libc.so.6+0x3c510)
 #4 0x00007a825c6840fc (/lib/x86_64-linux-gnu/libc.so.6+0x8a0fc)
 #5 0x00007a825c636472 raise (/lib/x86_64-linux-gnu/libc.so.6+0x3c472)
 #6 0x00007a825c6204b2 abort (/lib/x86_64-linux-gnu/libc.so.6+0x264b2)
 #7 0x00007a825c6203d5 (/lib/x86_64-linux-gnu/libc.so.6+0x263d5)
 #8 0x00007a825c62f3a2 (/lib/x86_64-linux-gnu/libc.so.6+0x353a2)
 #9 0x00005c47b1472fac (/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink+0x747fac)
#10 0x00005c47b1abbe07 llvm::orc::ExecutorProcessControl::~ExecutorProcessControl() (/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink+0xd90e07)
#11 0x00005c47b1abd54f llvm::orc::SelfExecutorProcessControl::~SelfExecutorProcessControl() (/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink+0xd9254f)
#12 0x00005c47b19ef2e8 llvm::orc::ExecutionSession::~ExecutionSession() (/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink+0xcc42e8)
#13 0x00005c47b144bedd llvm::Session::~Session() (/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink+0x720edd)
#14 0x00005c47b1456664 main (/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink+0x72b664)
#15 0x00007a825c6216ca (/lib/x86_64-linux-gnu/libc.so.6+0x276ca)
#16 0x00007a825c621785 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27785)
#17 0x00005c47b1444671 _start (/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink+0x719671)
/vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/test/ExecutionEngine/JITLink/x86-64/Output/COFF_addr32nb_reloc_neg_addend.test.script: line 2: 354723 Aborted                 /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/bin/llvm-jitlink -noexec -abs __ImageBase=0xfff00000 -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 -check /vol/worker/clang-debian-cpp20/clang-debian-cpp20/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_addr32nb_reloc_neg_addend.test /vol/worker/clang-debian-cpp20/clang-debian-cpp20/build/test/ExecutionEngine/JITLink/x86-64/Output/COFF_addr32nb_reloc_neg_addend.test.tmp

--

********************


@wangpc-pp
Copy link
Contributor

I believe this fixes an issue I'm seeing with IPRA.

Great! I checked that this can fix an issue I saw when I played around with IPRA as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants