If you have code that does division by a constant that can be auto vectorized by the compiler, the compiler does not convert the division to multiplication by the reciprocal if -freciprocal-math (or -ffast-math), but instead does the division. The bug is in fold-const.c near line 11254, where the code for handling REAL_CST should be cloned to handle VECTOR_CST (and presumably COMPLEX_CST also).
Actually in looking at it further, I was wrong in the initial claim. Auto vectorization now handles division by a constant. Explicit vectors like PowerPC (and probably SPU) do show the problem.
Created attachment 20712 [details] Example program that shows the issue on powerpc. Compile with -mcpu=power7 on powerpc.
The fold code should probably simply use fold_binary to do the constant folding (which already should handle 1/x for x vector and complex. There is a build_one_cst to build the constant 1 for any type). The exact result check would need to use mpc (and I'm not sure its correct for -frounding-math anyway).
I'll take this one.
Author: wschmidt Date: Fri Apr 20 14:19:13 2012 New Revision: 186625 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186625 Log: gcc: 2012-04-20 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR rtl-optimization/44214 * fold-const.c (exact_inverse): New function. (fold_binary_loc): Fold vector and complex division by constant into multiply by recripocal with flag_reciprocal_math; fold vector division by constant into multiply by reciprocal with exact inverse. gcc/testsuite: 2012-04-20 Bill Schmidt <wschmidt@linux.vnet.ibm.com> PR rtl-optimization/44214 * gcc.dg/pr44214-1.c: New test. * gcc.dg/pr44214-2.c: Likewise. * gcc.dg/pr44214-3.c: Likewise. Added: trunk/gcc/testsuite/gcc.dg/pr44214-1.c trunk/gcc/testsuite/gcc.dg/pr44214-2.c trunk/gcc/testsuite/gcc.dg/pr44214-3.c Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog
Fixed.