This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: [gcc3.5 improvement branch] Very Simple constant propagation


This patch is to address an efficiency problem in gcc. If you compile the following small loop
with -O3 -ffast-math, the optimizer converts the "a/b" into "a * 1/b", in the hopes of being
able to do some further optimizations. In this case it can't so ideally the combiner should
convert "a * 1/b" back into "a/b". Unfortunately, it can't figure out that it can do that because
the combiner only looks within the current basic block, and the constant 1 has been hoisted
out of the loop. This is unfortunate, because it causes an extra floating point multiplication to
be performed in every iteration of this loop, which is a major performance hit in the code this
originally came from. To fix this problem, I have implemented a very tiny, very specific,
very simple version of constant propagation: It goes over the RTL looking for a register that
is assigned a constant value once, and is never re-assigned another value anywhere in the
instructions for the function. For lack of a better name I called these "single set constants".
Whenever I find such a Single Set Constant, I replace uses of that register with the constant
value. This is performed just before the combiner is run, and it does fix this problem.


The test code for this problem is:

float *a, *b;

float foo () {
int i;
float sum = 1.0;
for (i = 0; i < 4; i++)
sum *= a[i]/b[i];
}



This patch has been tested on an Apple G4 running apple-darwin. It bootstraps and passes DejaGnu tests. Is this okay to commit to the gcc 3.5 improvements branch? Or gcc 3.4?

ChangeLog entry:

2004-01-15 Caroline Tice <ctice@apple.com>


* Makefile.in: Add code to compiler const-prop.c.
* combine.c (try_combine): Add conditional call to ss_replace_assignment.
* common.opt (ss-const-prop): New option.
* flags.h (flag_ss_const_prop): New flag.
* function.h (find_all_single_set_constants): New function declaration.
(cleanup_ss_constant_propagation): New function declaration.
(ss_replace_assignment): New function declaration.
(ss_constant_propagation): New function declaration.
* opts.c (decode_options): Turn on flag_ss_const_prop at -O2.
(common_handle_option): Add code for OPT_ss_const_prop.
* simplify-rtx.c (simplify_binary_operation): Add calls to
ss_constant_propagation.
* toplev.c a (flag_ss_const_prop): Initialize new flag.
(f_options): Add ss-const-prop option.
(rest_of_handle_combine): Add calls to find_all_single_set_constants and
cleanup_ss_constant_propagation.
* const-prop.c: New file.



Attachment: gcc4-const-prop.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]