Bug 64134 - (vector float){0, 0, b, a} Uses stores when it does not need to
Summary: (vector float){0, 0, b, a} Uses stores when it does not need to
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: ---
Assignee: Alan Lawrence
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2014-12-01 05:24 UTC by Andrew Pinski
Modified: 2015-06-26 14:09 UTC (History)
0 users

See Also:
Host:
Target: aarch64
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-12-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2014-12-01 05:24:47 UTC
Take the following code:
#define vector __attribute__((vector_size(16)))

float a; float b;
vector float fb(void) { return (vector float){ 0,0,b,a};}

--- CUT ---
This produces:
fb:
	adrp	x1, b
	adrp	x0, a
	ldr	w1, [x1, #:lo12:b]
	fmov	s0, wzr
	ldr	w0, [x0, #:lo12:a]
	sub	sp, sp, #16
	stp	s0, s0, [sp]
	str	w1, [sp, 8]
	str	w0, [sp, 12]
	ldr	q0, [sp]
	add	sp, sp, 16
	ret


This is really horrible and should be done as:
fb:
	adrp	x0, a
	adrp	x1, b
	movi	v0.4s, 0
	ldr	s1, [x0, #:lo12:a]
	ldr	s2, [x1, #:lo12:b]
	ins	v0.s[3], v1.s[0]
	ins	v0.s[2], v2.s[0]
	ret
Comment 1 Andrew Pinski 2014-12-01 05:26:58 UTC
#define vector __attribute__((vector_size(16)))

float a; float b; float c; float d;
vector float fb(void) { return (vector float){ d,c,b,a};}


Is just as bad.  We need to ins more in the aarch64 back-end.
Comment 2 ktkachov 2014-12-01 09:55:58 UTC
Confirmed. CC'ing Alan, he might find this of interest
Comment 3 Alan Lawrence 2015-04-20 10:29:58 UTC
Author: alalaw01
Date: Mon Apr 20 10:29:26 2015
New Revision: 222229

URL: https://gcc.gnu.org/viewcvs?rev=222229&root=gcc&view=rev
Log:
[AArch64] PR/64134: Make aarch64_expand_vector_init use 'ins' more often

gcc/:

	PR target/64134
	* config/aarch64/aarch64.c (aarch64_expand_vector_init): Load constant
	and overwrite variable parts if <= 1/2 the elements are variable.

gcc/testsuite/:

	PR target/64134
	* gcc.target/aarch64/vec_init_1.c: New test.

Added:
    trunk/gcc/testsuite/gcc.target/aarch64/vec_init_1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/aarch64/aarch64.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Alan Lawrence 2015-06-26 14:09:34 UTC
Fixed by r222229.