public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/46888] New: missed optimization of zero_extract with constant inputs
@ 2010-12-10 16:59 ams at gcc dot gnu.org
2010-12-10 17:02 ` [Bug rtl-optimization/46888] " ams at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: ams at gcc dot gnu.org @ 2010-12-10 16:59 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46888
Summary: missed optimization of zero_extract with constant
inputs
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: ams@gcc.gnu.org
The compiler fails to do constant folding for bit fields, at least on ARM
targets, and instead builds the constant at run time.
Test case:
struct bits
{
unsigned a:5;
unsigned b:5;
unsigned c:5;
unsigned d:5;
};
struct bits
f (unsigned int a)
{
struct bits bits = {0,0,0,0};
bits.a = 1;
bits.b = 2;
bits.c = 3;
bits.d = a;
return bits;
}
Output, compiled for ARM with "-O2 -mcpu=cortex-a8 -mthumb":
movs r2, #1
movs r3, #0
bfi r3, r2, #0, #5
movs r2, #2
bfi r3, r2, #5, #5
movs r2, #3
bfi r3, r2, #10, #5
bfi r3, r0, #15, #5
mov r0, r3
bx lr
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/46888] missed optimization of zero_extract with constant inputs
2010-12-10 16:59 [Bug rtl-optimization/46888] New: missed optimization of zero_extract with constant inputs ams at gcc dot gnu.org
@ 2010-12-10 17:02 ` ams at gcc dot gnu.org
2010-12-10 19:42 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: ams at gcc dot gnu.org @ 2010-12-10 17:02 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46888
--- Comment #1 from Andrew Stubbs <ams at gcc dot gnu.org> 2010-12-10 17:02:05 UTC ---
Two different patches have been posted to fix this:
http://gcc.gnu.org/ml/gcc-patches/2010-12/msg00778.html
http://gcc.gnu.org/ml/gcc-patches/2010-12/msg00784.html
One, or both should be applied to GCC 4.7, when the time comes.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/46888] missed optimization of zero_extract with constant inputs
2010-12-10 16:59 [Bug rtl-optimization/46888] New: missed optimization of zero_extract with constant inputs ams at gcc dot gnu.org
2010-12-10 17:02 ` [Bug rtl-optimization/46888] " ams at gcc dot gnu.org
@ 2010-12-10 19:42 ` pinskia at gcc dot gnu.org
2010-12-13 21:37 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-12-10 19:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46888
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Status|UNCONFIRMED |NEW
Last reconfirmed| |2010.12.10 19:42:11
Version|unknown |4.6.0
Ever Confirmed|0 |1
Severity|normal |enhancement
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-12-10 19:42:11 UTC ---
Here is a simpler example. Take:
struct b
{
int t;
int tt;
};
union a
{
long long t;
struct b b;
};
long long f(int i, int t)
{
long long ii = ((long long)i) << 32;
union a a;
a.t = 0;
a.b.t = i;
a.b.tt = t;
return a.t;
}
--- CUT ---
For MIPS64r2 (both n64 and n32):
move $2,$0
dins $2,$4,32,32
j $31
dins $2,$5,0,32
--- CUT ---
is produced but the first two instructions can really be done as one shift:
dsll $2,$4,32
j $31
dins $2,$5,0,32
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/46888] missed optimization of zero_extract with constant inputs
2010-12-10 16:59 [Bug rtl-optimization/46888] New: missed optimization of zero_extract with constant inputs ams at gcc dot gnu.org
2010-12-10 17:02 ` [Bug rtl-optimization/46888] " ams at gcc dot gnu.org
2010-12-10 19:42 ` pinskia at gcc dot gnu.org
@ 2010-12-13 21:37 ` pinskia at gcc dot gnu.org
2012-10-12 8:08 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-12-13 21:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46888
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-12-13 21:37:37 UTC ---
(In reply to comment #1)
> Two different patches have been posted to fix this:
>
> http://gcc.gnu.org/ml/gcc-patches/2010-12/msg00778.html
>
> http://gcc.gnu.org/ml/gcc-patches/2010-12/msg00784.html
The testcase in comment #2 is not optimized with the CSE patch but is with the
combine patch.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/46888] missed optimization of zero_extract with constant inputs
2010-12-10 16:59 [Bug rtl-optimization/46888] New: missed optimization of zero_extract with constant inputs ams at gcc dot gnu.org
` (2 preceding siblings ...)
2010-12-13 21:37 ` pinskia at gcc dot gnu.org
@ 2012-10-12 8:08 ` pinskia at gcc dot gnu.org
2012-10-12 8:23 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-10-12 8:08 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46888
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
AssignedTo|unassigned at gcc dot |pinskia at gcc dot gnu.org
|gnu.org |
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-10-12 08:07:49 UTC ---
Created attachment 28428
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28428
A third patch
Here is a third patch which improves the code a different way, one which seems
better as combine.c already had the code which is supposed to do the combining
of:
(set (x) (const))
(set (zero_extract (x a b) (const))
But it forgot that x can be a non subreg if we are using a zero extract.
Also it is easy add the case where the second set does not have a const there
and optimize it to a shift followed by an and which gets my testcase too.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/46888] missed optimization of zero_extract with constant inputs
2010-12-10 16:59 [Bug rtl-optimization/46888] New: missed optimization of zero_extract with constant inputs ams at gcc dot gnu.org
` (3 preceding siblings ...)
2012-10-12 8:08 ` pinskia at gcc dot gnu.org
@ 2012-10-12 8:23 ` pinskia at gcc dot gnu.org
2012-10-12 8:49 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-10-12 8:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46888
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-10-12 08:23:35 UTC ---
It actually does not work for the arm case but it can be improved to work for
it which I am doing now.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/46888] missed optimization of zero_extract with constant inputs
2010-12-10 16:59 [Bug rtl-optimization/46888] New: missed optimization of zero_extract with constant inputs ams at gcc dot gnu.org
` (4 preceding siblings ...)
2012-10-12 8:23 ` pinskia at gcc dot gnu.org
@ 2012-10-12 8:49 ` pinskia at gcc dot gnu.org
2012-10-12 8:51 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-10-12 8:49 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46888
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #28428|0 |1
is obsolete| |
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-10-12 08:49:35 UTC ---
Created attachment 28431
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28431
New patch
Still does not fix the ARM case but similar thing can be done for the three
combine case. It does fix the mips case which I was looking into; though
really there should be only one insert and no shift.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/46888] missed optimization of zero_extract with constant inputs
2010-12-10 16:59 [Bug rtl-optimization/46888] New: missed optimization of zero_extract with constant inputs ams at gcc dot gnu.org
` (5 preceding siblings ...)
2012-10-12 8:49 ` pinskia at gcc dot gnu.org
@ 2012-10-12 8:51 ` pinskia at gcc dot gnu.org
2012-11-13 1:19 ` pinskia at gcc dot gnu.org
2022-12-01 0:02 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-10-12 8:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46888
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-10-12 08:50:55 UTC ---
Oh with my current patch, we are able to remove at least one bfi, the first
one.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/46888] missed optimization of zero_extract with constant inputs
2010-12-10 16:59 [Bug rtl-optimization/46888] New: missed optimization of zero_extract with constant inputs ams at gcc dot gnu.org
` (6 preceding siblings ...)
2012-10-12 8:51 ` pinskia at gcc dot gnu.org
@ 2012-11-13 1:19 ` pinskia at gcc dot gnu.org
2022-12-01 0:02 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-11-13 1:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46888
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-11-13 01:18:52 UTC ---
http://gcc.gnu.org/ml/gcc-patches/2012-11/msg00952.html
Will improve the testcase at the tree level for little-endian:
_4 = (unsigned char) a_3(D);
_5 = (<unnamed-unsigned:5>) _4;
BIT_FIELD_REF <D.1727, 10, 0> = 65;
D.1727.c = 3;
D.1727.d = _5;
return D.1727;
And will fix it on big-endian:
D.1354_2 = (unsigned char) a_1(D);
D.1355_3 = (<unnamed-unsigned:5>) D.1354_2;
BIT_FIELD_REF <D.1356, 15, 0> = 1091;
D.1356.d = D.1355_3;
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/46888] missed optimization of zero_extract with constant inputs
2010-12-10 16:59 [Bug rtl-optimization/46888] New: missed optimization of zero_extract with constant inputs ams at gcc dot gnu.org
` (7 preceding siblings ...)
2012-11-13 1:19 ` pinskia at gcc dot gnu.org
@ 2022-12-01 0:02 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-01 0:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46888
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Target Milestone|--- |10.0
Resolution|--- |FIXED
--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed fully in GCC 10+:
movw r3, #3137
bfi r3, r0, #15, #5
mov r0, r3
bx lr
Had also improved in GCC 8:
movw r2, #3137
movs r3, #0
bfi r3, r2, #0, #16
bfi r3, r0, #15, #5
mov r0, r3
bx lr
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-12-01 0:02 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-10 16:59 [Bug rtl-optimization/46888] New: missed optimization of zero_extract with constant inputs ams at gcc dot gnu.org
2010-12-10 17:02 ` [Bug rtl-optimization/46888] " ams at gcc dot gnu.org
2010-12-10 19:42 ` pinskia at gcc dot gnu.org
2010-12-13 21:37 ` pinskia at gcc dot gnu.org
2012-10-12 8:08 ` pinskia at gcc dot gnu.org
2012-10-12 8:23 ` pinskia at gcc dot gnu.org
2012-10-12 8:49 ` pinskia at gcc dot gnu.org
2012-10-12 8:51 ` pinskia at gcc dot gnu.org
2012-11-13 1:19 ` pinskia at gcc dot gnu.org
2022-12-01 0:02 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).