Commit 79af7c1f by Michael Matz Committed by Michael Matz

re PR middle-end/41963 (177.mesa in SPEC CPU 2K is miscompiled)

	PR middle-end/41963
	* tree-ssa-math-opts.c (execute_cse_reciprocals): Check all uses
	of a potential reciprocal to really be reciprocals.

testsuite/
	* gcc.dg/pr41963.c: New test.

From-SVN: r153971
parent 9cd4e79b
2009-11-06 Michael Matz <matz@suse.de>
PR middle-end/41963
* tree-ssa-math-opts.c (execute_cse_reciprocals): Check all uses
of a potential reciprocal to really be reciprocals.
2009-11-06 Jakub Jelinek <jakub@redhat.com> 2009-11-06 Jakub Jelinek <jakub@redhat.com>
* config/i386/x86intrin.h: Include fma4intrin.h, xopintrin.h and * config/i386/x86intrin.h: Include fma4intrin.h, xopintrin.h and
2009-11-06 Michael Matz <matz@suse.de>
PR middle-end/41963
* gcc.dg/pr41963.c: New test.
2009-11-06 Jakub Jelinek <jakub@redhat.com> 2009-11-06 Jakub Jelinek <jakub@redhat.com>
PR middle-end/41935 PR middle-end/41935
......
/* { dg-do run } */
/* { dg-options "-O2 -ffast-math" } */
#include <math.h>
extern float sqrtf(float);
static __attribute__((noinline)) void f (float *dst, float *src)
{
int i, j;
for (i = 0; i < 2; i++)
{
float len;
dst[0] = src[0];
dst[1] = src[1];
len = sqrtf (dst[0] * dst[0] + dst[1] * dst[1]);
if (len > 0.5f)
{
len = 1.0f / len;
dst[0] *= len;
dst[1] *= len;
}
}
}
extern void abort (void);
int main()
{
float dst[2], src[2];
src[0] = 2.0f;
src[1] = 5.0f;
f (dst, src);
if (fabsf (dst[0] * dst[0] + dst[1] * dst[1] - 1.0f) > 0.01f)
abort ();
return 0;
}
...@@ -531,7 +531,9 @@ execute_cse_reciprocals (void) ...@@ -531,7 +531,9 @@ execute_cse_reciprocals (void)
|| DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)) || DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD))
{ {
enum built_in_function code; enum built_in_function code;
bool md_code; bool md_code, fail;
imm_use_iterator ui;
use_operand_p use_p;
code = DECL_FUNCTION_CODE (fndecl); code = DECL_FUNCTION_CODE (fndecl);
md_code = DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD; md_code = DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD;
...@@ -540,12 +542,36 @@ execute_cse_reciprocals (void) ...@@ -540,12 +542,36 @@ execute_cse_reciprocals (void)
if (!fndecl) if (!fndecl)
continue; continue;
/* Check that all uses of the SSA name are divisions,
otherwise replacing the defining statement will do
the wrong thing. */
fail = false;
FOR_EACH_IMM_USE_FAST (use_p, ui, arg1)
{
gimple stmt2 = USE_STMT (use_p);
if (is_gimple_debug (stmt2))
continue;
if (!is_gimple_assign (stmt2)
|| gimple_assign_rhs_code (stmt2) != RDIV_EXPR
|| gimple_assign_rhs1 (stmt2) == arg1
|| gimple_assign_rhs2 (stmt2) != arg1)
{
fail = true;
break;
}
}
if (fail)
continue;
gimple_call_set_fndecl (stmt1, fndecl); gimple_call_set_fndecl (stmt1, fndecl);
update_stmt (stmt1); update_stmt (stmt1);
gimple_assign_set_rhs_code (stmt, MULT_EXPR); FOR_EACH_IMM_USE_STMT (stmt, ui, arg1)
fold_stmt_inplace (stmt); {
update_stmt (stmt); gimple_assign_set_rhs_code (stmt, MULT_EXPR);
fold_stmt_inplace (stmt);
update_stmt (stmt);
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment