Bug 26629 - tree load PRE does not work on array references
Summary: tree load PRE does not work on array references
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.2.0
: P3 enhancement
Target Milestone: 4.2.0
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: missed-optimization, patch
Depends on:
Blocks:
 
Reported: 2006-03-10 05:31 UTC by Andrew Pinski
Modified: 2006-03-20 21:00 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-03-11 22:07:37


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2006-03-10 05:31:07 UTC
While Looking into PR 21485, I noticed this.  This might come up more with the array references for pointers patch.

Testcase:
typedef long dtype;
typedef dtype longarray[];
int g (longarray *array1, unsigned long i, dtype j)
{
  if ((*array1)[i] < (*array1)[i + 1])
      ++i;
  if (j < (*array1)[i])
    h();
  return i;
}
int g2 (longarray *array1, unsigned long i, dtype j)
{
  dtype a = (*array1)[i];
  dtype b = (*array1)[i + 1];
  dtype c = a;
  if (a < b) ++i, c = b;
  if (j < c)
    h();
  return i;
}

g2 is the optimized version of g.  If I remove the "return i", the RTL level optimizations catches it.
Comment 1 Andrew Pinski 2006-03-10 12:50:53 UTC
Here is another testcase:
typedef long dtype;
typedef dtype longarray[];
int g (longarray *array1, unsigned long i, dtype j)
{
  if (!(*array1)[i])
    i++;
  if (j < (*array1)[i])
    h();
  return i;
}

int g1 (longarray *array1, unsigned long i, dtype j)
{
  dtype a = (*array1)[i];
  if (!a)
    {
      i++;
      a = (*array1)[i];
    }
  if (j < a)
    h();
  return i;
}

FRE handles this just fine, it is PRE which does not.
Comment 2 Andrew Pinski 2006-03-10 12:59:43 UTC
(In reply to comment #1)
> FRE handles this just fine, it is PRE which does not.
Let me clarify that comment, For FRE I am talking about code like:
typedef long dtype;
typedef dtype longarray[];
int g (longarray *array1, unsigned long i, dtype j)
{
  if (!(*array1)[i])
    j++;
  if (j < (*array1)[i])
    h();
  return i;
}
Comment 3 Andrew Pinski 2006-03-11 22:07:37 UTC
I have a patch.  Thanks Daniel for recommending places to look to change.
Comment 4 Andrew Pinski 2006-03-17 16:11:41 UTC
Patch posted:
http://gcc.gnu.org/ml/gcc-patches/2006-03/msg01110.html
Comment 5 Andrew Pinski 2006-03-20 21:00:23 UTC
Subject: Bug 26629

Author: pinskia
Date: Mon Mar 20 21:00:18 2006
New Revision: 112227

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=112227
Log:
2006-03-20  Andrew Pinski  <pinskia@physics.uc.edu>

        PR tree-opt/26629
        * tree-ssa-pre (phi_translate): Handle ARRAY_REF's operands.
        (valid_in_set): Handle ARRAY_REF.
        Change "if min_variant or VH" to asserts.
        (create_component_ref_by_pieces): Handle ARRAY_REF.
        (create_expression_by_pieces): Likewise.
        (can_PRE_operation): ARRAY_REFs can now be PRE'd.

2006-03-20  Andrew Pinski  <pinskia@physics.uc.edu>

        PR tree-opt/26629
        * gcc.dg/tree-ssa/loadpre12.c: New test.
        * gcc.dg/tree-ssa/loadpre13.c: New test.
        * gcc.dg/tree-ssa/loadpre14.c: New test.
        * gcc.dg/tree-ssa/loadpre15.c: New test.
        * gcc.dg/tree-ssa/loadpre16.c: New test.
        * gcc.dg/tree-ssa/loadpre17.c: New test.
        * gcc.dg/tree-ssa/loadpre18.c: New test.
        * gcc.dg/tree-ssa/loadpre19.c: New test.
        * gcc.dg/tree-ssa/loadpre20.c: New test.
        * gcc.dg/tree-ssa/loadpre21.c: New test.
        * gcc.dg/tree-ssa/loadpre22.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loadpre12.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loadpre13.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loadpre14.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loadpre15.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loadpre16.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loadpre17.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loadpre18.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loadpre19.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loadpre20.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loadpre21.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loadpre22.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-pre.c

Comment 6 Andrew Pinski 2006-03-20 21:00:40 UTC
Fixed in rev 112227.