public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast
@ 2005-05-11 21:02 pinskia at gcc dot gnu dot org
  2005-05-11 21:02 ` [Bug tree-optimization/21520] " pinskia at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-11 21:02 UTC (permalink / raw)
  To: gcc-bugs

The following code we miss a PRE opportunity

int do_locator (int *call)
{
  int type = 1;
  if (call != 0)
    type = *call;
  return (int)(char)type;
}

We should get:
int do_locator (int *call)
{
  int type = 1;
  if (call != 0)
    type = (int)(char)*call;
  return type;
}

But right now we get:
int do_locator (int *call)
{
  char t = 1;
  if (call != 0)
    t = (char)*call;
  return (int)t;
}

-- 
           Summary: missing PRE opportunity with cast after cast
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P2
         Component: tree-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=21520


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/21520] missing PRE opportunity with cast after cast
  2005-05-11 21:02 [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast pinskia at gcc dot gnu dot org
@ 2005-05-11 21:02 ` pinskia at gcc dot gnu dot org
  2005-05-11 22:04 ` pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-11 21:02 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dberlin at gcc dot gnu dot
                   |                            |org, pinskia at gcc dot gnu
                   |                            |dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21520


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/21520] missing PRE opportunity with cast after cast
  2005-05-11 21:02 [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast pinskia at gcc dot gnu dot org
  2005-05-11 21:02 ` [Bug tree-optimization/21520] " pinskia at gcc dot gnu dot org
@ 2005-05-11 22:04 ` pinskia at gcc dot gnu dot org
  2005-05-11 22:25 ` [Bug tree-optimization/21520] missing PRE opportunity with operand after operand pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-11 22:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-11 22:04 -------
And we save an  instruction on x86 (both with -O2 -fomit-frame-pointer)
before:
        movl    4(%esp), %edx
        movb    $1, %al
        testl   %edx, %edx
        je      .L4
        movzbl  (%edx), %eax
.L4:
        movsbl  %al,%eax
        ret
after:
        movl    4(%esp), %edx
        movl    $1, %eax
        testl   %edx, %edx
        je      .L10
        movsbl  (%edx),%eax
.L10:
        ret

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21520


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/21520] missing PRE opportunity with operand after operand
  2005-05-11 21:02 [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast pinskia at gcc dot gnu dot org
  2005-05-11 21:02 ` [Bug tree-optimization/21520] " pinskia at gcc dot gnu dot org
  2005-05-11 22:04 ` pinskia at gcc dot gnu dot org
@ 2005-05-11 22:25 ` pinskia at gcc dot gnu dot org
  2005-05-11 23:22 ` steven at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-11 22:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-11 22:25 -------
Another testcase which shows it is not related to casts:
int do_locator (int *call)
{
  int type = 1;
  if (call != 0)
    type = *call;
  return type * 4 + 1;
}

int do_locator1 (int *call)
{
  int prephitmp5;
  prephitmp5 = 5;
  if (call != 0)
    prephitmp5 = *call * 4 + 1;
  return prephitmp5;
}

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|missing PRE opportunity with|missing PRE opportunity with
                   |cast after cast             |operand after operand


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21520


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/21520] missing PRE opportunity with operand after operand
  2005-05-11 21:02 [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast pinskia at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2005-05-11 22:25 ` [Bug tree-optimization/21520] missing PRE opportunity with operand after operand pinskia at gcc dot gnu dot org
@ 2005-05-11 23:22 ` steven at gcc dot gnu dot org
  2005-05-11 23:40 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-05-11 23:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2005-05-11 23:22 -------
The casts one seems to be there because we don't look through casts: 
 
Created value VH.14 for (charD.1) 1 
Created value VH.15 for (intD.0) VH.14 
 
This means that for the first cast we find a fully_constant_expression here: 
1650                              eprime = fully_constant_expression (eprime); 
 
but not for the second. 
 
I haven't looked at the other test case yet. 
 
 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-05-11 23:22:17
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21520


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/21520] missing PRE opportunity with operand after operand
  2005-05-11 21:02 [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast pinskia at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2005-05-11 23:22 ` steven at gcc dot gnu dot org
@ 2005-05-11 23:40 ` pinskia at gcc dot gnu dot org
  2005-05-12  6:58 ` steven at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-11 23:40 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-11 23:40 -------
I had forgot to mention this came from looking at PR 21518.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21520


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/21520] missing PRE opportunity with operand after operand
  2005-05-11 21:02 [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast pinskia at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2005-05-11 23:40 ` pinskia at gcc dot gnu dot org
@ 2005-05-12  6:58 ` steven at gcc dot gnu dot org
  2005-05-12 10:23 ` steven at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-05-12  6:58 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2005-05-12 06:58 -------
It looks like phi_translate should fold the phi-translated expression...? 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |steven at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21520


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/21520] missing PRE opportunity with operand after operand
  2005-05-11 21:02 [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast pinskia at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2005-05-12  6:58 ` steven at gcc dot gnu dot org
@ 2005-05-12 10:23 ` steven at gcc dot gnu dot org
  2005-05-12 22:13 ` cvs-commit at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-05-12 10:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2005-05-12 10:23 -------
The failure I mentioned in comment #7 is caused by remove_dead_inserted_code, 
which removes the statement setting that SSA name: 
 
In the .pre dump file: 
Removing unnecessary insertion:pretmp.308_35 = (unsigned char *)pretmp.307_36; 
 
And the ICE message: 
error: Missing definition for SSA_NAME: pretmp.308_35 in statement: 
 
That remove_dead_inserted_code passlet doesn't work very well anyway, for 
the original test case we also have dead code in the .pre dump: 
 
do_locator1 (call) 
{ 
  int prephitmp.4; 
  int pretmp.3; 
  char prephitmp.2; 
  char pretmp.1; 
  int type; 
  char D.1566; 
  int D.1565; 
 
<bb 0>: 
  if (call_3 != 0B) goto <L0>; else goto <L4>; 
 
<L4>:; 
  goto <bb 2> (<L1>); 
 
<L0>:; 
  type_7 = *call_3; 
  pretmp.1_2 = (char) type_7; 
  pretmp.3_10 = (int) pretmp.1_2; 
 
  # prephitmp.4_11 = PHI <1(3), pretmp.3_10(1)>; 
  # prephitmp.2_9 = PHI <1(3), pretmp.1_2(1)>; 
  # type_1 = PHI <1(3), type_7(1)>; 
<L1>:; 
  D.1566_4 = prephitmp.2_9; 
  D.1565_5 = prephitmp.4_11; 
  return D.1565_5; 
 
} 
 
It may be better to just not have this ad-hoc DCE and move a real DCE pass 
up in the pass schedule -- something like this: 
 
Index: tree-optimize.c 
=================================================================== 
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v 
retrieving revision 2.90 
diff -u -3 -p -r2.90 tree-optimize.c 
--- tree-optimize.c     11 May 2005 02:24:42 -0000      2.90 
+++ tree-optimize.c     12 May 2005 09:09:53 -0000 
@@ -405,10 +405,10 @@ init_tree_optimization_passes (void) 
   NEXT_PASS (pass_split_crit_edges); 
   NEXT_PASS (pass_pre); 
   NEXT_PASS (pass_sink_code); 
+  NEXT_PASS (pass_dce); 
   NEXT_PASS (pass_loop); 
   NEXT_PASS (pass_dominator); 
   NEXT_PASS (pass_copy_prop); 
-  NEXT_PASS (pass_dce); 
   /* FIXME: If DCE is not run before checking for uninitialized uses, 
      we may get false warnings (e.g., testsuite/gcc.dg/uninit-5.c). 
      However, this also causes us to misdiagnose cases that should be 
@@ -418,8 +418,8 @@ init_tree_optimization_passes (void) 
      account for the predicates protecting the set and the use of each 
      variable.  Using a representation like Gated Single Assignment 
      may help.  */ 
-  NEXT_PASS (pass_late_warn_uninitialized); 
   NEXT_PASS (pass_cd_dce); 
+  NEXT_PASS (pass_late_warn_uninitialized); 
   NEXT_PASS (pass_dse); 
   NEXT_PASS (pass_forwprop); 
   NEXT_PASS (pass_phiopt); 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21520


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/21520] missing PRE opportunity with operand after operand
  2005-05-11 21:02 [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast pinskia at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2005-05-12 10:23 ` steven at gcc dot gnu dot org
@ 2005-05-12 22:13 ` cvs-commit at gcc dot gnu dot org
  2005-05-12 23:33 ` dberlin at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-05-12 22:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-05-12 22:13 -------
Subject: Bug 21520

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	dberlin@gcc.gnu.org	2005-05-12 22:13:00

Modified files:
	gcc            : ChangeLog tree-ssa-pre.c 
Added files:
	gcc/testsuite/gcc.c-torture/compile: pr21532.c 

Log message:
	Fix PR tree-optimization/21520
	* tree-ssa-pre.c (phi_translate): Use fully_constant_expression
	to attempt to fold constants.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8751&r2=2.8752
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa-pre.c.diff?cvsroot=gcc&r1=2.85&r2=2.86
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/pr21532.c.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21520


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/21520] missing PRE opportunity with operand after operand
  2005-05-11 21:02 [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast pinskia at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2005-05-12 22:13 ` cvs-commit at gcc dot gnu dot org
@ 2005-05-12 23:33 ` dberlin at gcc dot gnu dot org
  2005-05-12 23:34 ` dberlin at gcc dot gnu dot org
  2005-05-13 11:47 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: dberlin at gcc dot gnu dot org @ 2005-05-12 23:33 UTC (permalink / raw)
  To: gcc-bugs



-- 
Bug 21520 depends on bug 21532, which changed state.

Bug 21532 Summary: ICE caused by PRE dead instruction removal
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21532

           What    |Old Value                   |New Value
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21520


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/21520] missing PRE opportunity with operand after operand
  2005-05-11 21:02 [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast pinskia at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2005-05-12 23:33 ` dberlin at gcc dot gnu dot org
@ 2005-05-12 23:34 ` dberlin at gcc dot gnu dot org
  2005-05-13 11:47 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: dberlin at gcc dot gnu dot org @ 2005-05-12 23:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dberlin at gcc dot gnu dot org  2005-05-12 23:34 -------
Foxed

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21520


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/21520] missing PRE opportunity with operand after operand
  2005-05-11 21:02 [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast pinskia at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2005-05-12 23:34 ` dberlin at gcc dot gnu dot org
@ 2005-05-13 11:47 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-13 11:47 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.1.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21520


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2005-05-13 11:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-11 21:02 [Bug tree-optimization/21520] New: missing PRE opportunity with cast after cast pinskia at gcc dot gnu dot org
2005-05-11 21:02 ` [Bug tree-optimization/21520] " pinskia at gcc dot gnu dot org
2005-05-11 22:04 ` pinskia at gcc dot gnu dot org
2005-05-11 22:25 ` [Bug tree-optimization/21520] missing PRE opportunity with operand after operand pinskia at gcc dot gnu dot org
2005-05-11 23:22 ` steven at gcc dot gnu dot org
2005-05-11 23:40 ` pinskia at gcc dot gnu dot org
2005-05-12  6:58 ` steven at gcc dot gnu dot org
2005-05-12 10:23 ` steven at gcc dot gnu dot org
2005-05-12 22:13 ` cvs-commit at gcc dot gnu dot org
2005-05-12 23:33 ` dberlin at gcc dot gnu dot org
2005-05-12 23:34 ` dberlin at gcc dot gnu dot org
2005-05-13 11:47 ` 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).