Bug 17641 - [x86-64] Convert load to lea
Summary: [x86-64] Convert load to lea
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-24 16:01 IST by H.J. Lu
Modified: 2015-04-06 09:39 IST (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2014-11-24 16:01:33 IST
For x86-64, gold should convert

   mov foo@GOTPCREL(%rip), %reg

to

   lea foo(%rip), %reg

if foo is a local symbol, like ld:

[hjl@gnu-6 lea-4]$ cat lea2.s
	.text
	.type	foo, @function
foo:
	ret
	.size	foo, .-foo
	.text
	.globl	bar
	.type	bar, @function
bar:
	movq	foo@GOTPCREL(%rip), %rax
	.size	bar, .-bar
[hjl@gnu-6 lea-4]$ gcc -c lea2.s
[hjl@gnu-6 lea-4]$ ld -shared lea2.o
[hjl@gnu-6 lea-4]$ objdump -dw a.out 

a.out:     file format elf64-x86-64


Disassembly of section .text:

00000000000001c5 <foo>:
 1c5:	c3                   	retq   

00000000000001c6 <bar>:
 1c6:	48 8d 05 f8 ff ff ff 	lea    -0x8(%rip),%rax        # 1c5 <foo>
[hjl@gnu-6 lea-4]$
Comment 1 cvs-commit@gcc.gnu.org 2015-04-06 09:39:32 IST
The master branch has been updated by Ilya Tocar <tocarip@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1fa29f10602cd0ab395e0f83c9d87ab160b0df8a

commit 1fa29f10602cd0ab395e0f83c9d87ab160b0df8a
Author: Ilya Tocar <ilya.tocar@intel.com>
Date:   Mon Apr 6 12:37:34 2015 +0300

    [Gold,x86_64] Convert mov foo@GOTPCREL(%rip), %reg to lea foo(%rip), %reg
    
    2015-04-06  Ilya Tocar  <ilya.tocar@intel.com>
    
    	PR gold/17641
    	* x86_64.cc (Target_x86_64::can_convert_mov_to_lea): New.
    	(Target_x86_64::Scan::local): Don't create GOT entry, when we
    	can convert mov to lea.
    	(Target_x86_64::Scan::global): Ditto.
    	(Target_x86_64::Relocate::relocate): Convert mov foo@GOTPCREL(%rip),
    	%reg to lea foo(%rip), %reg if possible.
    	* testsuite/Makefile.am (x86_64_mov_to_lea): New test.
    	* testsuite/x86_64_mov_to_lea1.s: New.
    	* testsuite/x86_64_mov_to_lea2.s: Ditto.
    	* testsuite/x86_64_mov_to_lea3.s: Ditto.
    	* testsuite/x86_64_mov_to_lea4.s: Ditto.
    	* testsuite/x86_64_mov_to_lea.sh: Ditto.
    ---