+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
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;
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. */
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. */
#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);
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;
/* 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));
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,
/* 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));
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,