re PR target/59390 (presence of __attribute__((target("fma"))) declaration breaks __builtin_fma)

2013-12-11  Sriraman Tallam  <tmsriram@google.com>

	PR target/59390
	* config/i386/i386.c (get_builtin): New function.
	(ix86_builtin_vectorized_function): Replace all instances of
	ix86_builtins[...] with get_builtin(...).
	(ix86_builtin_reciprocal): Ditto.

	PR target/59390
	* gcc.target/i386/pr59390.c: New test.
	* gcc.target/i386/pr59390_1.c: New test.
	* gcc.target/i386/pr59390_2.c: New test.

Tested boot-strap on all languages and test parity on x86_64 and with -m32.

From-SVN: r205904
This commit is contained in:
Sriraman Tallam 2013-12-11 20:06:46 +00:00 committed by Sriraman Tallam
parent 711df88d24
commit 2608443287
6 changed files with 142 additions and 52 deletions

View File

@ -1,3 +1,12 @@
2013-12-11 Sriraman Tallam <tmsriram@google.com>
PR target/59390
* config/i386/i386.c (get_builtin): New function.
(ix86_builtin_vectorized_function): Replace all instances of
ix86_builtins[...] with get_builtin(...).
(ix86_builtin_reciprocal): Ditto.
2013-12-11 Balaji V. Iyer <balaji.v.iyer@intel.com>
* langhooks.h (lang_hooks_for_decls): Remove lang_hooks_for_cilkplus.

View File

@ -33777,6 +33777,31 @@ addcarryx:
gcc_unreachable ();
}
/* This returns the target-specific builtin with code CODE if
current_function_decl has visibility on this builtin, which is checked
using isa flags. Returns NULL_TREE otherwise. */
static tree ix86_get_builtin (enum ix86_builtins code)
{
struct cl_target_option *opts;
tree target_tree = NULL_TREE;
/* Determine the isa flags of current_function_decl. */
if (current_function_decl)
target_tree = DECL_FUNCTION_SPECIFIC_TARGET (current_function_decl);
if (target_tree == NULL)
target_tree = target_option_default_node;
opts = TREE_TARGET_OPTION (target_tree);
if (ix86_builtins_isa[(int) code].isa & opts->x_ix86_isa_flags)
return ix86_builtin_decl (code, true);
else
return NULL_TREE;
}
/* Returns a function decl for a vectorized version of the builtin function
with builtin function code FN and the result vector type TYPE, or NULL_TREE
if it is not available. */
@ -33805,9 +33830,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == DFmode && in_mode == DFmode)
{
if (out_n == 2 && in_n == 2)
return ix86_builtins[IX86_BUILTIN_SQRTPD];
return ix86_get_builtin (IX86_BUILTIN_SQRTPD);
else if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_SQRTPD256];
return ix86_get_builtin (IX86_BUILTIN_SQRTPD256);
}
break;
@ -33815,9 +33840,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SFmode && in_mode == SFmode)
{
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_SQRTPS_NR];
return ix86_get_builtin (IX86_BUILTIN_SQRTPS_NR);
else if (out_n == 8 && in_n == 8)
return ix86_builtins[IX86_BUILTIN_SQRTPS_NR256];
return ix86_get_builtin (IX86_BUILTIN_SQRTPS_NR256);
}
break;
@ -33831,9 +33856,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SImode && in_mode == DFmode)
{
if (out_n == 4 && in_n == 2)
return ix86_builtins[IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX];
return ix86_get_builtin (IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX);
else if (out_n == 8 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX256];
return ix86_get_builtin (IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX256);
}
break;
@ -33847,9 +33872,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SImode && in_mode == SFmode)
{
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_FLOORPS_SFIX];
return ix86_get_builtin (IX86_BUILTIN_FLOORPS_SFIX);
else if (out_n == 8 && in_n == 8)
return ix86_builtins[IX86_BUILTIN_FLOORPS_SFIX256];
return ix86_get_builtin (IX86_BUILTIN_FLOORPS_SFIX256);
}
break;
@ -33863,9 +33888,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SImode && in_mode == DFmode)
{
if (out_n == 4 && in_n == 2)
return ix86_builtins[IX86_BUILTIN_CEILPD_VEC_PACK_SFIX];
return ix86_get_builtin (IX86_BUILTIN_CEILPD_VEC_PACK_SFIX);
else if (out_n == 8 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_CEILPD_VEC_PACK_SFIX256];
return ix86_get_builtin (IX86_BUILTIN_CEILPD_VEC_PACK_SFIX256);
}
break;
@ -33879,9 +33904,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SImode && in_mode == SFmode)
{
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_CEILPS_SFIX];
return ix86_get_builtin (IX86_BUILTIN_CEILPS_SFIX);
else if (out_n == 8 && in_n == 8)
return ix86_builtins[IX86_BUILTIN_CEILPS_SFIX256];
return ix86_get_builtin (IX86_BUILTIN_CEILPS_SFIX256);
}
break;
@ -33891,9 +33916,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SImode && in_mode == DFmode)
{
if (out_n == 4 && in_n == 2)
return ix86_builtins[IX86_BUILTIN_VEC_PACK_SFIX];
return ix86_get_builtin (IX86_BUILTIN_VEC_PACK_SFIX);
else if (out_n == 8 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_VEC_PACK_SFIX256];
return ix86_get_builtin (IX86_BUILTIN_VEC_PACK_SFIX256);
}
break;
@ -33903,9 +33928,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SImode && in_mode == SFmode)
{
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_CVTPS2DQ];
return ix86_get_builtin (IX86_BUILTIN_CVTPS2DQ);
else if (out_n == 8 && in_n == 8)
return ix86_builtins[IX86_BUILTIN_CVTPS2DQ256];
return ix86_get_builtin (IX86_BUILTIN_CVTPS2DQ256);
}
break;
@ -33919,9 +33944,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SImode && in_mode == DFmode)
{
if (out_n == 4 && in_n == 2)
return ix86_builtins[IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX];
return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX);
else if (out_n == 8 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX256];
return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX256);
}
break;
@ -33935,9 +33960,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SImode && in_mode == SFmode)
{
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_ROUNDPS_AZ_SFIX];
return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ_SFIX);
else if (out_n == 8 && in_n == 8)
return ix86_builtins[IX86_BUILTIN_ROUNDPS_AZ_SFIX256];
return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ_SFIX256);
}
break;
@ -33945,9 +33970,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == DFmode && in_mode == DFmode)
{
if (out_n == 2 && in_n == 2)
return ix86_builtins[IX86_BUILTIN_CPYSGNPD];
return ix86_get_builtin (IX86_BUILTIN_CPYSGNPD);
else if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_CPYSGNPD256];
return ix86_get_builtin (IX86_BUILTIN_CPYSGNPD256);
}
break;
@ -33955,9 +33980,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SFmode && in_mode == SFmode)
{
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_CPYSGNPS];
return ix86_get_builtin (IX86_BUILTIN_CPYSGNPS);
else if (out_n == 8 && in_n == 8)
return ix86_builtins[IX86_BUILTIN_CPYSGNPS256];
return ix86_get_builtin (IX86_BUILTIN_CPYSGNPS256);
}
break;
@ -33969,9 +33994,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == DFmode && in_mode == DFmode)
{
if (out_n == 2 && in_n == 2)
return ix86_builtins[IX86_BUILTIN_FLOORPD];
return ix86_get_builtin (IX86_BUILTIN_FLOORPD);
else if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_FLOORPD256];
return ix86_get_builtin (IX86_BUILTIN_FLOORPD256);
}
break;
@ -33983,9 +34008,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SFmode && in_mode == SFmode)
{
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_FLOORPS];
return ix86_get_builtin (IX86_BUILTIN_FLOORPS);
else if (out_n == 8 && in_n == 8)
return ix86_builtins[IX86_BUILTIN_FLOORPS256];
return ix86_get_builtin (IX86_BUILTIN_FLOORPS256);
}
break;
@ -33997,9 +34022,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == DFmode && in_mode == DFmode)
{
if (out_n == 2 && in_n == 2)
return ix86_builtins[IX86_BUILTIN_CEILPD];
return ix86_get_builtin (IX86_BUILTIN_CEILPD);
else if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_CEILPD256];
return ix86_get_builtin (IX86_BUILTIN_CEILPD256);
}
break;
@ -34011,9 +34036,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SFmode && in_mode == SFmode)
{
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_CEILPS];
return ix86_get_builtin (IX86_BUILTIN_CEILPS);
else if (out_n == 8 && in_n == 8)
return ix86_builtins[IX86_BUILTIN_CEILPS256];
return ix86_get_builtin (IX86_BUILTIN_CEILPS256);
}
break;
@ -34025,9 +34050,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == DFmode && in_mode == DFmode)
{
if (out_n == 2 && in_n == 2)
return ix86_builtins[IX86_BUILTIN_TRUNCPD];
return ix86_get_builtin (IX86_BUILTIN_TRUNCPD);
else if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_TRUNCPD256];
return ix86_get_builtin (IX86_BUILTIN_TRUNCPD256);
}
break;
@ -34039,9 +34064,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SFmode && in_mode == SFmode)
{
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_TRUNCPS];
return ix86_get_builtin (IX86_BUILTIN_TRUNCPS);
else if (out_n == 8 && in_n == 8)
return ix86_builtins[IX86_BUILTIN_TRUNCPS256];
return ix86_get_builtin (IX86_BUILTIN_TRUNCPS256);
}
break;
@ -34053,9 +34078,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == DFmode && in_mode == DFmode)
{
if (out_n == 2 && in_n == 2)
return ix86_builtins[IX86_BUILTIN_RINTPD];
return ix86_get_builtin (IX86_BUILTIN_RINTPD);
else if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_RINTPD256];
return ix86_get_builtin (IX86_BUILTIN_RINTPD256);
}
break;
@ -34067,9 +34092,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SFmode && in_mode == SFmode)
{
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_RINTPS];
return ix86_get_builtin (IX86_BUILTIN_RINTPS);
else if (out_n == 8 && in_n == 8)
return ix86_builtins[IX86_BUILTIN_RINTPS256];
return ix86_get_builtin (IX86_BUILTIN_RINTPS256);
}
break;
@ -34081,9 +34106,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == DFmode && in_mode == DFmode)
{
if (out_n == 2 && in_n == 2)
return ix86_builtins[IX86_BUILTIN_ROUNDPD_AZ];
return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ);
else if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_ROUNDPD_AZ256];
return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ256);
}
break;
@ -34095,9 +34120,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SFmode && in_mode == SFmode)
{
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_ROUNDPS_AZ];
return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ);
else if (out_n == 8 && in_n == 8)
return ix86_builtins[IX86_BUILTIN_ROUNDPS_AZ256];
return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ256);
}
break;
@ -34105,9 +34130,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == DFmode && in_mode == DFmode)
{
if (out_n == 2 && in_n == 2)
return ix86_builtins[IX86_BUILTIN_VFMADDPD];
return ix86_get_builtin (IX86_BUILTIN_VFMADDPD);
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_VFMADDPD256];
return ix86_get_builtin (IX86_BUILTIN_VFMADDPD256);
}
break;
@ -34115,9 +34140,9 @@ ix86_builtin_vectorized_function (tree fndecl, tree type_out,
if (out_mode == SFmode && in_mode == SFmode)
{
if (out_n == 4 && in_n == 4)
return ix86_builtins[IX86_BUILTIN_VFMADDPS];
return ix86_get_builtin (IX86_BUILTIN_VFMADDPS);
if (out_n == 8 && in_n == 8)
return ix86_builtins[IX86_BUILTIN_VFMADDPS256];
return ix86_get_builtin (IX86_BUILTIN_VFMADDPS256);
}
break;
@ -34397,7 +34422,7 @@ ix86_vectorize_builtin_gather (const_tree mem_vectype,
return NULL_TREE;
}
return ix86_builtins[code];
return ix86_get_builtin (code);
}
/* Returns a code for a target-specific builtin that implements
@ -34418,10 +34443,10 @@ ix86_builtin_reciprocal (unsigned int fn, bool md_fn,
{
/* Vectorized version of sqrt to rsqrt conversion. */
case IX86_BUILTIN_SQRTPS_NR:
return ix86_builtins[IX86_BUILTIN_RSQRTPS_NR];
return ix86_get_builtin (IX86_BUILTIN_RSQRTPS_NR);
case IX86_BUILTIN_SQRTPS_NR256:
return ix86_builtins[IX86_BUILTIN_RSQRTPS_NR256];
return ix86_get_builtin (IX86_BUILTIN_RSQRTPS_NR256);
default:
return NULL_TREE;
@ -34432,7 +34457,7 @@ ix86_builtin_reciprocal (unsigned int fn, bool md_fn,
{
/* Sqrt to rsqrt conversion. */
case BUILT_IN_SQRTF:
return ix86_builtins[IX86_BUILTIN_RSQRTF];
return ix86_get_builtin (IX86_BUILTIN_RSQRTF);
default:
return NULL_TREE;

View File

@ -1,3 +1,10 @@
2013-12-11 Sriraman Tallam <tmsriram@google.com>
PR target/59390
* gcc.target/i386/pr59390.c: New test.
* gcc.target/i386/pr59390_1.c: New test.
* gcc.target/i386/pr59390_2.c: New test.
2013-12-11 Balaji V. Iyer <balaji.v.iyer@intel.com>
* g++.dg/cilk-plus/CK/catch_exc.cc: New test case.

View File

@ -0,0 +1,16 @@
/* { dg-do compile } */
/* { dg-options "-std=c99 -O3" } */
#include "math.h"
void fun() __attribute__((target("fma")));
void
other_fun(double *restrict out, double * restrict a, double * restrict b, double * restrict c, int n)
{
int i;
for (i = 0; i < n; i++) {
out[i] = fma(a[i], b[i], c[i]);
}
}
/* { dg-final { scan-assembler-not "vfmadd" } } */

View File

@ -0,0 +1,17 @@
/* { dg-do compile } */
/* { dg-options "-std=c99 -O3" } */
#include "math.h"
void fun() __attribute__((target("fma")));
__attribute__((target("fma")))
void
other_fun(double *restrict out, double * restrict a, double * restrict b, double * restrict c, int n)
{
int i;
for (i = 0; i < n; i++) {
out[i] = fma(a[i], b[i], c[i]);
}
}
/* { dg-final { scan-assembler "vfmadd" } } */

View File

@ -0,0 +1,16 @@
/* { dg-do compile } */
/* { dg-options "-std=c99 -O3 -mfma" } */
#include "math.h"
void fun() __attribute__((target("fma")));
void
other_fun(double *restrict out, double * restrict a, double * restrict b, double * restrict c, int n)
{
int i;
for (i = 0; i < n; i++) {
out[i] = fma(a[i], b[i], c[i]);
}
}
/* { dg-final { scan-assembler "vfmadd" } } */