public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/45397] New: [4.5/4.6 Regression] Issues with integer narrowing conversions
@ 2010-08-24 13:19 jakub at gcc dot gnu dot org
2010-08-24 13:35 ` [Bug tree-optimization/45397] " jakub at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-08-24 13:19 UTC (permalink / raw)
To: gcc-bugs
In http://gcc.gnu.org/ml/gcc/2010-08/msg00326.html
Revital complained about MAX_EXPR no longer being recognized in:
int foo (const unsigned char *tmp, int i, int val)
{
return (unsigned char)(((tmp[i] + val)>0xFF)?0xFF:(((tmp[i] +
val)<0)?0:(tmp[i] + val)));
}
It is still recognized when using:
int bar (const unsigned char *tmp, int i, int val)
{
int x = (((tmp[i] + val)>0xFF)?0xFF:(((tmp[i] + val)<0)?0:(tmp[i] + val)));
return (unsigned char)x;
}
The regression is caused by folding being delayed in the C FE, while before
the inner COND_EXPR has been optimized by fold_ternary* into MAX_EXPR, now it
isn't immediately, thus convert_to_integer on the narrowing conversion
propagates the (unsigned char) narrowing casts down into the operands and when
fold_ternary* is actually called, it is too late, as the operands aren't
considered equal.
Perhaps it would be nice for -O2 to consider for e.g. int a and b
that (unsigned char) (a + b) is the same as (unsigned char) a + (unsigned char)
b during VN.
--
Summary: [4.5/4.6 Regression] Issues with integer narrowing
conversions
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Keywords: missed-optimization
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=45397
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/45397] [4.5/4.6 Regression] Issues with integer narrowing conversions
2010-08-24 13:19 [Bug tree-optimization/45397] New: [4.5/4.6 Regression] Issues with integer narrowing conversions jakub at gcc dot gnu dot org
@ 2010-08-24 13:35 ` jakub at gcc dot gnu dot org
2010-08-24 13:42 ` jakub at gcc dot gnu dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-08-24 13:35 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from jakub at gcc dot gnu dot org 2010-08-24 13:35 -------
On the C FE side, perhaps these optimizations should be moved over from
convert_to_integer to e.g. c_fully_fold_internal, where the operand would be
folded first and only afterwards the narrowing conversion optimization would be
applied. That would solve this testcase too, but wouldn't help the case where
the narrowing conversion is done by the user already.
int foo (const unsigned char *a, int b, int c)
{
int x = (unsigned char) (a[b] + c);
int y = a[b] + c;
int z = (unsigned char) y;
return x == z;
}
is another testcase which isn't currently optimized at the tree level (the RTL
level can figure this out though).
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jsm28 at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45397
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/45397] [4.5/4.6 Regression] Issues with integer narrowing conversions
2010-08-24 13:19 [Bug tree-optimization/45397] New: [4.5/4.6 Regression] Issues with integer narrowing conversions jakub at gcc dot gnu dot org
2010-08-24 13:35 ` [Bug tree-optimization/45397] " jakub at gcc dot gnu dot org
@ 2010-08-24 13:42 ` jakub at gcc dot gnu dot org
2010-08-24 14:13 ` rguenth at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-08-24 13:42 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from jakub at gcc dot gnu dot org 2010-08-24 13:41 -------
Created an attachment (id=21556)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21556&action=view)
minmax.patch
I've also noticed that the folder only recognizes the inner MAX_EXPR, but
doesn't recognize the outer MIN_EXPR. Apparently (when convert_to_integer
doesn't harm it, i.e. the bar testcase instead of foo) phiopt1 later on figures
this out. The attached (untested) patch handles that case early, but not sure
it is worth it.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45397
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/45397] [4.5/4.6 Regression] Issues with integer narrowing conversions
2010-08-24 13:19 [Bug tree-optimization/45397] New: [4.5/4.6 Regression] Issues with integer narrowing conversions jakub at gcc dot gnu dot org
2010-08-24 13:35 ` [Bug tree-optimization/45397] " jakub at gcc dot gnu dot org
2010-08-24 13:42 ` jakub at gcc dot gnu dot org
@ 2010-08-24 14:13 ` rguenth at gcc dot gnu dot org
2010-08-30 15:46 ` rguenth at gcc dot gnu dot org
2010-08-30 16:01 ` rguenth at gcc dot gnu dot org
4 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-08-24 14:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2010-08-24 14:13 -------
Confirmed.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2010-08-24 14:13:05
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45397
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/45397] [4.5/4.6 Regression] Issues with integer narrowing conversions
2010-08-24 13:19 [Bug tree-optimization/45397] New: [4.5/4.6 Regression] Issues with integer narrowing conversions jakub at gcc dot gnu dot org
` (2 preceding siblings ...)
2010-08-24 14:13 ` rguenth at gcc dot gnu dot org
@ 2010-08-30 15:46 ` rguenth at gcc dot gnu dot org
2010-08-30 16:01 ` rguenth at gcc dot gnu dot org
4 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-08-30 15:46 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |4.5.2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45397
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/45397] [4.5/4.6 Regression] Issues with integer narrowing conversions
2010-08-24 13:19 [Bug tree-optimization/45397] New: [4.5/4.6 Regression] Issues with integer narrowing conversions jakub at gcc dot gnu dot org
` (3 preceding siblings ...)
2010-08-30 15:46 ` rguenth at gcc dot gnu dot org
@ 2010-08-30 16:01 ` rguenth at gcc dot gnu dot org
4 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-08-30 16:01 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45397
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/45397] [4.5/4.6 Regression] Issues with integer narrowing conversions
[not found] <bug-45397-4@http.gcc.gnu.org/bugzilla/>
@ 2010-12-16 13:18 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2010-12-16 13:18 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45397
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|4.5.2 |4.5.3
--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2010-12-16 13:03:18 UTC ---
GCC 4.5.2 is being released, adjusting target milestone.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-12-16 13:12 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-24 13:19 [Bug tree-optimization/45397] New: [4.5/4.6 Regression] Issues with integer narrowing conversions jakub at gcc dot gnu dot org
2010-08-24 13:35 ` [Bug tree-optimization/45397] " jakub at gcc dot gnu dot org
2010-08-24 13:42 ` jakub at gcc dot gnu dot org
2010-08-24 14:13 ` rguenth at gcc dot gnu dot org
2010-08-30 15:46 ` rguenth at gcc dot gnu dot org
2010-08-30 16:01 ` rguenth at gcc dot gnu dot org
[not found] <bug-45397-4@http.gcc.gnu.org/bugzilla/>
2010-12-16 13:18 ` rguenth 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).