public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/38865]  New: missing FRE with VIEW_CONVERT_EXPR
@ 2009-01-15 23:38 pinskia at gcc dot gnu dot org
  2009-01-15 23:40 ` [Bug tree-optimization/38865] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-01-15 23:38 UTC (permalink / raw)
  To: gcc-bugs

Take:
struct s { int i; };
float a (struct s *sv)
{
  sv->i = 0;
  int d = sv->i;
  return *(float*)&d;
}


float a1 (struct s *sv)
{
  sv->i = 0;
  return *(float*)&sv->i;
}

We miss that we could constant prop 0 into the VIEW_CONVERT_EXPR.
Likewise for non aliasing issues but with vectors:
#define vector __attribute__((vector_size(16) ))
struct s { vector int i; };
vector float a (struct s *sv)
{
  sv->i = (vector int){0,0,0};
  vector int d = sv->i;
  return (vector float)(d);
}


vector float a1 (struct s *sv)
{
  sv->i = (vector int){0,0,0};
  return (vector float)sv->i;
}


-- 
           Summary: missing FRE with VIEW_CONVERT_EXPR
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pinskia at gcc dot gnu dot org


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


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

* [Bug tree-optimization/38865] missing FRE with VIEW_CONVERT_EXPR
  2009-01-15 23:38 [Bug tree-optimization/38865] New: missing FRE with VIEW_CONVERT_EXPR pinskia at gcc dot gnu dot org
@ 2009-01-15 23:40 ` pinskia at gcc dot gnu dot org
  2009-01-16  2:33 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-01-15 23:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2009-01-15 23:40 -------
Note with the disabling of VCE creation for *(float*)&sv->i after this bug has
been fixed, there is a possibility that -O2 -fno-strict-aliasing could get
slightly better code than -O2 :).


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


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


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

* [Bug tree-optimization/38865] missing FRE with VIEW_CONVERT_EXPR
  2009-01-15 23:38 [Bug tree-optimization/38865] New: missing FRE with VIEW_CONVERT_EXPR pinskia at gcc dot gnu dot org
  2009-01-15 23:40 ` [Bug tree-optimization/38865] " pinskia at gcc dot gnu dot org
@ 2009-01-16  2:33 ` pinskia at gcc dot gnu dot org
  2009-01-16  9:27 ` rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-01-16  2:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2009-01-16 02:33 -------
Mine. Simple patch which implements it in vn_reference_lookup, Since VCE is
both a reference and really a bit-wise cast, we can do the normal lookup and
then do a lookup if the VCE was not there.  I have not seen if this improves
any testcases yet though but I thought I remembering seeing code like this in
the benchmark we have internally.


Index: tree-ssa-sccvn.c
===================================================================
--- tree-ssa-sccvn.c    (revision 143413)
+++ tree-ssa-sccvn.c    (working copy)
@@ -1041,6 +1041,19 @@ vn_reference_lookup (tree op, VEC (tree,
   vr1.operands = valueize_refs (shared_reference_ops_from_ref (op));
   vr1.hashcode = vn_reference_compute_hash (&vr1);
   result = vn_reference_lookup_1 (&vr1, vnresult);
+  
+  /* If we don't get the result right away for a VIEW_CONVERT_EXPR, try again
+     with the original expression.  */
+  if (!result && TREE_CODE (op) == VIEW_CONVERT_EXPR)
+    {
+      vr1.vuses = valueize_vuses (vuses);
+      vr1.operands = valueize_refs (shared_reference_ops_from_ref
(TREE_OPERAND (op, 0)));
+      vr1.hashcode = vn_reference_compute_hash (&vr1);
+      result = vn_reference_lookup_1 (&vr1, vnresult);
+      /* Convert it back to the original type */
+      if (result)
+       fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (op), result);
+    }

   /* If there is a single defining statement for all virtual uses, we can
      use that, following virtual use-def chains.  */


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |pinskia at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-01-16 02:33:46
               date|                            |


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


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

* [Bug tree-optimization/38865] missing FRE with VIEW_CONVERT_EXPR
  2009-01-15 23:38 [Bug tree-optimization/38865] New: missing FRE with VIEW_CONVERT_EXPR pinskia at gcc dot gnu dot org
  2009-01-15 23:40 ` [Bug tree-optimization/38865] " pinskia at gcc dot gnu dot org
  2009-01-16  2:33 ` pinskia at gcc dot gnu dot org
@ 2009-01-16  9:27 ` rguenth at gcc dot gnu dot org
  2009-01-16  9:36 ` rguenther at suse dot de
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-01-16  9:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2009-01-16 09:27 -------
If you wouldn't generate a V_C_E for *(float*)&sv->i it would just work.

IMHO this should be invalid gimple anyway, as you V_C_E a register type but
the V_C_E argument is not a register.  Thus valid gimple would be either
using a temporary or doing V_C_E <float>(*sv).


-- 


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


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

* [Bug tree-optimization/38865] missing FRE with VIEW_CONVERT_EXPR
  2009-01-15 23:38 [Bug tree-optimization/38865] New: missing FRE with VIEW_CONVERT_EXPR pinskia at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2009-01-16  9:27 ` rguenth at gcc dot gnu dot org
@ 2009-01-16  9:36 ` rguenther at suse dot de
  2009-01-16 18:55 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenther at suse dot de @ 2009-01-16  9:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenther at suse dot de  2009-01-16 09:36 -------
Subject: Re:  missing FRE with
 VIEW_CONVERT_EXPR

On Fri, 16 Jan 2009, pinskia at gcc dot gnu dot org wrote:

> ------- Comment #2 from pinskia at gcc dot gnu dot org  2009-01-16 02:33 -------
> Mine. Simple patch which implements it in vn_reference_lookup, Since VCE is
> both a reference and really a bit-wise cast, we can do the normal lookup and
> then do a lookup if the VCE was not there.  I have not seen if this improves
> any testcases yet though but I thought I remembering seeing code like this in
> the benchmark we have internally.

Can you use the same trick as for union loads/stores and adjust
how we record V_C_Es instead and use the needs_insertion stuff?

Richard.

> Index: tree-ssa-sccvn.c
> ===================================================================
> --- tree-ssa-sccvn.c    (revision 143413)
> +++ tree-ssa-sccvn.c    (working copy)
> @@ -1041,6 +1041,19 @@ vn_reference_lookup (tree op, VEC (tree,
>    vr1.operands = valueize_refs (shared_reference_ops_from_ref (op));
>    vr1.hashcode = vn_reference_compute_hash (&vr1);
>    result = vn_reference_lookup_1 (&vr1, vnresult);
> +  
> +  /* If we don't get the result right away for a VIEW_CONVERT_EXPR, try again
> +     with the original expression.  */
> +  if (!result && TREE_CODE (op) == VIEW_CONVERT_EXPR)
> +    {
> +      vr1.vuses = valueize_vuses (vuses);
> +      vr1.operands = valueize_refs (shared_reference_ops_from_ref
> (TREE_OPERAND (op, 0)));
> +      vr1.hashcode = vn_reference_compute_hash (&vr1);
> +      result = vn_reference_lookup_1 (&vr1, vnresult);
> +      /* Convert it back to the original type */
> +      if (result)
> +       fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (op), result);
> +    }
> 
>    /* If there is a single defining statement for all virtual uses, we can
>       use that, following virtual use-def chains.  */
> 
> 
> 


-- 


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


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

* [Bug tree-optimization/38865] missing FRE with VIEW_CONVERT_EXPR
  2009-01-15 23:38 [Bug tree-optimization/38865] New: missing FRE with VIEW_CONVERT_EXPR pinskia at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2009-01-16  9:36 ` rguenther at suse dot de
@ 2009-01-16 18:55 ` pinskia at gcc dot gnu dot org
  2009-01-16 18:59 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-01-16 18:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2009-01-16 18:55 -------
>If you wouldn't generate a V_C_E for *(float*)&sv->i it would just work.

The front-end generates them for the vector testcase which is why I added that
one to show that forwprop does not matter in the end.


-- 


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


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

* [Bug tree-optimization/38865] missing FRE with VIEW_CONVERT_EXPR
  2009-01-15 23:38 [Bug tree-optimization/38865] New: missing FRE with VIEW_CONVERT_EXPR pinskia at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2009-01-16 18:55 ` pinskia at gcc dot gnu dot org
@ 2009-01-16 18:59 ` pinskia at gcc dot gnu dot org
  2009-06-12 19:01 ` pinskia at gcc dot gnu dot org
  2009-06-12 19:01 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-01-16 18:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pinskia at gcc dot gnu dot org  2009-01-16 18:59 -------
Here is another testcase but this time without -> :
struct s { int i; };
void g(struct s *);
float a (void)
{
  struct s sv;
  sv.i = 0;
  int d = sv.i;
  float d1 = *(float*)&d;
  g(&sv);
  return d1;
}
float a1 (void)
{
  struct s sv;
  sv.i = 0;
  float d = *(float*)&sv.i;
  g(&sv);
  return d;
}


-- 


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


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

* [Bug tree-optimization/38865] missing FRE with VIEW_CONVERT_EXPR
  2009-01-15 23:38 [Bug tree-optimization/38865] New: missing FRE with VIEW_CONVERT_EXPR pinskia at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2009-01-16 18:59 ` pinskia at gcc dot gnu dot org
@ 2009-06-12 19:01 ` pinskia at gcc dot gnu dot org
  2009-06-12 19:01 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-06-12 19:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from pinskia at gcc dot gnu dot org  2009-06-12 19:01 -------
Fixed.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.0


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


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

* [Bug tree-optimization/38865] missing FRE with VIEW_CONVERT_EXPR
  2009-01-15 23:38 [Bug tree-optimization/38865] New: missing FRE with VIEW_CONVERT_EXPR pinskia at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2009-06-12 19:01 ` pinskia at gcc dot gnu dot org
@ 2009-06-12 19:01 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-06-12 19:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pinskia at gcc dot gnu dot org  2009-06-12 19:00 -------
Subject: Bug 38865

Author: pinskia
Date: Fri Jun 12 19:00:39 2009
New Revision: 148437

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148437
Log:
2009-06-12  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR tree-opt/38865
        * tree-ssa-sccvn.c (visit_reference_op_load): If vn_reference_lookup
        is returns NULL and OP is a VCE, look through the VCE.



2009-06-12  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR tree-opt/38865
        * gcc.dg/tree-ssa/fre-vce-1.c
:

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/fre-vce-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-sccvn.c


-- 


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


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

end of thread, other threads:[~2009-06-12 19:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-15 23:38 [Bug tree-optimization/38865] New: missing FRE with VIEW_CONVERT_EXPR pinskia at gcc dot gnu dot org
2009-01-15 23:40 ` [Bug tree-optimization/38865] " pinskia at gcc dot gnu dot org
2009-01-16  2:33 ` pinskia at gcc dot gnu dot org
2009-01-16  9:27 ` rguenth at gcc dot gnu dot org
2009-01-16  9:36 ` rguenther at suse dot de
2009-01-16 18:55 ` pinskia at gcc dot gnu dot org
2009-01-16 18:59 ` pinskia at gcc dot gnu dot org
2009-06-12 19:01 ` pinskia at gcc dot gnu dot org
2009-06-12 19:01 ` 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).