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

            Bug ID: 47447
           Summary: bad and questionable codegen for inline asm returning
                    a value in a fixed register
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: RISC-V
          Assignee: unassignedb...@nondot.org
          Reporter: sor...@fastmail.com
                CC: a...@lowrisc.org, llvm-bugs@lists.llvm.org

__builtin_thread_pointer() is not supported on released versions of risc-v gcc
or clang, so I looked for alternatives that would generate the same code.  I
tried:

void *get_tp() {
    register void *tp asm("tp");
    asm("" : "=r"(tp));
    return tp;
}

define i8* @get_tp() {
  %1 = tail call i8* asm "", "={x4}"()
  ret i8* %1
}

(https://gcc.godbolt.org/z/GP5ab4)

This works fine on released gcc (can even fold into subsequent memory accesses
which become tp-relative) but llvm generates a superfluous stack frame as
though tp were a call-saved register.  Since tp is a fixed register, I don't
think llvm is _allowed_ to insert saves and restores for it; the asm might be
erroneous, I am not sure of the intended semantics, but if it is accepted it
should be accepted without generating a stack frame.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to