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.
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.
(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; }
I have a patch. Thanks Daniel for recommending places to look to change.
Patch posted: http://gcc.gnu.org/ml/gcc-patches/2006-03/msg01110.html
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
Fixed in rev 112227.