Bug 65326 - LRA missing a Thumb optimization.
Summary: LRA missing a Thumb optimization.
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.9.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2015-03-05 17:34 UTC by Matthew Wahab
Modified: 2015-05-07 11:20 UTC (History)
1 user (show)

See Also:
Host:
Target: arm
Build:
Known to work: 4.8.0, 4.8.1, 4.8.2, 4.9.0, 4.9.1, 4.9.2, 4.9.3
Known to fail: 5.0, 6.0
Last reconfirmed: 2015-04-22 00:00:00


Attachments
Testcase showing change in behaviour. (192 bytes, text/plain)
2015-03-05 17:34 UTC, Matthew Wahab
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Wahab 2015-03-05 17:34:14 UTC
Created attachment 34964 [details]
Testcase showing change in behaviour.

The ARM backend no longer supports -mno-lra so only the LRA is available. This
has also removed the Thumb mode optimiziation introduced in
https://gcc.gnu.org/ml/gcc-patches/2005-08/msg01140.html to fix PR 23436.

This turns sequences like
 	mov	r3, r9
	mov	r2, r10
	ldr	r0, [r3, r2]
into
	mov	r3, r9
	add	r3, r3, r10
	ldr	r0, [r3]
which saves a register.

Attached is a contrived test case. Compiling with gcc-4.9 with -mthumb -mno-lra 
(at -O1 and higher) produces the second (better) sequence. Compiling with
gcc-4.9 or gcc-trunk with -mthumb (at -O1 and higher) produces the first
sequence. The sequences appear after the 'nop'

gcc-4.9 is 
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20141119
(release) [ARM/embedded-4_9-branch revision 218278]

trunk is:
arm-none-eabi-gcc (unknown) 5.0.0 20150217 (experimental)
Comment 1 Renlin Li 2015-05-07 11:20:53 UTC
In this specific case, thumb_legitimize_address will generate ldr r0, [r9, r10] pattern(after IRA). However, this pattern only allows LO_REGS. During reload,  r9&r10 will be spilled into LO_REGS, that's where those two mov instructions come from.

(In reply to Matthew Wahab from comment #0)
> Created attachment 34964 [details]
> Testcase showing change in behaviour.
> 
> The ARM backend no longer supports -mno-lra so only the LRA is available.
> This
> has also removed the Thumb mode optimiziation introduced in
> https://gcc.gnu.org/ml/gcc-patches/2005-08/msg01140.html to fix PR 23436.
> 
> This turns sequences like
>  	mov	r3, r9
> 	mov	r2, r10
> 	ldr	r0, [r3, r2]
> into
> 	mov	r3, r9
> 	add	r3, r3, r10
> 	ldr	r0, [r3]
> which saves a register.
> 
> Attached is a contrived test case. Compiling with gcc-4.9 with -mthumb
> -mno-lra 
> (at -O1 and higher) produces the second (better) sequence. Compiling with
> gcc-4.9 or gcc-trunk with -mthumb (at -O1 and higher) produces the first
> sequence. The sequences appear after the 'nop'
> 
> gcc-4.9 is 
> arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20141119
> (release) [ARM/embedded-4_9-branch revision 218278]
> 
> trunk is:
> arm-none-eabi-gcc (unknown) 5.0.0 20150217 (experimental)