LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1103 - %rsp emitted as an index register
Summary: %rsp emitted as an index register
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: X86 (show other bugs)
Version: 1.9
Hardware: PC Linux
: P normal
Assignee: Chris Lattner
URL:
Keywords: compile-fail
Depends on:
Blocks:
 
Reported: 2007-01-10 11:47 PST by Dan Gohman
Modified: 2010-02-22 12:51 PST (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments
test case (14.21 KB, text/plain)
2007-01-10 11:50 PST, Dan Gohman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Gohman 2007-01-10 11:47:03 PST
The x86 backend allows %rsp to be used as an index register in an address
operand. Some assemblers accept this and automatically rewrite it so that %rsp
is the base register to make it legal, but some don't, including GAS.
Comment 1 Dan Gohman 2007-01-10 11:50:30 PST
Created attachment 553 [details]
test case

Compile with llc -march=x86-64 -sched=none and look for ',%rsp)' in the output.
Comment 2 Chris Lattner 2007-01-13 17:28:42 PST
To clarify, you're saying that:
leaq 16(%r10,%rsp), %r10

should be:

leaq 16(%rsp,%r10), %r10

?
Comment 3 Chris Lattner 2007-01-13 17:33:16 PST
okay, right.  The official syntax is:
  section:disp(base, index, scale)
Comment 4 Chris Lattner 2007-01-13 17:51:09 PST
This looks like a register coallescing issue.  llc -print-machineinstrs shows this after isel:

        %reg1165 = CMOVS64rr %reg1032, %reg1163
        %reg1038 = SUB32rr %reg1025, %reg1024
        %reg1034 = MOV64rr %RSP
...
        %reg1037 = LEA64r %reg1166, 1, %reg1034, 16
        %reg1036 = LEA64r %reg1164, 1, %reg1034, 16

When reg1034 is coallesced with RSP, we get the problem.
Comment 5 Chris Lattner 2007-01-13 18:14:27 PST
The most straight-forward way to fix this is in the asmprinter.  Addressed with this patch:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070108/042639.html

Testcase here:
Regression/CodeGen/X86/2007-01-13-StackPtrIndex.ll

-Chris