summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/fold-const.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/gcc/fold-const.c')
-rw-r--r--contrib/gcc/fold-const.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/contrib/gcc/fold-const.c b/contrib/gcc/fold-const.c
index b34422f..cc2698d 100644
--- a/contrib/gcc/fold-const.c
+++ b/contrib/gcc/fold-const.c
@@ -1467,33 +1467,36 @@ const_binop (enum tree_code code, tree arg1, tree arg2, int notrunc)
case RDIV_EXPR:
{
+ tree t1, t2, real, imag;
tree magsquared
= const_binop (PLUS_EXPR,
const_binop (MULT_EXPR, r2, r2, notrunc),
const_binop (MULT_EXPR, i2, i2, notrunc),
notrunc);
- t = build_complex (type,
- const_binop
- (INTEGRAL_TYPE_P (TREE_TYPE (r1))
- ? TRUNC_DIV_EXPR : RDIV_EXPR,
- const_binop (PLUS_EXPR,
- const_binop (MULT_EXPR, r1, r2,
- notrunc),
- const_binop (MULT_EXPR, i1, i2,
- notrunc),
- notrunc),
- magsquared, notrunc),
- const_binop
- (INTEGRAL_TYPE_P (TREE_TYPE (r1))
- ? TRUNC_DIV_EXPR : RDIV_EXPR,
- const_binop (MINUS_EXPR,
- const_binop (MULT_EXPR, i1, r2,
- notrunc),
- const_binop (MULT_EXPR, r1, i2,
- notrunc),
- notrunc),
- magsquared, notrunc));
+ t1 = const_binop (PLUS_EXPR,
+ const_binop (MULT_EXPR, r1, r2, notrunc),
+ const_binop (MULT_EXPR, i1, i2, notrunc),
+ notrunc);
+ t2 = const_binop (MINUS_EXPR,
+ const_binop (MULT_EXPR, i1, r2, notrunc),
+ const_binop (MULT_EXPR, r1, i2, notrunc),
+ notrunc);
+
+ if (INTEGRAL_TYPE_P (TREE_TYPE (r1)))
+ {
+ real = const_binop (TRUNC_DIV_EXPR, t1, magsquared, notrunc);
+ imag = const_binop (TRUNC_DIV_EXPR, t2, magsquared, notrunc);
+ }
+ else
+ {
+ real = const_binop (RDIV_EXPR, t1, magsquared, notrunc);
+ imag = const_binop (RDIV_EXPR, t2, magsquared, notrunc);
+ if (!real || !imag)
+ return NULL_TREE;
+ }
+
+ t = build_complex (type, real, imag);
}
break;
@@ -7497,6 +7500,8 @@ fold (tree expr)
else if (TREE_CODE (TREE_TYPE (arg0)) == INTEGER_TYPE
&& TREE_CODE (arg0) == NOP_EXPR
&& (tem = get_unwidened (arg0, NULL_TREE)) != arg0
+ && (TYPE_PRECISION (TREE_TYPE (tem))
+ > TYPE_PRECISION (TREE_TYPE (arg0)))
&& (code == EQ_EXPR || code == NE_EXPR
|| TREE_UNSIGNED (TREE_TYPE (arg0))
== TREE_UNSIGNED (TREE_TYPE (tem)))
@@ -8137,7 +8142,12 @@ fold (tree expr)
if (INTEGRAL_TYPE_P (type)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
- && TREE_CODE (arg2) == INTEGER_CST)
+ && TREE_CODE (arg2) == INTEGER_CST
+ /* ??? We somehow can end up here with
+ (unsigned int)1 == 1 ? 1U : 2U
+ for which we won't make any progress but recurse
+ indefinitely. Just stop here in this case. */
+ && TREE_CODE (arg1) != INTEGER_CST)
switch (comp_code)
{
case EQ_EXPR:
@@ -8194,8 +8204,9 @@ fold (tree expr)
/* If the second operand is simpler than the third, swap them
since that produces better jump optimization results. */
- if (tree_swap_operands_p (TREE_OPERAND (t, 1),
- TREE_OPERAND (t, 2), false))
+ if (truth_value_p (TREE_CODE (arg0))
+ && tree_swap_operands_p (TREE_OPERAND (t, 1),
+ TREE_OPERAND (t, 2), false))
{
/* See if this can be inverted. If it can't, possibly because
it was a floating-point inequality comparison, don't do
@@ -8431,7 +8442,7 @@ fold_checksum_tree (tree expr, struct md5_ctx *ctx, htab_t ht)
{
void **slot;
enum tree_code code;
- char buf[sizeof (struct tree_decl)];
+ struct tree_decl buf;
int i, len;
if (sizeof (struct tree_exp) + 5 * sizeof (tree)
@@ -8448,23 +8459,23 @@ fold_checksum_tree (tree expr, struct md5_ctx *ctx, htab_t ht)
if (code == SAVE_EXPR && SAVE_EXPR_NOPLACEHOLDER (expr))
{
/* Allow SAVE_EXPR_NOPLACEHOLDER flag to be modified. */
- memcpy (buf, expr, tree_size (expr));
- expr = (tree) buf;
+ memcpy (&buf, expr, tree_size (expr));
+ expr = (tree) &buf;
SAVE_EXPR_NOPLACEHOLDER (expr) = 0;
}
else if (TREE_CODE_CLASS (code) == 'd' && DECL_ASSEMBLER_NAME_SET_P (expr))
{
/* Allow DECL_ASSEMBLER_NAME to be modified. */
- memcpy (buf, expr, tree_size (expr));
- expr = (tree) buf;
+ memcpy (&buf, expr, tree_size (expr));
+ expr = (tree) &buf;
SET_DECL_ASSEMBLER_NAME (expr, NULL);
}
else if (TREE_CODE_CLASS (code) == 't'
&& (TYPE_POINTER_TO (expr) || TYPE_REFERENCE_TO (expr)))
{
/* Allow TYPE_POINTER_TO and TYPE_REFERENCE_TO to be modified. */
- memcpy (buf, expr, tree_size (expr));
- expr = (tree) buf;
+ memcpy (&buf, expr, tree_size (expr));
+ expr = (tree) &buf;
TYPE_POINTER_TO (expr) = NULL;
TYPE_REFERENCE_TO (expr) = NULL;
}
OpenPOWER on IntegriCloud