This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
const folding vs multiply-add
- To: gcc at gcc dot gnu dot org
- Subject: const folding vs multiply-add
- From: Dale Johannesen <dalej at apple dot com>
- Date: Thu, 8 Nov 2001 16:52:10 -0800
Currently the tree-based const folding changes x*2.0 to x+x.
This is not always the right thing to do on a machine with
a multiply-add instruction (ppc):
for(i=...) { x[i] = y[i] * 2.0 + z; }
Best code is to pull the load of 2.0 out of the loop and
generate a single multiply-add instruction within the loop.
Of course, the current behavior will be better in some other
cases. Getting all the cases right seems difficult, and
it's not obvious to me how to approach this. I could
probably teach combine to make x+x-z into a multiply-add
instruction, but then it's too late to pull the resulting
2.0 out of the loop. I'm inclined to just whack the tree-based
optimization out; since it's done before const propagation,
the gain isn't great anyway, and many users routinely write
x+x to begin with if they care about performance. There's
no hook to do that, so this would presumably remain an
Apple-specific change. Any better ideas?