From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22194 invoked by alias); 21 Jul 2005 12:04:54 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 22173 invoked by uid 48); 21 Jul 2005 12:04:49 -0000 Date: Thu, 21 Jul 2005 12:11:00 -0000 From: "steven at gcc dot gnu dot org" To: gcc-bugs@gcc.gnu.org Message-ID: <20050721120447.22586.steven@gcc.gnu.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug tree-optimization/22586] New: GVN-PRE could do strength reduction X-Bugzilla-Reason: CC X-SW-Source: 2005-07/txt/msg02552.txt.bz2 List-Id: There doesn't appear to be any reason why GVN-PRE couldn't be extended to do strength reduction. If this is added, the strength reduction currently done in DOM and IVOPTS may be removed or simplified. The implementation in IVOPTS only works on loops, and the transformations done in DOM only works in a few special cases and only on a branch of the dominator tree (i.e. not a global pass). Also, GVN-PRE could replace the flag_unsafe_math_optimizations trick that used to be in expr.c and is now in tree-ssa-loop-im.c: /* If divisor is invariant, convert a/b to a*(1/b), allowing reciprocal to be hoisted out of loop, saving expensive divide. */ Adding this transformation as a special case of "strength reduction" to GVN-PRE would allow the transformation to be done on straight-line code as well (the code in expr.c used to do this, but we don't do the transformation anymore at the moment). Consider as an example: int foo (int a[], int b[], int i) { a[i] = b[i] + 2; i++; a[i] = b[i] + 2; i++; a[i] = b[i] + 2; i++; a[i] = b[i] + 2; i++; return i; } "GCC 4.1.0 20050721 (experimental)" produces the following .vars dump: foo (a, b, i) { int * temp.44; int * temp.43; int * temp.42; int * D.1608; : D.1608 = (int *) ((long unsigned int) i * 4); *(D.1608 + a) = *(D.1608 + b) + 2; temp.42 = (int *) ((long unsigned int) (i + 1) * 4); *(a + temp.42) = *(b + temp.42) + 2; temp.43 = (int *) ((long unsigned int) (i + 2) * 4); *(a + temp.43) = *(b + temp.43) + 2; temp.44 = (int *) ((long unsigned int) (i + 3) * 4); *(a + temp.44) = *(b + temp.44) + 2; return i + 4; } Note the redundant computations of "i*4". Indeed, we don't optimize these away on RTL either. -- Summary: GVN-PRE could do strength reduction Product: gcc Version: 4.1.0 Status: UNCONFIRMED Keywords: missed-optimization, TREE Severity: enhancement Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: steven at gcc dot gnu dot org CC: dberlin at gcc dot gnu dot org,gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22586