public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed
@ 2004-04-20 1:38 pinskia at gcc dot gnu dot org
2004-04-20 1:45 ` [Bug optimization/15017] " pinskia at gcc dot gnu dot org
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-20 1:38 UTC (permalink / raw)
To: gcc-bugs
On most targets where _Bool is of size 1 (everywhere except PPC-darwin), the following
code contains sign/zero extends which is bad code:
static _Bool as, bs;
_Bool foo3 (void) {
if (as != bs) return 1;
else return 0;
}
Likewise for this code also:
static signed char as, bs;
_Bool foo3 (void) {
int as1 = as;
int bs1 = bs;
if (as1 != bs1) return 1;
else return 0;
}
--
Summary: [tree-ssa] compare (equal) with casts are not removed
Product: gcc
Version: tree-ssa
Status: UNCONFIRMED
Keywords: pessimizes-code
Severity: enhancement
Priority: P2
Component: optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: pinskia at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
@ 2004-04-20 1:45 ` pinskia at gcc dot gnu dot org
2004-04-20 2:25 ` pinskia at gcc dot gnu dot org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-20 1:45 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-04-20 01:09 -------
I will try to fix this but only after I finish my current projects: the cast pass, non-lowering
patch/offsetof, and fixing Darwin's back-end.
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |dann at godzilla dot ics dot
| |uci dot edu
AssignedTo|unassigned at gcc dot gnu |pinskia at gcc dot gnu dot
|dot org |org
Status|UNCONFIRMED |ASSIGNED
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2004-04-20 01:09:48
date| |
Target Milestone|--- |tree-ssa
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
2004-04-20 1:45 ` [Bug optimization/15017] " pinskia at gcc dot gnu dot org
@ 2004-04-20 2:25 ` pinskia at gcc dot gnu dot org
2004-04-20 14:44 ` dann at godzilla dot ics dot uci dot edu
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-20 2:25 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-04-20 01:16 -------
Here is an example which messes up on powerpc (lha is slower than lhz):
static short as, bs;
_Bool foo3 (void) {
int as1 = as;
int bs1 = bs;
if (as1 != bs1) return 1;
else return 0;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
2004-04-20 1:45 ` [Bug optimization/15017] " pinskia at gcc dot gnu dot org
2004-04-20 2:25 ` pinskia at gcc dot gnu dot org
@ 2004-04-20 14:44 ` dann at godzilla dot ics dot uci dot edu
2004-04-20 15:03 ` pinskia at gcc dot gnu dot org
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: dann at godzilla dot ics dot uci dot edu @ 2004-04-20 14:44 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From dann at godzilla dot ics dot uci dot edu 2004-04-20 14:15 -------
It seems that the underlying problem is casting bools to int before
using them.
For example look at the .original dump:
;; Function foo0 (foo0)
;; enabled by -tree-original
{
if ((int)a != 0)
return <return-value> = 1;
else
return <return-value> = 0;
}
The cast does not seem to be needed, != can take a bool as an argument.
Not emitting casts there will simplify the work the optimizers have to do.
I only gave you one function, here is the file I was playing with:
_Bool foo (_Bool a, _Bool b)
{
if (a != b)
return 1;
else
return 0;
}
_Bool foo0 (_Bool a)
{
if (a)
return 1;
else
return 0;
}
_Bool bar (_Bool a)
{
return a;
}
_Bool foo1 (_Bool a, _Bool b)
{
if (bar(a))
return 1;
else
return 0;
}
struct mm
{
_Bool a;
_Bool b;
} T;
_Bool foo2 (void)
{
if (T.a != T.b)
return 1;
else
return 0;
}
static _Bool as, bs;
_Bool foo3 (void) {
if (as != bs) return 1;
else return 0;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
` (2 preceding siblings ...)
2004-04-20 14:44 ` dann at godzilla dot ics dot uci dot edu
@ 2004-04-20 15:03 ` pinskia at gcc dot gnu dot org
2004-04-20 16:23 ` dann at godzilla dot ics dot uci dot edu
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-20 15:03 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-04-20 14:34 -------
And here is the tree dump for patches which I have in my local tree (my cast pass and addition to PHI-
OPT to work with different types and one which combines the return statements):
;; Function foo (foo)
foo (a, b)
{
<bb 0>:
return ((int)a != (int)b); <-- conversion to int not needed
}
;; Function foo0 (foo0)
foo0 (a)
{
<bb 0>:
return (a != 0); <-- same as a cast to int, I have to think of a better way of doing this.
}
;; Function bar (bar)
bar (a)
{
<bb 0>:
return (int)a; <-- good code as _Bool is promoted to int by the ABI
}
;; Function foo2 (foo2)
foo2 ()
{
<bb 0>:
return ((int)T.a != (int)T.b); <--- extranous casts
}
;; Function foo3 (foo3)
foo3 ()
{
<bb 0>:
return ((int)as != (int)bs); <--- likewise
}
;; Function foo1 (foo1)
foo1 (a, b)
{
<bb 0>:
return ((int)a != 0); <--- likewise, and comparision
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
` (3 preceding siblings ...)
2004-04-20 15:03 ` pinskia at gcc dot gnu dot org
@ 2004-04-20 16:23 ` dann at godzilla dot ics dot uci dot edu
2004-05-18 16:42 ` [Bug tree-optimization/15017] " pinskia at gcc dot gnu dot org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: dann at godzilla dot ics dot uci dot edu @ 2004-04-20 16:23 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From dann at godzilla dot ics dot uci dot edu 2004-04-20 15:19 -------
> bar (a)
> {
> <bb 0>:
> return (int)a; <-- good code as _Bool is promoted to int by the ABI
I am not so sure about this, the ABI should not matter at the tree level.
Here is another example:
_Bool A;
_Bool foo01 (void)
{
if (A)
return 1;
else
return 0;
}
The .original dump is:
if ((int)A != 0)
{
return <return-value> = 1;
}
else
{
return <return-value> = 0;
}
The cast should not be emitted here. So IMO the main problem is
emitting the casts in the first place, not being able to get rid
of them later is a different issue.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
` (4 preceding siblings ...)
2004-04-20 16:23 ` dann at godzilla dot ics dot uci dot edu
@ 2004-05-18 16:42 ` pinskia at gcc dot gnu dot org
2004-05-24 21:17 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-18 16:42 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-18 03:50 -------
The second example in comment 0 is fixed when the patch in 15459 is applied.
--
What |Removed |Added
----------------------------------------------------------------------------
BugsThisDependsOn| |15459
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
` (5 preceding siblings ...)
2004-05-18 16:42 ` [Bug tree-optimization/15017] " pinskia at gcc dot gnu dot org
@ 2004-05-24 21:17 ` pinskia at gcc dot gnu dot org
2004-06-07 19:33 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-24 21:17 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|3.5.0 |---
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
` (6 preceding siblings ...)
2004-05-24 21:17 ` pinskia at gcc dot gnu dot org
@ 2004-06-07 19:33 ` pinskia at gcc dot gnu dot org
2005-05-02 4:46 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-07 19:33 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-07 19:33 -------
I will note that at least one of examples later on are filed as PR 15618.
--
What |Removed |Added
----------------------------------------------------------------------------
BugsThisDependsOn| |15618
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
` (7 preceding siblings ...)
2004-06-07 19:33 ` pinskia at gcc dot gnu dot org
@ 2005-05-02 4:46 ` pinskia at gcc dot gnu dot org
2005-05-02 5:00 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-02 4:46 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-02 04:46 -------
Example 1 in comment #0 has been fixed already.
foo0 and foo1 in comment #3 is PR 15618.
foo, foo2, and foo3 in comment #3 has been already fixed also.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
` (8 preceding siblings ...)
2005-05-02 4:46 ` pinskia at gcc dot gnu dot org
@ 2005-05-02 5:00 ` pinskia at gcc dot gnu dot org
2005-05-02 18:51 ` dann at godzilla dot ics dot uci dot edu
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-02 5:00 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-02 05:00 -------
Oh, bool_var1 != bool_var0 should be changed to use TRUTH_XOR_EXPR also.
I will look into that tomorrow.
--
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2005-01-10 15:42:47 |2005-05-02 05:00:30
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
` (9 preceding siblings ...)
2005-05-02 5:00 ` pinskia at gcc dot gnu dot org
@ 2005-05-02 18:51 ` dann at godzilla dot ics dot uci dot edu
2005-05-04 1:52 ` pinskia at gcc dot gnu dot org
2005-05-08 18:20 ` pinskia at gcc dot gnu dot org
12 siblings, 0 replies; 14+ messages in thread
From: dann at godzilla dot ics dot uci dot edu @ 2005-05-02 18:51 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From dann at godzilla dot ics dot uci dot edu 2005-05-02 18:51 -------
Comment #3 in PR15484 has a reference to a patch that might fix the cause for
some of these issues.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
` (10 preceding siblings ...)
2005-05-02 18:51 ` dann at godzilla dot ics dot uci dot edu
@ 2005-05-04 1:52 ` pinskia at gcc dot gnu dot org
2005-05-08 18:20 ` pinskia at gcc dot gnu dot org
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-04 1:52 UTC (permalink / raw)
To: gcc-bugs
--
Bug 15017 depends on bug 15618, which changed state.
Bug 15618 Summary: Missed bool optimization
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15618
What |Old Value |New Value
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/15017] [tree-ssa] compare (equal) with casts are not removed
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
` (11 preceding siblings ...)
2005-05-04 1:52 ` pinskia at gcc dot gnu dot org
@ 2005-05-08 18:20 ` pinskia at gcc dot gnu dot org
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-08 18:20 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-08 18:20 -------
I am too busy for this one.
--
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|pinskia at gcc dot gnu dot |unassigned at gcc dot gnu
|org |dot org
Status|ASSIGNED |NEW
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15017
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2005-05-08 18:20 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-20 1:38 [Bug optimization/15017] New: [tree-ssa] compare (equal) with casts are not removed pinskia at gcc dot gnu dot org
2004-04-20 1:45 ` [Bug optimization/15017] " pinskia at gcc dot gnu dot org
2004-04-20 2:25 ` pinskia at gcc dot gnu dot org
2004-04-20 14:44 ` dann at godzilla dot ics dot uci dot edu
2004-04-20 15:03 ` pinskia at gcc dot gnu dot org
2004-04-20 16:23 ` dann at godzilla dot ics dot uci dot edu
2004-05-18 16:42 ` [Bug tree-optimization/15017] " pinskia at gcc dot gnu dot org
2004-05-24 21:17 ` pinskia at gcc dot gnu dot org
2004-06-07 19:33 ` pinskia at gcc dot gnu dot org
2005-05-02 4:46 ` pinskia at gcc dot gnu dot org
2005-05-02 5:00 ` pinskia at gcc dot gnu dot org
2005-05-02 18:51 ` dann at godzilla dot ics dot uci dot edu
2005-05-04 1:52 ` pinskia at gcc dot gnu dot org
2005-05-08 18:20 ` pinskia at gcc dot gnu dot 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).