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

            Bug ID: 45585
           Summary: Assembler operand constraints are ineffective with
                    global register variables
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C
          Assignee: unassignedclangb...@nondot.org
          Reporter: ubiz...@gmail.com
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@metafoo.co.uk

Following testcase:

--cut here--
register unsigned long current_stack_pointer asm("rsp");

void
foo (void)
{
  asm volatile ("# %0" :: "a" (current_stack_pointer));
}
--cut here--

compiles on x86 with -O2 to:

        #APP
        # %rsp
        #NO_APP

Please note that the asm uses input operand constraint "a" that would allow
only %rax register.

GCC gets this right and reloads %rsp to %rax:

        movq    %rsp, %rax
#APP
        # %rax
#NO_APP

If the constraint is changed to "r", which allows all general registers,
including %rsp, GCC generates

#APP
        # %rsp
#NO_APP

I'd like to argue that the compiler should reload the input argument, so that
the asm input operand constraint is always respected.

-- 
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