[llvm-bugs] [Bug 43449] New: Under -O0, function with preserve_most calling convention fails to spill before calling functions with normal calling convention

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 25 10:59:38 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43449

            Bug ID: 43449
           Summary: Under -O0, function with preserve_most calling
                    convention fails to spill before calling functions
                    with normal calling convention
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: AArch64
          Assignee: unassignedbugs at nondot.org
          Reporter: scw at google.com
                CC: arnaud.degrandmaison at arm.com,
                    llvm-bugs at lists.llvm.org, peter.smith at linaro.org,
                    Ties.Stuij at arm.com

Created attachment 22572
  --> https://bugs.llvm.org/attachment.cgi?id=22572&action=edit
Reproducer

Though not formally documented, according to CSR_AArch64_RT_MostRegs in
AArch64CallingConvention.td, functions with preserve_most calling convention
preserves X9 through X15 in addition to the normal callee saved registers.

When a preserve_most function calls a function with normal calling convetion,
X9 through X15 thus have to be spilled. When optimization is disabled (-O0),
this is not done resulting in register values for the caller of preserve_most
functions getting overridden.

Reproducer (also attached):
====BEGIN REPRODUCER====
#include <assert.h>

void C() {
  asm volatile("mov x9, %0" : : "N"(0xdead) :"x9");
  asm volatile("mov x10, %0" : : "N"(0xdead) :"x10");
  asm volatile("mov x11, %0" : : "N"(0xdead) :"x11");
  asm volatile("mov x12, %0" : : "N"(0xdead) :"x12");
  asm volatile("mov x13, %0" : : "N"(0xdead) :"x13");
  asm volatile("mov x14, %0" : : "N"(0xdead) :"x14");
  asm volatile("mov x15, %0" : : "N"(0xdead) :"x15");
}

__attribute__((preserve_most))
void B() {
  C();
}

int main() {
  asm volatile("mov x9, %0" : : "N"(0xbeef) :"x9");
  asm volatile("mov x10, %0" : : "N"(0xbeef) :"x10");
  asm volatile("mov x11, %0" : : "N"(0xbeef) :"x11");
  asm volatile("mov x12, %0" : : "N"(0xbeef) :"x12");
  asm volatile("mov x13, %0" : : "N"(0xbeef) :"x13");
  asm volatile("mov x14, %0" : : "N"(0xbeef) :"x14");
  asm volatile("mov x15, %0" : : "N"(0xbeef) :"x15");

  B();

  int v;
  asm volatile("mov %w0, w9" : "=r"(v) : "r"(v) );
  assert(v == 0xbeef);
  return 0;
}
=====END REPRODUCER=====

Spilling is correctly generated with any level of optimization; function body
of C() is not needed for spilling to happen.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190925/2940b1e0/attachment.html>


More information about the llvm-bugs mailing list