re PR tree-optimization/49963 (ICE: in abs_hwi, at hwint.c:108)

2011-08-18  Paolo Carlini  <paolo.carlini@oracle.com>
	    Joseph Myers  <joseph@codesourcery.com>

	PR tree-optimization/49963
	* hwint.c (absu_hwi): Define.
	* hwint.h (absu_hwi): Declare.
	* fold-const.c (fold_plusminus_mult_expr): Use absu_hwi instead
	of abs_hwi.
	* tree-ssa-math-opts.c (gimple_expand_builtin_pow): Likewise.
	* tree-ssa-loop-prefetch.c (prune_ref_by_group_reuse): Likewise.

Co-Authored-By: Joseph Myers <joseph@codesourcery.com>

From-SVN: r177848
This commit is contained in:
Paolo Carlini 2011-08-18 11:30:42 +00:00 committed by Paolo Carlini
parent 97919ae7b6
commit 4c9cf7af89
6 changed files with 28 additions and 8 deletions

View File

@ -1,3 +1,14 @@
2011-08-18 Paolo Carlini <paolo.carlini@oracle.com>
Joseph Myers <joseph@codesourcery.com>
PR tree-optimization/49963
* hwint.c (absu_hwi): Define.
* hwint.h (absu_hwi): Declare.
* fold-const.c (fold_plusminus_mult_expr): Use absu_hwi instead
of abs_hwi.
* tree-ssa-math-opts.c (gimple_expand_builtin_pow): Likewise.
* tree-ssa-loop-prefetch.c (prune_ref_by_group_reuse): Likewise.
2011-08-18 Richard Guenther <rguenther@suse.de>
* expr.c (get_inner_reference): Sign-extend the constant

View File

@ -7036,7 +7036,7 @@ fold_plusminus_mult_expr (location_t loc, enum tree_code code, tree type,
int11 = TREE_INT_CST_LOW (arg11);
/* Move min of absolute values to int11. */
if (abs_hwi (int01) < abs_hwi (int11))
if (absu_hwi (int01) < absu_hwi (int11))
{
tmp = int01, int01 = int11, int11 = tmp;
alt0 = arg00, arg00 = arg10, arg10 = alt0;
@ -7046,7 +7046,7 @@ fold_plusminus_mult_expr (location_t loc, enum tree_code code, tree type,
else
maybe_same = arg11;
if (exact_log2 (abs_hwi (int11)) > 0 && int01 % int11 == 0
if (exact_log2 (absu_hwi (int11)) > 0 && int01 % int11 == 0
/* The remainder should not be a constant, otherwise we
end up folding i * 4 + 2 to (i * 2 + 1) * 2 which has
increased the number of multiplications necessary. */

View File

@ -109,6 +109,14 @@ abs_hwi (HOST_WIDE_INT x)
return x >= 0 ? x : -x;
}
/* Compute the absolute value of X as an unsigned type. */
unsigned HOST_WIDE_INT
absu_hwi (HOST_WIDE_INT x)
{
return x >= 0 ? (unsigned HOST_WIDE_INT)x : -(unsigned HOST_WIDE_INT)x;
}
/* Compute the greatest common divisor of two numbers A and B using
Euclid's algorithm. */

View File

@ -233,6 +233,7 @@ exact_log2 (unsigned HOST_WIDE_INT x)
#define HOST_WIDE_INT_MAX (~(HOST_WIDE_INT_MIN))
extern HOST_WIDE_INT abs_hwi (HOST_WIDE_INT);
extern unsigned HOST_WIDE_INT absu_hwi (HOST_WIDE_INT);
extern HOST_WIDE_INT gcd (HOST_WIDE_INT, HOST_WIDE_INT);
extern HOST_WIDE_INT pos_mul_hwi (HOST_WIDE_INT, HOST_WIDE_INT);
extern HOST_WIDE_INT mul_hwi (HOST_WIDE_INT, HOST_WIDE_INT);

View File

@ -795,7 +795,7 @@ prune_ref_by_group_reuse (struct mem_ref *ref, struct mem_ref *by,
prefetch_before = (hit_from - delta_r + step - 1) / step;
/* Do not reduce prefetch_before if we meet beyond cache size. */
if (prefetch_before > (unsigned) abs_hwi (L2_CACHE_SIZE_BYTES / step))
if (prefetch_before > absu_hwi (L2_CACHE_SIZE_BYTES / step))
prefetch_before = PREFETCH_ALL;
if (prefetch_before < ref->prefetch_before)
ref->prefetch_before = prefetch_before;

View File

@ -1231,7 +1231,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
/* Attempt to fold powi(arg0, abs(n/2)) into multiplies. If not
possible or profitable, give up. Skip the degenerate case when
n is 1 or -1, where the result is always 1. */
if (abs_hwi (n) != 1)
if (absu_hwi (n) != 1)
{
powi_x_ndiv2 = gimple_expand_builtin_powi (gsi, loc, arg0,
abs_hwi (n / 2));
@ -1243,7 +1243,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
result of the optimal multiply sequence just calculated. */
sqrt_arg0 = build_and_insert_call (gsi, loc, &target, sqrtfn, arg0);
if (abs_hwi (n) == 1)
if (absu_hwi (n) == 1)
result = sqrt_arg0;
else
result = build_and_insert_binop (gsi, loc, target, MULT_EXPR,
@ -1285,7 +1285,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
/* Attempt to fold powi(arg0, abs(n/3)) into multiplies. If not
possible or profitable, give up. Skip the degenerate case when
abs(n) < 3, where the result is always 1. */
if (abs_hwi (n) >= 3)
if (absu_hwi (n) >= 3)
{
powi_x_ndiv3 = gimple_expand_builtin_powi (gsi, loc, arg0,
abs_hwi (n / 3));
@ -1298,14 +1298,14 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
either cbrt(x) or cbrt(x) * cbrt(x). */
cbrt_x = build_and_insert_call (gsi, loc, &target, cbrtfn, arg0);
if (abs_hwi (n) % 3 == 1)
if (absu_hwi (n) % 3 == 1)
powi_cbrt_x = cbrt_x;
else
powi_cbrt_x = build_and_insert_binop (gsi, loc, target, MULT_EXPR,
cbrt_x, cbrt_x);
/* Multiply the two subexpressions, unless powi(x,abs(n)/3) = 1. */
if (abs_hwi (n) < 3)
if (absu_hwi (n) < 3)
result = powi_cbrt_x;
else
result = build_and_insert_binop (gsi, loc, target, MULT_EXPR,