[LLVMbugs] [Bug 20978] New: Inline assembly handling of adding negative numbers not as smart as gcc's

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Sep 17 10:34:44 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20978

            Bug ID: 20978
           Summary: Inline assembly handling of adding negative numbers
                    not as smart as gcc's
           Product: clang
           Version: trunk
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: bero at lindev.ch
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 13047
  --> http://llvm.org/bugs/attachment.cgi?id=13047&action=edit
test case

Compiling the attached test case with clang -target aarch64-linux-android -O2
-c test.c -o test.o results in

test.c:5:3: error: expected compatible register, symbol or integer in range
      [0, 4095]
                "add %w[result], %w[result], %w[num]    \n\t"
                ^
<inline asm>:1:14: note: instantiated into assembly here
        add w0, w0, #4294967295 
                    ^
1 error generated.


This is not unreasonable, given add doesn't take a negative number and the
constraint is set to IJr (J --> valid for sub --> doesn't catch the -1).

However, gcc (tested Linaro 4.9-2014.09, but it's probably the same for older
gcc, the code has compiled with gcc forever) compiles the code just fine,
recognizes what it meant to do, and generates
        sub w0, w0, #1

It would be nice if clang could match - better compatibility and the generated
code is better than what could be achieved by the workarounds (changing the
constraint to Ir or adding an if clause for add vs. sub).

-- 
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/20140917/91c652ec/attachment.html>


More information about the llvm-bugs mailing list