public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/45522]  New: VRP misses oppurtunity for statement folding.
@ 2010-09-03 15:58 hubicka at gcc dot gnu dot org
  2010-09-03 15:59 ` [Bug tree-optimization/45522] " hubicka at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 13+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2010-09-03 15:58 UTC (permalink / raw)
  To: gcc-bugs

Hi,
compiling the attached testcase (reduced from tree.c) with -O2 leads to vrp
folding:
  if (D.2762_2 == 6)
    goto <bb 3>;
  else
    goto <bb 9>;

<bb 3>:
  D.2766_5 = (int) D.2762_2;
  D.2767_6 = tree_code_type[D.2766_5];

into
  D.2762_2 = type_1(D)->base.code;
  if (D.2762_2 == 6)
    goto <bb 3>;
  else
    goto <bb 9>;

<bb 3>:
  D.2766_5 = 6;
  D.2767_6 = tree_code_type[6];

this is good transform, however tree_code_type is constant initialized array
and we miss possibility to fold it into constant until expansion triggering
code in expr.c I would like to retire.

We can fold tree_code_type[6], so apparently just no one calls fold_gimple_stmt
on it?


-- 
           Summary: VRP misses oppurtunity for statement folding.
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hubicka at gcc dot gnu dot org


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


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

* [Bug tree-optimization/45522] VRP misses oppurtunity for statement folding.
  2010-09-03 15:58 [Bug tree-optimization/45522] New: VRP misses oppurtunity for statement folding hubicka at gcc dot gnu dot org
@ 2010-09-03 15:59 ` hubicka at gcc dot gnu dot org
  2010-09-03 16:33 ` hubicka at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2010-09-03 15:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from hubicka at gcc dot gnu dot org  2010-09-03 15:59 -------
Created an attachment (id=21684)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21684&action=view)
testcase


-- 


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


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

* [Bug tree-optimization/45522] VRP misses oppurtunity for statement folding.
  2010-09-03 15:58 [Bug tree-optimization/45522] New: VRP misses oppurtunity for statement folding hubicka at gcc dot gnu dot org
  2010-09-03 15:59 ` [Bug tree-optimization/45522] " hubicka at gcc dot gnu dot org
@ 2010-09-03 16:33 ` hubicka at gcc dot gnu dot org
  2010-09-03 16:34 ` hubicka at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2010-09-03 16:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from hubicka at gcc dot gnu dot org  2010-09-03 16:33 -------
OK, the problem seems to be that fold_stmt seems to make no serious attempt to
fold constant references.  There is some code in maybe_fold_reference that
seems to partly duplicate fold_const_aggregate_ref however.  What is reason for
that?

The following patch solves the problem, I am looking what other testcases I can
find.


-- 


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


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

* [Bug tree-optimization/45522] VRP misses oppurtunity for statement folding.
  2010-09-03 15:58 [Bug tree-optimization/45522] New: VRP misses oppurtunity for statement folding hubicka at gcc dot gnu dot org
  2010-09-03 15:59 ` [Bug tree-optimization/45522] " hubicka at gcc dot gnu dot org
  2010-09-03 16:33 ` hubicka at gcc dot gnu dot org
@ 2010-09-03 16:34 ` hubicka at gcc dot gnu dot org
  2010-09-03 20:05 ` hubicka at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2010-09-03 16:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from hubicka at gcc dot gnu dot org  2010-09-03 16:34 -------
Created an attachment (id=21685)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21685&action=view)
patch for better folding


-- 


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


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

* [Bug tree-optimization/45522] VRP misses oppurtunity for statement folding.
  2010-09-03 15:58 [Bug tree-optimization/45522] New: VRP misses oppurtunity for statement folding hubicka at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2010-09-03 16:34 ` hubicka at gcc dot gnu dot org
@ 2010-09-03 20:05 ` hubicka at gcc dot gnu dot org
  2010-09-03 20:10 ` hubicka at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2010-09-03 20:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from hubicka at gcc dot gnu dot org  2010-09-03 20:04 -------
A related testcase where we fail to fold fundamentals[0]
typedef union tree_node *tree;
enum tree_code
{
  OFFSET_TYPE, ENUMERAL_TYPE, BOOLEAN_TYPE, POINTER_TYPE, FIXED_POINT_TYPE,
};
struct tree_base
{
  unsigned public_flag:1;
};
struct tree_decl_with_vis
{
  unsigned comdat_flag:1;
};
union tree_node
{
  struct tree_base base;
  struct tree_decl_with_vis decl_with_vis;
};
enum tree_index
{
    TI_LONG_DOUBLE_PTR_TYPE, TI_INTEGER_PTR_TYPE, TI_VOID_TYPE, TI_PTR_TYPE,
    TI_VA_LIST_FPR_COUNTER_FIELD, TI_BOOLEAN_TYPE, TI_FILEPTR_TYPE,
    TI_CURRENT_TARGET_PRAGMA, TI_CURRENT_OPTIMIZE_PRAGMA, TI_MAX
};
extern tree global_trees[TI_MAX];
emit_support_tinfos (void)
{
  static tree *const fundamentals[] = {
    &global_trees[TI_VOID_TYPE], &global_trees[TI_BOOLEAN_TYPE],
  };
  int ix;
  for (ix = 0; fundamentals[ix]; ix++)
    {
        {
          tree tinfo;
            {
              ((void) (!(((tinfo)->base.public_flag) && !(__extension__ (
                                                                          {
                                                                         
__typeof
                                                                         
(tinfo)
                                                                          __t
                                                                          =
                                                                         
(tinfo);
                                                                          __t;}
                                                          )->decl_with_vis.
                                                          comdat_flag)) ?
                       fancy_abort ("../../gcc/cp/rtti.c", 1529,
                                    __FUNCTION__), 0 : 0));
            }
        }
    }
}


-- 


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


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

* [Bug tree-optimization/45522] VRP misses oppurtunity for statement folding.
  2010-09-03 15:58 [Bug tree-optimization/45522] New: VRP misses oppurtunity for statement folding hubicka at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2010-09-03 20:05 ` hubicka at gcc dot gnu dot org
@ 2010-09-03 20:10 ` hubicka at gcc dot gnu dot org
  2010-09-03 20:13 ` hubicka at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2010-09-03 20:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from hubicka at gcc dot gnu dot org  2010-09-03 20:09 -------
And here we fail to fold messages[1] created by PRE
enum
{
  ERROR_OK, ERROR_UNKNOWN, 
  ERROR_NUM
};
enum
{ __LC_CTYPE = 0, __LC_NUMERIC = 1, __LC_TIME = 2, __LC_COLLATE =
    3, __LC_MONETARY = 4, __LC_MESSAGES = 5, __LC_ALL = 6, __LC_PAPER =
    10, __LC_MEASUREMENT = 11, __LC_IDENTIFICATION = 12 };
static const char *const _messages[] = {
  "no error", "unknown error", "Internal error: unknown reason",
};
elf_errmsg (int err)
{
  if (err < 0 || err >= ERROR_NUM || _messages[err] == ((void *) 0))
    {
      err = ERROR_UNKNOWN;
    }
  return _messages[err];
}


-- 


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


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

* [Bug tree-optimization/45522] VRP misses oppurtunity for statement folding.
  2010-09-03 15:58 [Bug tree-optimization/45522] New: VRP misses oppurtunity for statement folding hubicka at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2010-09-03 20:10 ` hubicka at gcc dot gnu dot org
@ 2010-09-03 20:13 ` hubicka at gcc dot gnu dot org
  2010-09-03 20:29 ` hubicka at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2010-09-03 20:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from hubicka at gcc dot gnu dot org  2010-09-03 20:12 -------
In testcase from comment #4 the problem is that value in DECL_INITIAL is not in
the form acceptable for gimple_min_invariant.  Have patch.
In testcase from comment #5 we never try to fold it.


-- 


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


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

* [Bug tree-optimization/45522] VRP misses oppurtunity for statement folding.
  2010-09-03 15:58 [Bug tree-optimization/45522] New: VRP misses oppurtunity for statement folding hubicka at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2010-09-03 20:13 ` hubicka at gcc dot gnu dot org
@ 2010-09-03 20:29 ` hubicka at gcc dot gnu dot org
  2010-09-04  8:29 ` rguenther at suse dot de
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2010-09-03 20:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from hubicka at gcc dot gnu dot org  2010-09-03 20:28 -------
In #5 the expression is created by PRE via create_expression_by_pieces that
uses normal fold that is not able of constant variable folding. The statement
does not get folded later and survives.  I guess one can fold all statements in
commit_edge_insertions but it seems by symptomatic?


-- 


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


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

* [Bug tree-optimization/45522] VRP misses oppurtunity for statement folding.
  2010-09-03 15:58 [Bug tree-optimization/45522] New: VRP misses oppurtunity for statement folding hubicka at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2010-09-03 20:29 ` hubicka at gcc dot gnu dot org
@ 2010-09-04  8:29 ` rguenther at suse dot de
  2010-09-04 13:52 ` hubicka at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: rguenther at suse dot de @ 2010-09-04  8:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenther at suse dot de  2010-09-04 08:29 -------
Subject: Re:  VRP misses oppurtunity for statement
 folding.

On Fri, 3 Sep 2010, hubicka at gcc dot gnu dot org wrote:

> ------- Comment #7 from hubicka at gcc dot gnu dot org  2010-09-03 20:28 -------
> In #5 the expression is created by PRE via create_expression_by_pieces that
> uses normal fold that is not able of constant variable folding. The statement
> does not get folded later and survives.  I guess one can fold all statements in
> commit_edge_insertions but it seems by symptomatic?

You need to enhance fully_constant_vn_reference_p.

Richard.


-- 


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


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

* [Bug tree-optimization/45522] VRP misses oppurtunity for statement folding.
  2010-09-03 15:58 [Bug tree-optimization/45522] New: VRP misses oppurtunity for statement folding hubicka at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2010-09-04  8:29 ` rguenther at suse dot de
@ 2010-09-04 13:52 ` hubicka at gcc dot gnu dot org
  2010-09-04 14:11 ` rguenther at suse dot de
  2010-09-04 18:01 ` hubicka at gcc dot gnu dot org
  10 siblings, 0 replies; 13+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2010-09-04 13:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from hubicka at gcc dot gnu dot org  2010-09-04 13:51 -------
Hi,
thanks.  In meantime I made tree-ssa-pre to fold statements it produces and it
gets me to bootstrapland with sanity check in expr.c except for Ada (with the
patches I sent so far)

So it seems that I need to basically duplicate all logic for initializer
folding from tree-ssa-ccp.c into this function, right? I guess it makes sense,
but it is all quite ugly.

On VN side, i wondered if we can retire more of expand this way. For example
dojump knows that:
a = b ror x;
if (a != 0)
can be folded into:
if (b != 0)
(ror is rotation).  I guess we should do this kind of tricks in VN instead?

Honza


-- 


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


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

* [Bug tree-optimization/45522] VRP misses oppurtunity for statement folding.
  2010-09-03 15:58 [Bug tree-optimization/45522] New: VRP misses oppurtunity for statement folding hubicka at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2010-09-04 13:52 ` hubicka at gcc dot gnu dot org
@ 2010-09-04 14:11 ` rguenther at suse dot de
  2010-09-04 18:01 ` hubicka at gcc dot gnu dot org
  10 siblings, 0 replies; 13+ messages in thread
From: rguenther at suse dot de @ 2010-09-04 14:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from rguenther at suse dot de  2010-09-04 14:11 -------
Subject: Re:  VRP misses oppurtunity for statement
 folding.

On Sat, 4 Sep 2010, hubicka at gcc dot gnu dot org wrote:

> ------- Comment #9 from hubicka at gcc dot gnu dot org  2010-09-04 13:51 -------
> Hi,
> thanks.  In meantime I made tree-ssa-pre to fold statements it produces and it
> gets me to bootstrapland with sanity check in expr.c except for Ada (with the
> patches I sent so far)

Well - that's a workaround and will cause us to miss PRE because we do
not fold during translation of expressions.  So I wouldn't go down that
route.

> So it seems that I need to basically duplicate all logic for initializer
> folding from tree-ssa-ccp.c into this function, right? I guess it makes sense,
> but it is all quite ugly.

Yes ;)

> On VN side, i wondered if we can retire more of expand this way. For example
> dojump knows that:
> a = b ror x;
> if (a != 0)
> can be folded into:
> if (b != 0)
> (ror is rotation).  I guess we should do this kind of tricks in VN instead?

Well ... it's not that easy (that's not CSE but tree-combining, so
the specific thing would fit to forwprop).

Richard.


-- 


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


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

* [Bug tree-optimization/45522] VRP misses oppurtunity for statement folding.
  2010-09-03 15:58 [Bug tree-optimization/45522] New: VRP misses oppurtunity for statement folding hubicka at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2010-09-04 14:11 ` rguenther at suse dot de
@ 2010-09-04 18:01 ` hubicka at gcc dot gnu dot org
  10 siblings, 0 replies; 13+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2010-09-04 18:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from hubicka at gcc dot gnu dot org  2010-09-04 18:00 -------
Created an attachment (id=21700)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21700&action=view)
proposed fix for sccvn

Well, this is patch I am currently testing. At least small part is shared in
between tree-ssa-ccp (probably should go into gimple-fold) and VN.
I am not sure how much of other initializer folding I need to borrow - i.e.
folding of var_decl into its decl_initial, handling of component_refs and such.

Also the tree-ssa-ccp code seems quite incomplette, it won't fold array with
incomplette initializer for example because it won't find the matching item. 
Probably worth to fix.

Honza


-- 


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


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

* [Bug tree-optimization/45522] VRP misses oppurtunity for statement folding.
       [not found] <bug-45522-4@http.gcc.gnu.org/bugzilla/>
@ 2010-10-28 20:41 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-10-28 20:41 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2010.10.28 20:41:46
     Ever Confirmed|0                           |1

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-10-28 20:41:46 UTC ---
Confirmed.


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

end of thread, other threads:[~2010-10-28 20:41 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-03 15:58 [Bug tree-optimization/45522] New: VRP misses oppurtunity for statement folding hubicka at gcc dot gnu dot org
2010-09-03 15:59 ` [Bug tree-optimization/45522] " hubicka at gcc dot gnu dot org
2010-09-03 16:33 ` hubicka at gcc dot gnu dot org
2010-09-03 16:34 ` hubicka at gcc dot gnu dot org
2010-09-03 20:05 ` hubicka at gcc dot gnu dot org
2010-09-03 20:10 ` hubicka at gcc dot gnu dot org
2010-09-03 20:13 ` hubicka at gcc dot gnu dot org
2010-09-03 20:29 ` hubicka at gcc dot gnu dot org
2010-09-04  8:29 ` rguenther at suse dot de
2010-09-04 13:52 ` hubicka at gcc dot gnu dot org
2010-09-04 14:11 ` rguenther at suse dot de
2010-09-04 18:01 ` hubicka at gcc dot gnu dot org
     [not found] <bug-45522-4@http.gcc.gnu.org/bugzilla/>
2010-10-28 20:41 ` pinskia 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).