public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/31261] New: Missed tree optimizations: (8 - (x & 7)) & 7
@ 2007-03-19 11:05 jakub at gcc dot gnu dot org
2007-03-19 11:17 ` [Bug tree-optimization/31261] " rguenth at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: jakub at gcc dot gnu dot org @ 2007-03-19 11:05 UTC (permalink / raw)
To: gcc-bugs
In 4.2 with -O2 -m32 -fomit-frame-pointer on x86_64:
unsigned int foo (unsigned int x)
{
return (8 - (x & 7)) & 7;
}
results in andl $7, reg; negl reg; andl $7, reg.
On 4.3 apparently some RTL optimization catches this, but it is still a missed
tree optimization, fold should be able to fold:
(cst - (x & cstmask)) & cstmask2 as
(cst & cstmask2) + (-x & cstmask2) if x is unsigned or if -INT_MIN wraps to
INT_MIN, both cstmask and cstmask2 are constants z^2-1 for some z and
(cstmask & cstmask2) == cstmask2.
BTW, even for
(8 + (x & 7)) & 7
the optimized dump contains:
(x & 7) + 8 & 7
for both 4.2/4.3 (no idea why 8 & 7 hasn't been simplified as 0).
--
Summary: Missed tree optimizations: (8 - (x & 7)) & 7
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jakub at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31261
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/31261] Missed tree optimizations: (8 - (x & 7)) & 7
2007-03-19 11:05 [Bug tree-optimization/31261] New: Missed tree optimizations: (8 - (x & 7)) & 7 jakub at gcc dot gnu dot org
@ 2007-03-19 11:17 ` rguenth at gcc dot gnu dot org
2007-03-19 11:19 ` rguenth at gcc dot gnu dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-03-19 11:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rguenth at gcc dot gnu dot org 2007-03-19 11:17 -------
(x & 7) + 8 & 7 is actually ((x & 7) + 8) & 7
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31261
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/31261] Missed tree optimizations: (8 - (x & 7)) & 7
2007-03-19 11:05 [Bug tree-optimization/31261] New: Missed tree optimizations: (8 - (x & 7)) & 7 jakub at gcc dot gnu dot org
2007-03-19 11:17 ` [Bug tree-optimization/31261] " rguenth at gcc dot gnu dot org
@ 2007-03-19 11:19 ` rguenth at gcc dot gnu dot org
2007-03-21 15:06 ` jakub at gcc dot gnu dot org
2007-03-21 18:28 ` trt at acm dot org
3 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-03-19 11:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2007-03-19 11:19 -------
You would need to enhance associate_trees () or the reassoc pass to fix this.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |missed-optimization, TREE
Last reconfirmed|0000-00-00 00:00:00 |2007-03-19 11:19:48
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31261
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/31261] Missed tree optimizations: (8 - (x & 7)) & 7
2007-03-19 11:05 [Bug tree-optimization/31261] New: Missed tree optimizations: (8 - (x & 7)) & 7 jakub at gcc dot gnu dot org
2007-03-19 11:17 ` [Bug tree-optimization/31261] " rguenth at gcc dot gnu dot org
2007-03-19 11:19 ` rguenth at gcc dot gnu dot org
@ 2007-03-21 15:06 ` jakub at gcc dot gnu dot org
2007-03-21 18:28 ` trt at acm dot org
3 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu dot org @ 2007-03-21 15:06 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from jakub at gcc dot gnu dot org 2007-03-21 15:05 -------
Created an attachment (id=13244)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13244&action=view)
gcc43-pr31261.patch
Patch I'm testing ATM.
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |jakub at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31261
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/31261] Missed tree optimizations: (8 - (x & 7)) & 7
2007-03-19 11:05 [Bug tree-optimization/31261] New: Missed tree optimizations: (8 - (x & 7)) & 7 jakub at gcc dot gnu dot org
` (2 preceding siblings ...)
2007-03-21 15:06 ` jakub at gcc dot gnu dot org
@ 2007-03-21 18:28 ` trt at acm dot org
3 siblings, 0 replies; 6+ messages in thread
From: trt at acm dot org @ 2007-03-21 18:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from trt at acm dot org 2007-03-21 18:28 -------
I think this could be generalized to more operators, e.g.
(y | (x & 7)) & 7
^ (bitwise or, xor, multiply, ...)
This optimization could be for "e & M" where e contains a subexpression of the
form "t & N" which can (sometimes) be simplified to "t". I suppose that would
require walking the tree.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31261
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/31261] Missed tree optimizations: (8 - (x & 7)) & 7
[not found] <bug-31261-4@http.gcc.gnu.org/bugzilla/>
@ 2010-09-30 21:23 ` jakub at gcc dot gnu.org
0 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-09-30 21:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31261
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2010-09-30 19:21:44 UTC ---
Author: jakub
Date: Thu Sep 30 19:21:34 2010
New Revision: 164761
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=164761
Log:
PR tree-optimization/31261
* fold-const.c (fold_binary): Optimize ((A & N) + B) & M
for constants M and N, M == (1LL << cst) - 1 && (N & M) == M.
* gcc.dg/tree-ssa/pr31261.c: New test.
Added:
trunk/gcc/testsuite/gcc.dg/tree-ssa/pr31261.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/fold-const.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-09-30 19:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-19 11:05 [Bug tree-optimization/31261] New: Missed tree optimizations: (8 - (x & 7)) & 7 jakub at gcc dot gnu dot org
2007-03-19 11:17 ` [Bug tree-optimization/31261] " rguenth at gcc dot gnu dot org
2007-03-19 11:19 ` rguenth at gcc dot gnu dot org
2007-03-21 15:06 ` jakub at gcc dot gnu dot org
2007-03-21 18:28 ` trt at acm dot org
[not found] <bug-31261-4@http.gcc.gnu.org/bugzilla/>
2010-09-30 21:23 ` jakub 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).