[backport from gcc-4.7/trunk ] gcc/ 2011-04-20 Richard Guenther PR tree-optimization/47892 * tree-if-conv.c (if_convertible_stmt_p): Const builtins are if-convertible. gcc/testsuite/ 2011-04-20 Richard Guenther PR tree-optimization/47892 * gcc.dg/vect/fast-math-ifcvt-1.c: New testcase. --- gcc-4.6.0/gcc/testsuite/gcc.dg/vect/fast-math-ifcvt-1.c.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.6.0/gcc/testsuite/gcc.dg/vect/fast-math-ifcvt-1.c 2011-05-15 14:16:58.000000000 +0200 @@ -0,0 +1,18 @@ +/* PR 47892 */ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_float } */ +/* { dg-require-effective-target vect_condition } */ + +void +bestseries9 (float * __restrict__ arr, int len) +{ + int i; + for (i = 0; i < len; ++i) + { + float or = arr[i]; + arr[i] = (or > 0.0f) * (2 - or * or); + } +} + +/* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ --- gcc-4.6.0/gcc/tree-if-conv.c.~1~ 2011-02-23 17:49:52.000000000 +0100 +++ gcc-4.6.0/gcc/tree-if-conv.c 2011-05-15 14:16:58.000000000 +0200 @@ -702,6 +702,22 @@ if_convertible_stmt_p (gimple stmt, VEC case GIMPLE_ASSIGN: return if_convertible_gimple_assign_stmt_p (stmt, refs); + case GIMPLE_CALL: + { + tree fndecl = gimple_call_fndecl (stmt); + if (fndecl) + { + int flags = gimple_call_flags (stmt); + if ((flags & ECF_CONST) + && !(flags & ECF_LOOPING_CONST_OR_PURE) + /* We can only vectorize some builtins at the moment, + so restrict if-conversion to those. */ + && DECL_BUILT_IN (fndecl)) + return true; + } + return false; + } + default: /* Don't know what to do with 'em so don't do anything. */ if (dump_file && (dump_flags & TDF_DETAILS))