#include "config.h"
#include "system.h"
#include "flags.h"
#include "tree.h"
#include "real.h"
#include "rtl.h"
#include "expr.h"
#include "tm_p.h"
#include "toplev.h"
#include "ggc.h"
#include "hashtab.h"
#include "langhooks.h"
static void encode PARAMS ((HOST_WIDE_INT *,
unsigned HOST_WIDE_INT,
HOST_WIDE_INT));
static void decode PARAMS ((HOST_WIDE_INT *,
unsigned HOST_WIDE_INT *,
HOST_WIDE_INT *));
static tree negate_expr PARAMS ((tree));
static tree split_tree PARAMS ((tree, enum tree_code, tree *, tree *,
tree *, int));
static tree associate_trees PARAMS ((tree, tree, enum tree_code, tree));
static tree int_const_binop PARAMS ((enum tree_code, tree, tree, int));
static tree const_binop PARAMS ((enum tree_code, tree, tree, int));
static hashval_t size_htab_hash PARAMS ((const void *));
static int size_htab_eq PARAMS ((const void *, const void *));
static tree fold_convert PARAMS ((tree, tree));
static enum tree_code invert_tree_comparison PARAMS ((enum tree_code));
static enum tree_code swap_tree_comparison PARAMS ((enum tree_code));
static int comparison_to_compcode PARAMS ((enum tree_code));
static enum tree_code compcode_to_comparison PARAMS ((int));
static int truth_value_p PARAMS ((enum tree_code));
static int operand_equal_for_comparison_p PARAMS ((tree, tree, tree));
static int twoval_comparison_p PARAMS ((tree, tree *, tree *, int *));
static tree eval_subst PARAMS ((tree, tree, tree, tree, tree));
static tree omit_one_operand PARAMS ((tree, tree, tree));
static tree pedantic_omit_one_operand PARAMS ((tree, tree, tree));
static tree distribute_bit_expr PARAMS ((enum tree_code, tree, tree, tree));
static tree make_bit_field_ref PARAMS ((tree, tree, int, int, int));
static tree optimize_bit_field_compare PARAMS ((enum tree_code, tree,
tree, tree));
static tree decode_field_reference PARAMS ((tree, HOST_WIDE_INT *,
HOST_WIDE_INT *,
enum machine_mode *, int *,
int *, tree *, tree *));
static int all_ones_mask_p PARAMS ((tree, int));
static tree sign_bit_p PARAMS ((tree, tree));
static int simple_operand_p PARAMS ((tree));
static tree range_binop PARAMS ((enum tree_code, tree, tree, int,
tree, int));
static tree make_range PARAMS ((tree, int *, tree *, tree *));
static tree build_range_check PARAMS ((tree, tree, int, tree, tree));
static int merge_ranges PARAMS ((int *, tree *, tree *, int, tree, tree,
int, tree, tree));
static tree fold_range_test PARAMS ((tree));
static tree unextend PARAMS ((tree, int, int, tree));
static tree fold_truthop PARAMS ((enum tree_code, tree, tree, tree));
static tree optimize_minmax_comparison PARAMS ((tree));
static tree extract_muldiv PARAMS ((tree, tree, enum tree_code, tree));
static tree extract_muldiv_1 PARAMS ((tree, tree, enum tree_code, tree));
static tree strip_compound_expr PARAMS ((tree, tree));
static int multiple_of_p PARAMS ((tree, tree, tree));
static tree constant_boolean_node PARAMS ((int, tree));
static int count_cond PARAMS ((tree, int));
static tree fold_binary_op_with_conditional_arg
PARAMS ((enum tree_code, tree, tree, tree, int));
static bool fold_real_zero_addition_p PARAMS ((tree, tree, int));
#define COMPCODE_FALSE 0
#define COMPCODE_LT 1
#define COMPCODE_EQ 2
#define COMPCODE_LE 3
#define COMPCODE_GT 4
#define COMPCODE_NE 5
#define COMPCODE_GE 6
#define COMPCODE_TRUE 7
#define OVERFLOW_SUM_SIGN(a, b, sum) ((~((a) ^ (b)) & ((a) ^ (sum))) < 0)
#define LOWPART(x) \
((x) & (((unsigned HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)) - 1))
#define HIGHPART(x) \
((unsigned HOST_WIDE_INT) (x) >> HOST_BITS_PER_WIDE_INT / 2)
#define BASE ((unsigned HOST_WIDE_INT) 1 << HOST_BITS_PER_WIDE_INT / 2)
static void
encode (words, low, hi)
HOST_WIDE_INT *words;
unsigned HOST_WIDE_INT low;
HOST_WIDE_INT hi;
{
words[0] = LOWPART (low);
words[1] = HIGHPART (low);
words[2] = LOWPART (hi);
words[3] = HIGHPART (hi);
}
static void
decode (words, low, hi)
HOST_WIDE_INT *words;
unsigned HOST_WIDE_INT *low;
HOST_WIDE_INT *hi;
{
*low = words[0] + words[1] * BASE;
*hi = words[2] + words[3] * BASE;
}
int
force_fit_type (t, overflow)
tree t;
int overflow;
{
unsigned HOST_WIDE_INT low;
HOST_WIDE_INT high;
unsigned int prec;
if (TREE_CODE (t) == REAL_CST)
{
return overflow;
}
else if (TREE_CODE (t) != INTEGER_CST)
return overflow;
low = TREE_INT_CST_LOW (t);
high = TREE_INT_CST_HIGH (t);
if (POINTER_TYPE_P (TREE_TYPE (t)))
prec = POINTER_SIZE;
else
prec = TYPE_PRECISION (TREE_TYPE (t));
if (prec == 2 * HOST_BITS_PER_WIDE_INT)
;
else if (prec > HOST_BITS_PER_WIDE_INT)
TREE_INT_CST_HIGH (t)
&= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
else
{
TREE_INT_CST_HIGH (t) = 0;
if (prec < HOST_BITS_PER_WIDE_INT)
TREE_INT_CST_LOW (t) &= ~((unsigned HOST_WIDE_INT) (-1) << prec);
}
if (TREE_UNSIGNED (TREE_TYPE (t))
&& ! (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE
&& TYPE_IS_SIZETYPE (TREE_TYPE (t))))
return overflow;
if (prec != 2 * HOST_BITS_PER_WIDE_INT
&& (prec > HOST_BITS_PER_WIDE_INT
? 0 != (TREE_INT_CST_HIGH (t)
& ((HOST_WIDE_INT) 1
<< (prec - HOST_BITS_PER_WIDE_INT - 1)))
: 0 != (TREE_INT_CST_LOW (t)
& ((unsigned HOST_WIDE_INT) 1 << (prec - 1)))))
{
if (prec > HOST_BITS_PER_WIDE_INT)
TREE_INT_CST_HIGH (t)
|= ((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
else
{
TREE_INT_CST_HIGH (t) = -1;
if (prec < HOST_BITS_PER_WIDE_INT)
TREE_INT_CST_LOW (t) |= ((unsigned HOST_WIDE_INT) (-1) << prec);
}
}
return
((overflow | (low ^ TREE_INT_CST_LOW (t)) | (high ^ TREE_INT_CST_HIGH (t)))
!= 0);
}
int
add_double (l1, h1, l2, h2, lv, hv)
unsigned HOST_WIDE_INT l1, l2;
HOST_WIDE_INT h1, h2;
unsigned HOST_WIDE_INT *lv;
HOST_WIDE_INT *hv;
{
unsigned HOST_WIDE_INT l;
HOST_WIDE_INT h;
l = l1 + l2;
h = h1 + h2 + (l < l1);
*lv = l;
*hv = h;
return OVERFLOW_SUM_SIGN (h1, h2, h);
}
int
neg_double (l1, h1, lv, hv)
unsigned HOST_WIDE_INT l1;
HOST_WIDE_INT h1;
unsigned HOST_WIDE_INT *lv;
HOST_WIDE_INT *hv;
{
if (l1 == 0)
{
*lv = 0;
*hv = - h1;
return (*hv & h1) < 0;
}
else
{
*lv = -l1;
*hv = ~h1;
return 0;
}
}
int
mul_double (l1, h1, l2, h2, lv, hv)
unsigned HOST_WIDE_INT l1, l2;
HOST_WIDE_INT h1, h2;
unsigned HOST_WIDE_INT *lv;
HOST_WIDE_INT *hv;
{
HOST_WIDE_INT arg1[4];
HOST_WIDE_INT arg2[4];
HOST_WIDE_INT prod[4 * 2];
unsigned HOST_WIDE_INT carry;
int i, j, k;
unsigned HOST_WIDE_INT toplow, neglow;
HOST_WIDE_INT tophigh, neghigh;
encode (arg1, l1, h1);
encode (arg2, l2, h2);
memset ((char *) prod, 0, sizeof prod);
for (i = 0; i < 4; i++)
{
carry = 0;
for (j = 0; j < 4; j++)
{
k = i + j;
carry += arg1[i] * arg2[j];
carry += prod[k];
prod[k] = LOWPART (carry);
carry = HIGHPART (carry);
}
prod[i + 4] = carry;
}
decode (prod, lv, hv);
decode (prod + 4, &toplow, &tophigh);
if (h1 < 0)
{
neg_double (l2, h2, &neglow, &neghigh);
add_double (neglow, neghigh, toplow, tophigh, &toplow, &tophigh);
}
if (h2 < 0)
{
neg_double (l1, h1, &neglow, &neghigh);
add_double (neglow, neghigh, toplow, tophigh, &toplow, &tophigh);
}
return (*hv < 0 ? ~(toplow & tophigh) : toplow | tophigh) != 0;
}
void
lshift_double (l1, h1, count, prec, lv, hv, arith)
unsigned HOST_WIDE_INT l1;
HOST_WIDE_INT h1, count;
unsigned int prec;
unsigned HOST_WIDE_INT *lv;
HOST_WIDE_INT *hv;
int arith;
{
unsigned HOST_WIDE_INT signmask;
if (count < 0)
{
rshift_double (l1, h1, -count, prec, lv, hv, arith);
return;
}
#ifdef SHIFT_COUNT_TRUNCATED
if (SHIFT_COUNT_TRUNCATED)
count %= prec;
#endif
if (count >= 2 * HOST_BITS_PER_WIDE_INT)
{
*hv = 0;
*lv = 0;
}
else if (count >= HOST_BITS_PER_WIDE_INT)
{
*hv = l1 << (count - HOST_BITS_PER_WIDE_INT);
*lv = 0;
}
else
{
*hv = (((unsigned HOST_WIDE_INT) h1 << count)
| (l1 >> (HOST_BITS_PER_WIDE_INT - count - 1) >> 1));
*lv = l1 << count;
}
signmask = -((prec > HOST_BITS_PER_WIDE_INT
? ((unsigned HOST_WIDE_INT) *hv
>> (prec - HOST_BITS_PER_WIDE_INT - 1))
: (*lv >> (prec - 1))) & 1);
if (prec >= 2 * HOST_BITS_PER_WIDE_INT)
;
else if (prec >= HOST_BITS_PER_WIDE_INT)
{
*hv &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
*hv |= signmask << (prec - HOST_BITS_PER_WIDE_INT);
}
else
{
*hv = signmask;
*lv &= ~((unsigned HOST_WIDE_INT) (-1) << prec);
*lv |= signmask << prec;
}
}
void
rshift_double (l1, h1, count, prec, lv, hv, arith)
unsigned HOST_WIDE_INT l1;
HOST_WIDE_INT h1, count;
unsigned int prec;
unsigned HOST_WIDE_INT *lv;
HOST_WIDE_INT *hv;
int arith;
{
unsigned HOST_WIDE_INT signmask;
signmask = (arith
? -((unsigned HOST_WIDE_INT) h1 >> (HOST_BITS_PER_WIDE_INT - 1))
: 0);
#ifdef SHIFT_COUNT_TRUNCATED
if (SHIFT_COUNT_TRUNCATED)
count %= prec;
#endif
if (count >= 2 * HOST_BITS_PER_WIDE_INT)
{
*hv = 0;
*lv = 0;
}
else if (count >= HOST_BITS_PER_WIDE_INT)
{
*hv = 0;
*lv = (unsigned HOST_WIDE_INT) h1 >> (count - HOST_BITS_PER_WIDE_INT);
}
else
{
*hv = (unsigned HOST_WIDE_INT) h1 >> count;
*lv = ((l1 >> count)
| ((unsigned HOST_WIDE_INT) h1 << (HOST_BITS_PER_WIDE_INT - count - 1) << 1));
}
if (count >= (HOST_WIDE_INT)prec)
{
*hv = signmask;
*lv = signmask;
}
else if ((prec - count) >= 2 * HOST_BITS_PER_WIDE_INT)
;
else if ((prec - count) >= HOST_BITS_PER_WIDE_INT)
{
*hv &= ~((HOST_WIDE_INT) (-1) << (prec - count - HOST_BITS_PER_WIDE_INT));
*hv |= signmask << (prec - count - HOST_BITS_PER_WIDE_INT);
}
else
{
*hv = signmask;
*lv &= ~((unsigned HOST_WIDE_INT) (-1) << (prec - count));
*lv |= signmask << (prec - count);
}
}
void
lrotate_double (l1, h1, count, prec, lv, hv)
unsigned HOST_WIDE_INT l1;
HOST_WIDE_INT h1, count;
unsigned int prec;
unsigned HOST_WIDE_INT *lv;
HOST_WIDE_INT *hv;
{
unsigned HOST_WIDE_INT s1l, s2l;
HOST_WIDE_INT s1h, s2h;
count %= prec;
if (count < 0)
count += prec;
lshift_double (l1, h1, count, prec, &s1l, &s1h, 0);
rshift_double (l1, h1, prec - count, prec, &s2l, &s2h, 0);
*lv = s1l | s2l;
*hv = s1h | s2h;
}
void
rrotate_double (l1, h1, count, prec, lv, hv)
unsigned HOST_WIDE_INT l1;
HOST_WIDE_INT h1, count;
unsigned int prec;
unsigned HOST_WIDE_INT *lv;
HOST_WIDE_INT *hv;
{
unsigned HOST_WIDE_INT s1l, s2l;
HOST_WIDE_INT s1h, s2h;
count %= prec;
if (count < 0)
count += prec;
rshift_double (l1, h1, count, prec, &s1l, &s1h, 0);
lshift_double (l1, h1, prec - count, prec, &s2l, &s2h, 0);
*lv = s1l | s2l;
*hv = s1h | s2h;
}
int
div_and_round_double (code, uns,
lnum_orig, hnum_orig, lden_orig, hden_orig,
lquo, hquo, lrem, hrem)
enum tree_code code;
int uns;
unsigned HOST_WIDE_INT lnum_orig;
HOST_WIDE_INT hnum_orig;
unsigned HOST_WIDE_INT lden_orig;
HOST_WIDE_INT hden_orig;
unsigned HOST_WIDE_INT *lquo, *lrem;
HOST_WIDE_INT *hquo, *hrem;
{
int quo_neg = 0;
HOST_WIDE_INT num[4 + 1];
HOST_WIDE_INT den[4], quo[4];
int i, j;
unsigned HOST_WIDE_INT work;
unsigned HOST_WIDE_INT carry = 0;
unsigned HOST_WIDE_INT lnum = lnum_orig;
HOST_WIDE_INT hnum = hnum_orig;
unsigned HOST_WIDE_INT lden = lden_orig;
HOST_WIDE_INT hden = hden_orig;
int overflow = 0;
if (hden == 0 && lden == 0)
overflow = 1, lden = 1;
if (!uns)
{
if (hnum < 0)
{
quo_neg = ~ quo_neg;
if (neg_double (lnum, hnum, &lnum, &hnum)
&& ((HOST_WIDE_INT) lden & hden) == -1)
overflow = 1;
}
if (hden < 0)
{
quo_neg = ~ quo_neg;
neg_double (lden, hden, &lden, &hden);
}
}
if (hnum == 0 && hden == 0)
{
*hquo = *hrem = 0;
*lquo = lnum / lden;
goto finish_up;
}
if (hnum == 0)
{
*hquo = *lquo = 0;
*hrem = hnum;
*lrem = lnum;
goto finish_up;
}
memset ((char *) quo, 0, sizeof quo);
memset ((char *) num, 0, sizeof num);
memset ((char *) den, 0, sizeof den);
encode (num, lnum, hnum);
encode (den, lden, hden);
if (hden == 0 && lden < (unsigned HOST_WIDE_INT) BASE)
{
for (i = 4 - 1; i >= 0; i--)
{
work = num[i] + carry * BASE;
quo[i] = work / lden;
carry = work % lden;
}
}
else
{
int num_hi_sig, den_hi_sig;
unsigned HOST_WIDE_INT quo_est, scale;
for (i = 4 - 1;; i--)
if (den[i] != 0)
{
den_hi_sig = i;
break;
}
scale = BASE / (den[den_hi_sig] + 1);
if (scale > 1)
{
carry = 0;
for (i = 0; i <= 4 - 1; i++)
{
work = (num[i] * scale) + carry;
num[i] = LOWPART (work);
carry = HIGHPART (work);
}
num[4] = carry;
carry = 0;
for (i = 0; i <= 4 - 1; i++)
{
work = (den[i] * scale) + carry;
den[i] = LOWPART (work);
carry = HIGHPART (work);
if (den[i] != 0) den_hi_sig = i;
}
}
num_hi_sig = 4;
for (i = num_hi_sig - den_hi_sig - 1; i >= 0; i--)
{
unsigned HOST_WIDE_INT tmp;
num_hi_sig = i + den_hi_sig + 1;
work = num[num_hi_sig] * BASE + num[num_hi_sig - 1];
if (num[num_hi_sig] != den[den_hi_sig])
quo_est = work / den[den_hi_sig];
else
quo_est = BASE - 1;
tmp = work - quo_est * den[den_hi_sig];
if (tmp < BASE
&& (den[den_hi_sig - 1] * quo_est
> (tmp * BASE + num[num_hi_sig - 2])))
quo_est--;
carry = 0;
for (j = 0; j <= den_hi_sig; j++)
{
work = quo_est * den[j] + carry;
carry = HIGHPART (work);
work = num[i + j] - LOWPART (work);
num[i + j] = LOWPART (work);
carry += HIGHPART (work) != 0;
}
if (num[num_hi_sig] < (HOST_WIDE_INT) carry)
{
quo_est--;
carry = 0;
for (j = 0; j <= den_hi_sig; j++)
{
work = num[i + j] + den[j] + carry;
carry = HIGHPART (work);
num[i + j] = LOWPART (work);
}
num [num_hi_sig] += carry;
}
quo[i] = quo_est;
}
}
decode (quo, lquo, hquo);
finish_up:
if (quo_neg)
neg_double (*lquo, *hquo, lquo, hquo);
mul_double (*lquo, *hquo, lden_orig, hden_orig, lrem, hrem);
neg_double (*lrem, *hrem, lrem, hrem);
add_double (lnum_orig, hnum_orig, *lrem, *hrem, lrem, hrem);
switch (code)
{
case TRUNC_DIV_EXPR:
case TRUNC_MOD_EXPR:
case EXACT_DIV_EXPR:
return overflow;
case FLOOR_DIV_EXPR:
case FLOOR_MOD_EXPR:
if (quo_neg && (*lrem != 0 || *hrem != 0))
{
add_double (*lquo, *hquo, (HOST_WIDE_INT) -1, (HOST_WIDE_INT) -1,
lquo, hquo);
}
else
return overflow;
break;
case CEIL_DIV_EXPR:
case CEIL_MOD_EXPR:
if (!quo_neg && (*lrem != 0 || *hrem != 0))
{
add_double (*lquo, *hquo, (HOST_WIDE_INT) 1, (HOST_WIDE_INT) 0,
lquo, hquo);
}
else
return overflow;
break;
case ROUND_DIV_EXPR:
case ROUND_MOD_EXPR:
{
unsigned HOST_WIDE_INT labs_rem = *lrem;
HOST_WIDE_INT habs_rem = *hrem;
unsigned HOST_WIDE_INT labs_den = lden, ltwice;
HOST_WIDE_INT habs_den = hden, htwice;
if (*hrem < 0)
neg_double (*lrem, *hrem, &labs_rem, &habs_rem);
if (hden < 0)
neg_double (lden, hden, &labs_den, &habs_den);
mul_double ((HOST_WIDE_INT) 2, (HOST_WIDE_INT) 0,
labs_rem, habs_rem, <wice, &htwice);
if (((unsigned HOST_WIDE_INT) habs_den
< (unsigned HOST_WIDE_INT) htwice)
|| (((unsigned HOST_WIDE_INT) habs_den
== (unsigned HOST_WIDE_INT) htwice)
&& (labs_den < ltwice)))
{
if (*hquo < 0)
add_double (*lquo, *hquo,
(HOST_WIDE_INT) -1, (HOST_WIDE_INT) -1, lquo, hquo);
else
add_double (*lquo, *hquo, (HOST_WIDE_INT) 1, (HOST_WIDE_INT) 0,
lquo, hquo);
}
else
return overflow;
}
break;
default:
abort ();
}
mul_double (*lquo, *hquo, lden_orig, hden_orig, lrem, hrem);
neg_double (*lrem, *hrem, lrem, hrem);
add_double (lnum_orig, hnum_orig, *lrem, *hrem, lrem, hrem);
return overflow;
}
static tree
negate_expr (t)
tree t;
{
tree type;
tree tem;
if (t == 0)
return 0;
type = TREE_TYPE (t);
STRIP_SIGN_NOPS (t);
switch (TREE_CODE (t))
{
case INTEGER_CST:
case REAL_CST:
if (! TREE_UNSIGNED (type)
&& 0 != (tem = fold (build1 (NEGATE_EXPR, type, t)))
&& ! TREE_OVERFLOW (tem))
return tem;
break;
case NEGATE_EXPR:
return convert (type, TREE_OPERAND (t, 0));
case MINUS_EXPR:
if (! FLOAT_TYPE_P (type) || flag_unsafe_math_optimizations)
return convert (type,
fold (build (MINUS_EXPR, TREE_TYPE (t),
TREE_OPERAND (t, 1),
TREE_OPERAND (t, 0))));
break;
default:
break;
}
return convert (type, fold (build1 (NEGATE_EXPR, TREE_TYPE (t), t)));
}
static tree
split_tree (in, code, conp, litp, minus_litp, negate_p)
tree in;
enum tree_code code;
tree *conp, *litp, *minus_litp;
int negate_p;
{
tree var = 0;
*conp = 0;
*litp = 0;
*minus_litp = 0;
STRIP_SIGN_NOPS (in);
if (TREE_CODE (in) == INTEGER_CST || TREE_CODE (in) == REAL_CST)
*litp = in;
else if (TREE_CODE (in) == code
|| (! FLOAT_TYPE_P (TREE_TYPE (in))
&& ((code == PLUS_EXPR && TREE_CODE (in) == MINUS_EXPR)
|| (code == MINUS_EXPR && TREE_CODE (in) == PLUS_EXPR))))
{
tree op0 = TREE_OPERAND (in, 0);
tree op1 = TREE_OPERAND (in, 1);
int neg1_p = TREE_CODE (in) == MINUS_EXPR;
int neg_litp_p = 0, neg_conp_p = 0, neg_var_p = 0;
if (TREE_CODE (op0) == INTEGER_CST || TREE_CODE (op0) == REAL_CST)
*litp = op0, op0 = 0;
else if (TREE_CODE (op1) == INTEGER_CST || TREE_CODE (op1) == REAL_CST)
*litp = op1, neg_litp_p = neg1_p, op1 = 0;
if (op0 != 0 && TREE_CONSTANT (op0))
*conp = op0, op0 = 0;
else if (op1 != 0 && TREE_CONSTANT (op1))
*conp = op1, neg_conp_p = neg1_p, op1 = 0;
if (op0 != 0 && op1 != 0)
var = in;
else if (op0 != 0)
var = op0;
else
var = op1, neg_var_p = neg1_p;
if (neg_litp_p)
*minus_litp = *litp, *litp = 0;
if (neg_conp_p)
*conp = negate_expr (*conp);
if (neg_var_p)
var = negate_expr (var);
}
else if (TREE_CONSTANT (in))
*conp = in;
else
var = in;
if (negate_p)
{
if (*litp)
*minus_litp = *litp, *litp = 0;
else if (*minus_litp)
*litp = *minus_litp, *minus_litp = 0;
*conp = negate_expr (*conp);
var = negate_expr (var);
}
return var;
}
static tree
associate_trees (t1, t2, code, type)
tree t1, t2;
enum tree_code code;
tree type;
{
if (t1 == 0)
return t2;
else if (t2 == 0)
return t1;
if (TREE_CODE (t1) == code || TREE_CODE (t2) == code
|| TREE_CODE (t1) == MINUS_EXPR || TREE_CODE (t2) == MINUS_EXPR)
{
if (code == PLUS_EXPR)
{
if (TREE_CODE (t1) == NEGATE_EXPR)
return build (MINUS_EXPR, type, convert (type, t2),
convert (type, TREE_OPERAND (t1, 0)));
else if (TREE_CODE (t2) == NEGATE_EXPR)
return build (MINUS_EXPR, type, convert (type, t1),
convert (type, TREE_OPERAND (t2, 0)));
}
return build (code, type, convert (type, t1), convert (type, t2));
}
return fold (build (code, type, convert (type, t1), convert (type, t2)));
}
static tree
int_const_binop (code, arg1, arg2, notrunc)
enum tree_code code;
tree arg1, arg2;
int notrunc;
{
unsigned HOST_WIDE_INT int1l, int2l;
HOST_WIDE_INT int1h, int2h;
unsigned HOST_WIDE_INT low;
HOST_WIDE_INT hi;
unsigned HOST_WIDE_INT garbagel;
HOST_WIDE_INT garbageh;
tree t;
tree type = TREE_TYPE (arg1);
int uns = TREE_UNSIGNED (type);
int is_sizetype
= (TREE_CODE (type) == INTEGER_TYPE && TYPE_IS_SIZETYPE (type));
int overflow = 0;
int no_overflow = 0;
int1l = TREE_INT_CST_LOW (arg1);
int1h = TREE_INT_CST_HIGH (arg1);
int2l = TREE_INT_CST_LOW (arg2);
int2h = TREE_INT_CST_HIGH (arg2);
switch (code)
{
case BIT_IOR_EXPR:
low = int1l | int2l, hi = int1h | int2h;
break;
case BIT_XOR_EXPR:
low = int1l ^ int2l, hi = int1h ^ int2h;
break;
case BIT_AND_EXPR:
low = int1l & int2l, hi = int1h & int2h;
break;
case BIT_ANDTC_EXPR:
low = int1l & ~int2l, hi = int1h & ~int2h;
break;
case RSHIFT_EXPR:
int2l = -int2l;
case LSHIFT_EXPR:
lshift_double (int1l, int1h, int2l, TYPE_PRECISION (type),
&low, &hi, !uns);
no_overflow = 1;
break;
case RROTATE_EXPR:
int2l = - int2l;
case LROTATE_EXPR:
lrotate_double (int1l, int1h, int2l, TYPE_PRECISION (type),
&low, &hi);
break;
case PLUS_EXPR:
overflow = add_double (int1l, int1h, int2l, int2h, &low, &hi);
break;
case MINUS_EXPR:
neg_double (int2l, int2h, &low, &hi);
add_double (int1l, int1h, low, hi, &low, &hi);
overflow = OVERFLOW_SUM_SIGN (hi, int2h, int1h);
break;
case MULT_EXPR:
overflow = mul_double (int1l, int1h, int2l, int2h, &low, &hi);
break;
case TRUNC_DIV_EXPR:
case FLOOR_DIV_EXPR: case CEIL_DIV_EXPR:
case EXACT_DIV_EXPR:
if (int2h == 0 && (HOST_WIDE_INT) int2l > 0
&& ! TREE_CONSTANT_OVERFLOW (arg1)
&& ! TREE_CONSTANT_OVERFLOW (arg2)
&& int1h == 0 && (HOST_WIDE_INT) int1l >= 0)
{
if (code == CEIL_DIV_EXPR)
int1l += int2l - 1;
low = int1l / int2l, hi = 0;
break;
}
case ROUND_DIV_EXPR:
if (int2h == 0 && int2l == 1)
{
low = int1l, hi = int1h;
break;
}
if (int1l == int2l && int1h == int2h
&& ! (int1l == 0 && int1h == 0))
{
low = 1, hi = 0;
break;
}
overflow = div_and_round_double (code, uns, int1l, int1h, int2l, int2h,
&low, &hi, &garbagel, &garbageh);
break;
case TRUNC_MOD_EXPR:
case FLOOR_MOD_EXPR: case CEIL_MOD_EXPR:
if (int2h == 0 && (HOST_WIDE_INT) int2l > 0
&& ! TREE_CONSTANT_OVERFLOW (arg1)
&& ! TREE_CONSTANT_OVERFLOW (arg2)
&& int1h == 0 && (HOST_WIDE_INT) int1l >= 0)
{
if (code == CEIL_MOD_EXPR)
int1l += int2l - 1;
low = int1l % int2l, hi = 0;
break;
}
case ROUND_MOD_EXPR:
overflow = div_and_round_double (code, uns,
int1l, int1h, int2l, int2h,
&garbagel, &garbageh, &low, &hi);
break;
case MIN_EXPR:
case MAX_EXPR:
if (uns)
low = (((unsigned HOST_WIDE_INT) int1h
< (unsigned HOST_WIDE_INT) int2h)
|| (((unsigned HOST_WIDE_INT) int1h
== (unsigned HOST_WIDE_INT) int2h)
&& int1l < int2l));
else
low = (int1h < int2h
|| (int1h == int2h && int1l < int2l));
if (low == (code == MIN_EXPR))
low = int1l, hi = int1h;
else
low = int2l, hi = int2h;
break;
default:
abort ();
}
if (is_sizetype
&& ((hi == 0 && (HOST_WIDE_INT) low >= 0)
|| (hi == -1 && (HOST_WIDE_INT) low < 0))
&& overflow == 0 && ! TREE_OVERFLOW (arg1) && ! TREE_OVERFLOW (arg2))
return size_int_type_wide (low, type);
else
{
t = build_int_2 (low, hi);
TREE_TYPE (t) = TREE_TYPE (arg1);
}
TREE_OVERFLOW (t)
= ((notrunc
? (!uns || is_sizetype) && overflow
: (force_fit_type (t, (!uns || is_sizetype) && overflow)
&& ! no_overflow))
| TREE_OVERFLOW (arg1)
| TREE_OVERFLOW (arg2));
if (is_sizetype
&& ! TREE_OVERFLOW (t)
&& (TREE_INT_CST_HIGH (t) != hi
|| TREE_INT_CST_LOW (t) != low))
TREE_OVERFLOW (t) = 1;
TREE_CONSTANT_OVERFLOW (t) = (TREE_OVERFLOW (t)
| TREE_CONSTANT_OVERFLOW (arg1)
| TREE_CONSTANT_OVERFLOW (arg2));
return t;
}
static tree
const_binop (code, arg1, arg2, notrunc)
enum tree_code code;
tree arg1, arg2;
int notrunc;
{
STRIP_NOPS (arg1);
STRIP_NOPS (arg2);
if (TREE_CODE (arg1) == INTEGER_CST)
return int_const_binop (code, arg1, arg2, notrunc);
if (TREE_CODE (arg1) == REAL_CST)
{
REAL_VALUE_TYPE d1;
REAL_VALUE_TYPE d2;
REAL_VALUE_TYPE value;
tree t;
d1 = TREE_REAL_CST (arg1);
d2 = TREE_REAL_CST (arg2);
if (REAL_VALUE_ISNAN (d1))
return arg1;
else if (REAL_VALUE_ISNAN (d2))
return arg2;
REAL_ARITHMETIC (value, code, d1, d2);
t = build_real (TREE_TYPE (arg1),
real_value_truncate (TYPE_MODE (TREE_TYPE (arg1)),
value));
TREE_OVERFLOW (t)
= (force_fit_type (t, 0)
| TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2));
TREE_CONSTANT_OVERFLOW (t)
= TREE_OVERFLOW (t)
| TREE_CONSTANT_OVERFLOW (arg1)
| TREE_CONSTANT_OVERFLOW (arg2);
return t;
}
if (TREE_CODE (arg1) == COMPLEX_CST)
{
tree type = TREE_TYPE (arg1);
tree r1 = TREE_REALPART (arg1);
tree i1 = TREE_IMAGPART (arg1);
tree r2 = TREE_REALPART (arg2);
tree i2 = TREE_IMAGPART (arg2);
tree t;
switch (code)
{
case PLUS_EXPR:
t = build_complex (type,
const_binop (PLUS_EXPR, r1, r2, notrunc),
const_binop (PLUS_EXPR, i1, i2, notrunc));
break;
case MINUS_EXPR:
t = build_complex (type,
const_binop (MINUS_EXPR, r1, r2, notrunc),
const_binop (MINUS_EXPR, i1, i2, notrunc));
break;
case MULT_EXPR:
t = build_complex (type,
const_binop (MINUS_EXPR,
const_binop (MULT_EXPR,
r1, r2, notrunc),
const_binop (MULT_EXPR,
i1, i2, notrunc),
notrunc),
const_binop (PLUS_EXPR,
const_binop (MULT_EXPR,
r1, i2, notrunc),
const_binop (MULT_EXPR,
i1, r2, notrunc),
notrunc));
break;
case RDIV_EXPR:
{
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));
}
break;
default:
abort ();
}
return t;
}
return 0;
}
static hashval_t
size_htab_hash (x)
const void *x;
{
tree t = (tree) x;
return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t)
^ htab_hash_pointer (TREE_TYPE (t))
^ (TREE_OVERFLOW (t) << 20));
}
static int
size_htab_eq (x, y)
const void *x;
const void *y;
{
tree xt = (tree) x;
tree yt = (tree) y;
return (TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt)
&& TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt)
&& TREE_TYPE (xt) == TREE_TYPE (yt)
&& TREE_OVERFLOW (xt) == TREE_OVERFLOW (yt));
}
tree
size_int_wide (number, kind)
HOST_WIDE_INT number;
enum size_type_kind kind;
{
return size_int_type_wide (number, sizetype_tab[(int) kind]);
}
static GTY (()) tree new_const;
static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
htab_t size_htab;
tree
size_int_type_wide (number, type)
HOST_WIDE_INT number;
tree type;
{
PTR *slot;
if (size_htab == 0)
{
size_htab = htab_create_ggc (1024, size_htab_hash, size_htab_eq, NULL);
new_const = make_node (INTEGER_CST);
}
TREE_INT_CST_LOW (new_const) = number;
TREE_INT_CST_HIGH (new_const) = number < 0 ? -1 : 0;
TREE_TYPE (new_const) = type;
TREE_OVERFLOW (new_const) = TREE_CONSTANT_OVERFLOW (new_const)
= force_fit_type (new_const, 0);
slot = htab_find_slot (size_htab, new_const, INSERT);
if (*slot == 0)
{
tree t = new_const;
*slot = (PTR) new_const;
new_const = make_node (INTEGER_CST);
return t;
}
else
return (tree) *slot;
}
tree
size_binop (code, arg0, arg1)
enum tree_code code;
tree arg0, arg1;
{
tree type = TREE_TYPE (arg0);
if (TREE_CODE (type) != INTEGER_TYPE || ! TYPE_IS_SIZETYPE (type)
|| type != TREE_TYPE (arg1))
abort ();
if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
{
if (code == PLUS_EXPR && integer_zerop (arg0))
return arg1;
else if ((code == MINUS_EXPR || code == PLUS_EXPR)
&& integer_zerop (arg1))
return arg0;
else if (code == MULT_EXPR && integer_onep (arg0))
return arg1;
return int_const_binop (code, arg0, arg1, 0);
}
if (arg0 == error_mark_node || arg1 == error_mark_node)
return error_mark_node;
return fold (build (code, type, arg0, arg1));
}
tree
size_diffop (arg0, arg1)
tree arg0, arg1;
{
tree type = TREE_TYPE (arg0);
tree ctype;
if (TREE_CODE (type) != INTEGER_TYPE || ! TYPE_IS_SIZETYPE (type)
|| type != TREE_TYPE (arg1))
abort ();
if (! TREE_UNSIGNED (type))
return size_binop (MINUS_EXPR, arg0, arg1);
ctype = (type == bitsizetype || type == ubitsizetype
? sbitsizetype : ssizetype);
if (TREE_CODE (arg0) != INTEGER_CST || TREE_CODE (arg1) != INTEGER_CST)
return size_binop (MINUS_EXPR, convert (ctype, arg0),
convert (ctype, arg1));
if (tree_int_cst_equal (arg0, arg1))
return convert (ctype, integer_zero_node);
else if (tree_int_cst_lt (arg1, arg0))
return convert (ctype, size_binop (MINUS_EXPR, arg0, arg1));
else
return size_binop (MINUS_EXPR, convert (ctype, integer_zero_node),
convert (ctype, size_binop (MINUS_EXPR, arg1, arg0)));
}
static tree
fold_convert (t, arg1)
tree t;
tree arg1;
{
tree type = TREE_TYPE (t);
int overflow = 0;
if (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type))
{
if (TREE_CODE (arg1) == INTEGER_CST)
{
if (TYPE_PRECISION (type) > 2 * HOST_BITS_PER_WIDE_INT)
return t;
if (TREE_CODE (type) == INTEGER_TYPE && TYPE_IS_SIZETYPE (type)
&& !TREE_CONSTANT_OVERFLOW (arg1)
&& compare_tree_int (arg1, 10000) < 0)
return size_int_type_wide (TREE_INT_CST_LOW (arg1), type);
t = build_int_2 (TREE_INT_CST_LOW (arg1),
TREE_INT_CST_HIGH (arg1));
TREE_TYPE (t) = type;
TREE_OVERFLOW (t)
= ((force_fit_type (t,
(TREE_INT_CST_HIGH (arg1) < 0
&& (TREE_UNSIGNED (type)
< TREE_UNSIGNED (TREE_TYPE (arg1)))))
&& ! POINTER_TYPE_P (TREE_TYPE (arg1)))
|| TREE_OVERFLOW (arg1));
TREE_CONSTANT_OVERFLOW (t)
= TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg1);
}
else if (TREE_CODE (arg1) == REAL_CST)
{
REAL_VALUE_TYPE x;
REAL_VALUE_TYPE l;
REAL_VALUE_TYPE u;
tree type1 = TREE_TYPE (arg1);
int no_upper_bound;
x = TREE_REAL_CST (arg1);
l = real_value_from_int_cst (type1, TYPE_MIN_VALUE (type));
no_upper_bound = (TYPE_MAX_VALUE (type) == NULL);
if (!no_upper_bound)
u = real_value_from_int_cst (type1, TYPE_MAX_VALUE (type));
REAL_ARITHMETIC (l, MINUS_EXPR, l, dconst1);
if (!no_upper_bound)
REAL_ARITHMETIC (u, PLUS_EXPR, u, dconst1);
if (REAL_VALUE_ISNAN (x))
overflow = 1, x = dconst0;
else if (! (REAL_VALUES_LESS (l, x)
&& !no_upper_bound
&& REAL_VALUES_LESS (x, u)))
overflow = 1;
{
HOST_WIDE_INT low, high;
REAL_VALUE_TO_INT (&low, &high, x);
t = build_int_2 (low, high);
}
TREE_TYPE (t) = type;
TREE_OVERFLOW (t)
= TREE_OVERFLOW (arg1) | force_fit_type (t, overflow);
TREE_CONSTANT_OVERFLOW (t)
= TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg1);
}
TREE_TYPE (t) = type;
}
else if (TREE_CODE (type) == REAL_TYPE)
{
if (TREE_CODE (arg1) == INTEGER_CST)
return build_real_from_int_cst (type, arg1);
if (TREE_CODE (arg1) == REAL_CST)
{
if (REAL_VALUE_ISNAN (TREE_REAL_CST (arg1)))
{
t = copy_node (arg1);
TREE_TYPE (t) = type;
return t;
}
t = build_real (type,
real_value_truncate (TYPE_MODE (type),
TREE_REAL_CST (arg1)));
TREE_OVERFLOW (t)
= TREE_OVERFLOW (arg1) | force_fit_type (t, 0);
TREE_CONSTANT_OVERFLOW (t)
= TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg1);
return t;
}
}
TREE_CONSTANT (t) = 1;
return t;
}
tree
non_lvalue (x)
tree x;
{
tree result;
if (TREE_CODE (x) == NON_LVALUE_EXPR
|| TREE_CODE (x) == INTEGER_CST
|| TREE_CODE (x) == REAL_CST
|| TREE_CODE (x) == STRING_CST
|| TREE_CODE (x) == ADDR_EXPR)
return x;
result = build1 (NON_LVALUE_EXPR, TREE_TYPE (x), x);
TREE_CONSTANT (result) = TREE_CONSTANT (x);
return result;
}
int pedantic_lvalues;
tree
pedantic_non_lvalue (x)
tree x;
{
if (pedantic_lvalues)
return non_lvalue (x);
else
return x;
}
static enum tree_code
invert_tree_comparison (code)
enum tree_code code;
{
switch (code)
{
case EQ_EXPR:
return NE_EXPR;
case NE_EXPR:
return EQ_EXPR;
case GT_EXPR:
return LE_EXPR;
case GE_EXPR:
return LT_EXPR;
case LT_EXPR:
return GE_EXPR;
case LE_EXPR:
return GT_EXPR;
default:
abort ();
}
}
static enum tree_code
swap_tree_comparison (code)
enum tree_code code;
{
switch (code)
{
case EQ_EXPR:
case NE_EXPR:
return code;
case GT_EXPR:
return LT_EXPR;
case GE_EXPR:
return LE_EXPR;
case LT_EXPR:
return GT_EXPR;
case LE_EXPR:
return GE_EXPR;
default:
abort ();
}
}
static int
comparison_to_compcode (code)
enum tree_code code;
{
switch (code)
{
case LT_EXPR:
return COMPCODE_LT;
case EQ_EXPR:
return COMPCODE_EQ;
case LE_EXPR:
return COMPCODE_LE;
case GT_EXPR:
return COMPCODE_GT;
case NE_EXPR:
return COMPCODE_NE;
case GE_EXPR:
return COMPCODE_GE;
default:
abort ();
}
}
static enum tree_code
compcode_to_comparison (code)
int code;
{
switch (code)
{
case COMPCODE_LT:
return LT_EXPR;
case COMPCODE_EQ:
return EQ_EXPR;
case COMPCODE_LE:
return LE_EXPR;
case COMPCODE_GT:
return GT_EXPR;
case COMPCODE_NE:
return NE_EXPR;
case COMPCODE_GE:
return GE_EXPR;
default:
abort ();
}
}
static int
truth_value_p (code)
enum tree_code code;
{
return (TREE_CODE_CLASS (code) == '<'
|| code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR
|| code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
|| code == TRUTH_XOR_EXPR || code == TRUTH_NOT_EXPR);
}
int
operand_equal_p (arg0, arg1, only_const)
tree arg0, arg1;
int only_const;
{
if (TREE_UNSIGNED (TREE_TYPE (arg0)) != TREE_UNSIGNED (TREE_TYPE (arg1)))
return 0;
STRIP_NOPS (arg0);
STRIP_NOPS (arg1);
if (TREE_CODE (arg0) != TREE_CODE (arg1)
|| TREE_CODE (TREE_TYPE (arg0)) == ERROR_MARK
|| TREE_CODE (TREE_TYPE (arg1)) == ERROR_MARK
|| TYPE_MODE (TREE_TYPE (arg0)) != TYPE_MODE (TREE_TYPE (arg1)))
return 0;
if (arg0 == arg1 && ! only_const
&& (TREE_CODE (arg0) == SAVE_EXPR
|| (! TREE_SIDE_EFFECTS (arg0) && ! TREE_SIDE_EFFECTS (arg1))))
return 1;
if (TREE_CONSTANT (arg0) && TREE_CONSTANT (arg1))
switch (TREE_CODE (arg0))
{
case INTEGER_CST:
return (! TREE_CONSTANT_OVERFLOW (arg0)
&& ! TREE_CONSTANT_OVERFLOW (arg1)
&& tree_int_cst_equal (arg0, arg1));
case REAL_CST:
return (! TREE_CONSTANT_OVERFLOW (arg0)
&& ! TREE_CONSTANT_OVERFLOW (arg1)
&& REAL_VALUES_IDENTICAL (TREE_REAL_CST (arg0),
TREE_REAL_CST (arg1)));
case VECTOR_CST:
{
tree v1, v2;
if (TREE_CONSTANT_OVERFLOW (arg0)
|| TREE_CONSTANT_OVERFLOW (arg1))
return 0;
v1 = TREE_VECTOR_CST_ELTS (arg0);
v2 = TREE_VECTOR_CST_ELTS (arg1);
while (v1 && v2)
{
if (!operand_equal_p (v1, v2, only_const))
return 0;
v1 = TREE_CHAIN (v1);
v2 = TREE_CHAIN (v2);
}
return 1;
}
case COMPLEX_CST:
return (operand_equal_p (TREE_REALPART (arg0), TREE_REALPART (arg1),
only_const)
&& operand_equal_p (TREE_IMAGPART (arg0), TREE_IMAGPART (arg1),
only_const));
case STRING_CST:
return (TREE_STRING_LENGTH (arg0) == TREE_STRING_LENGTH (arg1)
&& ! memcmp (TREE_STRING_POINTER (arg0),
TREE_STRING_POINTER (arg1),
TREE_STRING_LENGTH (arg0)));
case ADDR_EXPR:
return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0),
0);
default:
break;
}
if (only_const)
return 0;
switch (TREE_CODE_CLASS (TREE_CODE (arg0)))
{
case '1':
if ((TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == CONVERT_EXPR)
&& (TREE_UNSIGNED (TREE_TYPE (arg0))
!= TREE_UNSIGNED (TREE_TYPE (arg1))))
return 0;
return operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0), 0);
case '<':
case '2':
if (operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0), 0)
&& operand_equal_p (TREE_OPERAND (arg0, 1), TREE_OPERAND (arg1, 1),
0))
return 1;
return ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MULT_EXPR
|| TREE_CODE (arg0) == MIN_EXPR || TREE_CODE (arg0) == MAX_EXPR
|| TREE_CODE (arg0) == BIT_IOR_EXPR
|| TREE_CODE (arg0) == BIT_XOR_EXPR
|| TREE_CODE (arg0) == BIT_AND_EXPR
|| TREE_CODE (arg0) == NE_EXPR || TREE_CODE (arg0) == EQ_EXPR)
&& operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 1), 0)
&& operand_equal_p (TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 0), 0));
case 'r':
if (TREE_SIDE_EFFECTS (arg0)
|| TREE_SIDE_EFFECTS (arg1))
return 0;
switch (TREE_CODE (arg0))
{
case INDIRECT_REF:
return operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0), 0);
case COMPONENT_REF:
case ARRAY_REF:
case ARRAY_RANGE_REF:
return (operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0), 0)
&& operand_equal_p (TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 1), 0));
case BIT_FIELD_REF:
return (operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0), 0)
&& operand_equal_p (TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 1), 0)
&& operand_equal_p (TREE_OPERAND (arg0, 2),
TREE_OPERAND (arg1, 2), 0));
default:
return 0;
}
case 'e':
if (TREE_CODE (arg0) == RTL_EXPR)
return rtx_equal_p (RTL_EXPR_RTL (arg0), RTL_EXPR_RTL (arg1));
return 0;
default:
return 0;
}
}
static int
operand_equal_for_comparison_p (arg0, arg1, other)
tree arg0, arg1;
tree other;
{
int unsignedp1, unsignedpo;
tree primarg0, primarg1, primother;
unsigned int correct_width;
if (operand_equal_p (arg0, arg1, 0))
return 1;
if (! INTEGRAL_TYPE_P (TREE_TYPE (arg0))
|| ! INTEGRAL_TYPE_P (TREE_TYPE (arg1)))
return 0;
primarg0 = arg0, primarg1 = arg1;
STRIP_NOPS (primarg0);
STRIP_NOPS (primarg1);
if (operand_equal_p (primarg0, primarg1, 0))
return 1;
primarg1 = get_narrower (arg1, &unsignedp1);
primother = get_narrower (other, &unsignedpo);
correct_width = TYPE_PRECISION (TREE_TYPE (arg1));
if (unsignedp1 == unsignedpo
&& TYPE_PRECISION (TREE_TYPE (primarg1)) < correct_width
&& TYPE_PRECISION (TREE_TYPE (primother)) < correct_width)
{
tree type = TREE_TYPE (arg0);
primarg1 = convert ((*lang_hooks.types.signed_or_unsigned_type)
(unsignedp1, TREE_TYPE (primarg1)), primarg1);
if (operand_equal_p (arg0, convert (type, primarg1), 0))
return 1;
}
return 0;
}
static int
twoval_comparison_p (arg, cval1, cval2, save_p)
tree arg;
tree *cval1, *cval2;
int *save_p;
{
enum tree_code code = TREE_CODE (arg);
char class = TREE_CODE_CLASS (code);
if (class == 'e' && code == TRUTH_NOT_EXPR)
class = '1';
else if (class == 'e'
&& (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR
|| code == COMPOUND_EXPR))
class = '2';
else if (class == 'e' && code == SAVE_EXPR && SAVE_EXPR_RTL (arg) == 0
&& ! TREE_SIDE_EFFECTS (TREE_OPERAND (arg, 0)))
{
if (*cval1 || *cval2)
return 0;
class = '1';
*save_p = 1;
}
switch (class)
{
case '1':
return twoval_comparison_p (TREE_OPERAND (arg, 0), cval1, cval2, save_p);
case '2':
return (twoval_comparison_p (TREE_OPERAND (arg, 0), cval1, cval2, save_p)
&& twoval_comparison_p (TREE_OPERAND (arg, 1),
cval1, cval2, save_p));
case 'c':
return 1;
case 'e':
if (code == COND_EXPR)
return (twoval_comparison_p (TREE_OPERAND (arg, 0),
cval1, cval2, save_p)
&& twoval_comparison_p (TREE_OPERAND (arg, 1),
cval1, cval2, save_p)
&& twoval_comparison_p (TREE_OPERAND (arg, 2),
cval1, cval2, save_p));
return 0;
case '<':
if (operand_equal_p (TREE_OPERAND (arg, 0),
TREE_OPERAND (arg, 1), 0))
return 0;
if (*cval1 == 0)
*cval1 = TREE_OPERAND (arg, 0);
else if (operand_equal_p (*cval1, TREE_OPERAND (arg, 0), 0))
;
else if (*cval2 == 0)
*cval2 = TREE_OPERAND (arg, 0);
else if (operand_equal_p (*cval2, TREE_OPERAND (arg, 0), 0))
;
else
return 0;
if (operand_equal_p (*cval1, TREE_OPERAND (arg, 1), 0))
;
else if (*cval2 == 0)
*cval2 = TREE_OPERAND (arg, 1);
else if (operand_equal_p (*cval2, TREE_OPERAND (arg, 1), 0))
;
else
return 0;
return 1;
default:
return 0;
}
}
static tree
eval_subst (arg, old0, new0, old1, new1)
tree arg;
tree old0, new0, old1, new1;
{
tree type = TREE_TYPE (arg);
enum tree_code code = TREE_CODE (arg);
char class = TREE_CODE_CLASS (code);
if (class == 'e' && code == TRUTH_NOT_EXPR)
class = '1';
else if (class == 'e'
&& (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR))
class = '2';
switch (class)
{
case '1':
return fold (build1 (code, type,
eval_subst (TREE_OPERAND (arg, 0),
old0, new0, old1, new1)));
case '2':
return fold (build (code, type,
eval_subst (TREE_OPERAND (arg, 0),
old0, new0, old1, new1),
eval_subst (TREE_OPERAND (arg, 1),
old0, new0, old1, new1)));
case 'e':
switch (code)
{
case SAVE_EXPR:
return eval_subst (TREE_OPERAND (arg, 0), old0, new0, old1, new1);
case COMPOUND_EXPR:
return eval_subst (TREE_OPERAND (arg, 1), old0, new0, old1, new1);
case COND_EXPR:
return fold (build (code, type,
eval_subst (TREE_OPERAND (arg, 0),
old0, new0, old1, new1),
eval_subst (TREE_OPERAND (arg, 1),
old0, new0, old1, new1),
eval_subst (TREE_OPERAND (arg, 2),
old0, new0, old1, new1)));
default:
break;
}
case '<':
{
tree arg0 = TREE_OPERAND (arg, 0);
tree arg1 = TREE_OPERAND (arg, 1);
if (arg0 == old0 || operand_equal_p (arg0, old0, 0))
arg0 = new0;
else if (arg0 == old1 || operand_equal_p (arg0, old1, 0))
arg0 = new1;
if (arg1 == old0 || operand_equal_p (arg1, old0, 0))
arg1 = new0;
else if (arg1 == old1 || operand_equal_p (arg1, old1, 0))
arg1 = new1;
return fold (build (code, type, arg0, arg1));
}
default:
return arg;
}
}
static tree
omit_one_operand (type, result, omitted)
tree type, result, omitted;
{
tree t = convert (type, result);
if (TREE_SIDE_EFFECTS (omitted))
return build (COMPOUND_EXPR, type, omitted, t);
return non_lvalue (t);
}
static tree
pedantic_omit_one_operand (type, result, omitted)
tree type, result, omitted;
{
tree t = convert (type, result);
if (TREE_SIDE_EFFECTS (omitted))
return build (COMPOUND_EXPR, type, omitted, t);
return pedantic_non_lvalue (t);
}
tree
invert_truthvalue (arg)
tree arg;
{
tree type = TREE_TYPE (arg);
enum tree_code code = TREE_CODE (arg);
if (code == ERROR_MARK)
return arg;
if (TREE_CODE_CLASS (code) == '<')
{
if (FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg, 0)))
&& !flag_unsafe_math_optimizations
&& code != NE_EXPR
&& code != EQ_EXPR)
return build1 (TRUTH_NOT_EXPR, type, arg);
else
return build (invert_tree_comparison (code), type,
TREE_OPERAND (arg, 0), TREE_OPERAND (arg, 1));
}
switch (code)
{
case INTEGER_CST:
return convert (type, build_int_2 (integer_zerop (arg), 0));
case TRUTH_AND_EXPR:
return build (TRUTH_OR_EXPR, type,
invert_truthvalue (TREE_OPERAND (arg, 0)),
invert_truthvalue (TREE_OPERAND (arg, 1)));
case TRUTH_OR_EXPR:
return build (TRUTH_AND_EXPR, type,
invert_truthvalue (TREE_OPERAND (arg, 0)),
invert_truthvalue (TREE_OPERAND (arg, 1)));
case TRUTH_XOR_EXPR:
if (TREE_CODE (TREE_OPERAND (arg, 1)) == TRUTH_NOT_EXPR)
return build (TRUTH_XOR_EXPR, type, TREE_OPERAND (arg, 0),
TREE_OPERAND (TREE_OPERAND (arg, 1), 0));
else
return build (TRUTH_XOR_EXPR, type,
invert_truthvalue (TREE_OPERAND (arg, 0)),
TREE_OPERAND (arg, 1));
case TRUTH_ANDIF_EXPR:
return build (TRUTH_ORIF_EXPR, type,
invert_truthvalue (TREE_OPERAND (arg, 0)),
invert_truthvalue (TREE_OPERAND (arg, 1)));
case TRUTH_ORIF_EXPR:
return build (TRUTH_ANDIF_EXPR, type,
invert_truthvalue (TREE_OPERAND (arg, 0)),
invert_truthvalue (TREE_OPERAND (arg, 1)));
case TRUTH_NOT_EXPR:
return TREE_OPERAND (arg, 0);
case COND_EXPR:
return build (COND_EXPR, type, TREE_OPERAND (arg, 0),
invert_truthvalue (TREE_OPERAND (arg, 1)),
invert_truthvalue (TREE_OPERAND (arg, 2)));
case COMPOUND_EXPR:
return build (COMPOUND_EXPR, type, TREE_OPERAND (arg, 0),
invert_truthvalue (TREE_OPERAND (arg, 1)));
case WITH_RECORD_EXPR:
return build (WITH_RECORD_EXPR, type,
invert_truthvalue (TREE_OPERAND (arg, 0)),
TREE_OPERAND (arg, 1));
case NON_LVALUE_EXPR:
return invert_truthvalue (TREE_OPERAND (arg, 0));
case NOP_EXPR:
case CONVERT_EXPR:
case FLOAT_EXPR:
return build1 (TREE_CODE (arg), type,
invert_truthvalue (TREE_OPERAND (arg, 0)));
case BIT_AND_EXPR:
if (!integer_onep (TREE_OPERAND (arg, 1)))
break;
return build (EQ_EXPR, type, arg, convert (type, integer_zero_node));
case SAVE_EXPR:
return build1 (TRUTH_NOT_EXPR, type, arg);
case CLEANUP_POINT_EXPR:
return build1 (CLEANUP_POINT_EXPR, type,
invert_truthvalue (TREE_OPERAND (arg, 0)));
default:
break;
}
if (TREE_CODE (TREE_TYPE (arg)) != BOOLEAN_TYPE)
abort ();
return build1 (TRUTH_NOT_EXPR, type, arg);
}
static tree
distribute_bit_expr (code, type, arg0, arg1)
enum tree_code code;
tree type;
tree arg0, arg1;
{
tree common;
tree left, right;
if (TREE_CODE (arg0) != TREE_CODE (arg1)
|| TREE_CODE (arg0) == code
|| (TREE_CODE (arg0) != BIT_AND_EXPR
&& TREE_CODE (arg0) != BIT_IOR_EXPR))
return 0;
if (operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0), 0))
{
common = TREE_OPERAND (arg0, 0);
left = TREE_OPERAND (arg0, 1);
right = TREE_OPERAND (arg1, 1);
}
else if (operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 1), 0))
{
common = TREE_OPERAND (arg0, 0);
left = TREE_OPERAND (arg0, 1);
right = TREE_OPERAND (arg1, 0);
}
else if (operand_equal_p (TREE_OPERAND (arg0, 1), TREE_OPERAND (arg1, 0), 0))
{
common = TREE_OPERAND (arg0, 1);
left = TREE_OPERAND (arg0, 0);
right = TREE_OPERAND (arg1, 1);
}
else if (operand_equal_p (TREE_OPERAND (arg0, 1), TREE_OPERAND (arg1, 1), 0))
{
common = TREE_OPERAND (arg0, 1);
left = TREE_OPERAND (arg0, 0);
right = TREE_OPERAND (arg1, 0);
}
else
return 0;
return fold (build (TREE_CODE (arg0), type, common,
fold (build (code, type, left, right))));
}
static tree
make_bit_field_ref (inner, type, bitsize, bitpos, unsignedp)
tree inner;
tree type;
int bitsize, bitpos;
int unsignedp;
{
tree result = build (BIT_FIELD_REF, type, inner,
size_int (bitsize), bitsize_int (bitpos));
TREE_UNSIGNED (result) = unsignedp;
return result;
}
static tree
optimize_bit_field_compare (code, compare_type, lhs, rhs)
enum tree_code code;
tree compare_type;
tree lhs, rhs;
{
HOST_WIDE_INT lbitpos, lbitsize, rbitpos, rbitsize, nbitpos, nbitsize;
tree type = TREE_TYPE (lhs);
tree signed_type, unsigned_type;
int const_p = TREE_CODE (rhs) == INTEGER_CST;
enum machine_mode lmode, rmode, nmode;
int lunsignedp, runsignedp;
int lvolatilep = 0, rvolatilep = 0;
tree linner, rinner = NULL_TREE;
tree mask;
tree offset;
linner = get_inner_reference (lhs, &lbitsize, &lbitpos, &offset, &lmode,
&lunsignedp, &lvolatilep);
if (linner == lhs || lbitsize == GET_MODE_BITSIZE (lmode) || lbitsize < 0
|| offset != 0 || TREE_CODE (linner) == PLACEHOLDER_EXPR)
return 0;
if (!const_p)
{
rinner = get_inner_reference (rhs, &rbitsize, &rbitpos, &offset, &rmode,
&runsignedp, &rvolatilep);
if (rinner == rhs || lbitpos != rbitpos || lbitsize != rbitsize
|| lunsignedp != runsignedp || offset != 0
|| TREE_CODE (rinner) == PLACEHOLDER_EXPR)
return 0;
}
nmode = get_best_mode (lbitsize, lbitpos,
const_p ? TYPE_ALIGN (TREE_TYPE (linner))
: MIN (TYPE_ALIGN (TREE_TYPE (linner)),
TYPE_ALIGN (TREE_TYPE (rinner))),
word_mode, lvolatilep || rvolatilep);
if (nmode == VOIDmode)
return 0;
signed_type = (*lang_hooks.types.type_for_mode) (nmode, 0);
unsigned_type = (*lang_hooks.types.type_for_mode) (nmode, 1);
nbitsize = GET_MODE_BITSIZE (nmode);
nbitpos = lbitpos & ~ (nbitsize - 1);
lbitpos -= nbitpos;
if (nbitsize == lbitsize)
return 0;
if (BYTES_BIG_ENDIAN)
lbitpos = nbitsize - lbitsize - lbitpos;
mask = build_int_2 (~0, ~0);
TREE_TYPE (mask) = unsigned_type;
force_fit_type (mask, 0);
mask = convert (unsigned_type, mask);
mask = const_binop (LSHIFT_EXPR, mask, size_int (nbitsize - lbitsize), 0);
mask = const_binop (RSHIFT_EXPR, mask,
size_int (nbitsize - lbitsize - lbitpos), 0);
if (! const_p)
return build (code, compare_type,
build (BIT_AND_EXPR, unsigned_type,
make_bit_field_ref (linner, unsigned_type,
nbitsize, nbitpos, 1),
mask),
build (BIT_AND_EXPR, unsigned_type,
make_bit_field_ref (rinner, unsigned_type,
nbitsize, nbitpos, 1),
mask));
if (lunsignedp)
{
if (! integer_zerop (const_binop (RSHIFT_EXPR,
convert (unsigned_type, rhs),
size_int (lbitsize), 0)))
{
warning ("comparison is always %d due to width of bit-field",
code == NE_EXPR);
return convert (compare_type,
(code == NE_EXPR
? integer_one_node : integer_zero_node));
}
}
else
{
tree tem = const_binop (RSHIFT_EXPR, convert (signed_type, rhs),
size_int (lbitsize - 1), 0);
if (! integer_zerop (tem) && ! integer_all_onesp (tem))
{
warning ("comparison is always %d due to width of bit-field",
code == NE_EXPR);
return convert (compare_type,
(code == NE_EXPR
? integer_one_node : integer_zero_node));
}
}
if (lbitsize == 1 && ! integer_zerop (rhs))
{
code = code == EQ_EXPR ? NE_EXPR : EQ_EXPR;
rhs = convert (type, integer_zero_node);
}
lhs = make_bit_field_ref (linner, unsigned_type, nbitsize, nbitpos, 1);
if (lvolatilep)
{
TREE_SIDE_EFFECTS (lhs) = 1;
TREE_THIS_VOLATILE (lhs) = 1;
}
rhs = fold (const_binop (BIT_AND_EXPR,
const_binop (LSHIFT_EXPR,
convert (unsigned_type, rhs),
size_int (lbitpos), 0),
mask, 0));
return build (code, compare_type,
build (BIT_AND_EXPR, unsigned_type, lhs, mask),
rhs);
}
static tree
decode_field_reference (exp, pbitsize, pbitpos, pmode, punsignedp,
pvolatilep, pmask, pand_mask)
tree exp;
HOST_WIDE_INT *pbitsize, *pbitpos;
enum machine_mode *pmode;
int *punsignedp, *pvolatilep;
tree *pmask;
tree *pand_mask;
{
tree and_mask = 0;
tree mask, inner, offset;
tree unsigned_type;
unsigned int precision;
if (! INTEGRAL_TYPE_P (TREE_TYPE (exp)))
return 0;
STRIP_NOPS (exp);
if (TREE_CODE (exp) == BIT_AND_EXPR)
{
and_mask = TREE_OPERAND (exp, 1);
exp = TREE_OPERAND (exp, 0);
STRIP_NOPS (exp); STRIP_NOPS (and_mask);
if (TREE_CODE (and_mask) != INTEGER_CST)
return 0;
}
inner = get_inner_reference (exp, pbitsize, pbitpos, &offset, pmode,
punsignedp, pvolatilep);
if ((inner == exp && and_mask == 0)
|| *pbitsize < 0 || offset != 0
|| TREE_CODE (inner) == PLACEHOLDER_EXPR)
return 0;
unsigned_type = (*lang_hooks.types.type_for_size) (*pbitsize, 1);
precision = TYPE_PRECISION (unsigned_type);
mask = build_int_2 (~0, ~0);
TREE_TYPE (mask) = unsigned_type;
force_fit_type (mask, 0);
mask = const_binop (LSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0);
mask = const_binop (RSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0);
if (and_mask != 0)
mask = fold (build (BIT_AND_EXPR, unsigned_type,
convert (unsigned_type, and_mask), mask));
*pmask = mask;
*pand_mask = and_mask;
return inner;
}
static int
all_ones_mask_p (mask, size)
tree mask;
int size;
{
tree type = TREE_TYPE (mask);
unsigned int precision = TYPE_PRECISION (type);
tree tmask;
tmask = build_int_2 (~0, ~0);
TREE_TYPE (tmask) = (*lang_hooks.types.signed_type) (type);
force_fit_type (tmask, 0);
return
tree_int_cst_equal (mask,
const_binop (RSHIFT_EXPR,
const_binop (LSHIFT_EXPR, tmask,
size_int (precision - size),
0),
size_int (precision - size), 0));
}
static tree
sign_bit_p (exp, val)
tree exp;
tree val;
{
unsigned HOST_WIDE_INT lo;
HOST_WIDE_INT hi;
int width;
tree t;
t = TREE_TYPE (exp);
if (! INTEGRAL_TYPE_P (t))
return NULL_TREE;
if (TREE_CODE (val) != INTEGER_CST
|| TREE_CONSTANT_OVERFLOW (val))
return NULL_TREE;
width = TYPE_PRECISION (t);
if (width > HOST_BITS_PER_WIDE_INT)
{
hi = (unsigned HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT - 1);
lo = 0;
}
else
{
hi = 0;
lo = (unsigned HOST_WIDE_INT) 1 << (width - 1);
}
if (TREE_INT_CST_HIGH (val) == hi && TREE_INT_CST_LOW (val) == lo)
return exp;
if (TREE_CODE (exp) == NOP_EXPR
&& TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))) < width)
return sign_bit_p (TREE_OPERAND (exp, 0), val);
return NULL_TREE;
}
static int
simple_operand_p (exp)
tree exp;
{
while ((TREE_CODE (exp) == NOP_EXPR
|| TREE_CODE (exp) == CONVERT_EXPR)
&& (TYPE_MODE (TREE_TYPE (exp))
== TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
exp = TREE_OPERAND (exp, 0);
return (TREE_CODE_CLASS (TREE_CODE (exp)) == 'c'
|| (DECL_P (exp)
&& ! TREE_ADDRESSABLE (exp)
&& ! TREE_THIS_VOLATILE (exp)
&& ! DECL_NONLOCAL (exp)
&& ! TREE_PUBLIC (exp)
&& ! DECL_EXTERNAL (exp)
&& (! TREE_STATIC (exp) || DECL_REGISTER (exp))));
}
static tree
range_binop (code, type, arg0, upper0_p, arg1, upper1_p)
enum tree_code code;
tree type;
tree arg0, arg1;
int upper0_p, upper1_p;
{
tree tem;
int result;
int sgn0, sgn1;
if (arg0 != 0 && arg1 != 0)
{
tem = fold (build (code, type != 0 ? type : TREE_TYPE (arg0),
arg0, convert (TREE_TYPE (arg0), arg1)));
STRIP_NOPS (tem);
return TREE_CODE (tem) == INTEGER_CST ? tem : 0;
}
if (TREE_CODE_CLASS (code) != '<')
return 0;
sgn0 = arg0 != 0 ? 0 : (upper0_p ? 1 : -1);
sgn1 = arg1 != 0 ? 0 : (upper1_p ? 1 : -1);
switch (code)
{
case EQ_EXPR:
result = sgn0 == sgn1;
break;
case NE_EXPR:
result = sgn0 != sgn1;
break;
case LT_EXPR:
result = sgn0 < sgn1;
break;
case LE_EXPR:
result = sgn0 <= sgn1;
break;
case GT_EXPR:
result = sgn0 > sgn1;
break;
case GE_EXPR:
result = sgn0 >= sgn1;
break;
default:
abort ();
}
return convert (type, result ? integer_one_node : integer_zero_node);
}
static tree
make_range (exp, pin_p, plow, phigh)
tree exp;
int *pin_p;
tree *plow, *phigh;
{
enum tree_code code;
tree arg0 = NULL_TREE, arg1 = NULL_TREE, type = NULL_TREE;
tree orig_type = NULL_TREE;
int in_p, n_in_p;
tree low, high, n_low, n_high;
in_p = 0, low = high = convert (TREE_TYPE (exp), integer_zero_node);
while (1)
{
code = TREE_CODE (exp);
if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
{
arg0 = TREE_OPERAND (exp, 0);
if (TREE_CODE_CLASS (code) == '<'
|| TREE_CODE_CLASS (code) == '1'
|| TREE_CODE_CLASS (code) == '2')
type = TREE_TYPE (arg0);
if (TREE_CODE_CLASS (code) == '2'
|| TREE_CODE_CLASS (code) == '<'
|| (TREE_CODE_CLASS (code) == 'e'
&& TREE_CODE_LENGTH (code) > 1))
arg1 = TREE_OPERAND (exp, 1);
}
if (type != NULL_TREE && orig_type == NULL_TREE)
orig_type = type;
switch (code)
{
case TRUTH_NOT_EXPR:
in_p = ! in_p, exp = arg0;
continue;
case EQ_EXPR: case NE_EXPR:
case LT_EXPR: case LE_EXPR: case GE_EXPR: case GT_EXPR:
if (low == 0 || high == 0
|| ! integer_zerop (low) || ! integer_zerop (high)
|| TREE_CODE (arg1) != INTEGER_CST)
break;
switch (code)
{
case NE_EXPR:
low = high = arg1;
break;
case EQ_EXPR:
in_p = ! in_p, low = high = arg1;
break;
case GT_EXPR:
low = 0, high = arg1;
break;
case GE_EXPR:
in_p = ! in_p, low = arg1, high = 0;
break;
case LT_EXPR:
low = arg1, high = 0;
break;
case LE_EXPR:
in_p = ! in_p, low = 0, high = arg1;
break;
default:
abort ();
}
exp = arg0;
if (TREE_UNSIGNED (type) && (low == 0 || high == 0))
{
if (! merge_ranges (&n_in_p, &n_low, &n_high, in_p, low, high,
1, convert (type, integer_zero_node),
NULL_TREE))
break;
in_p = n_in_p, low = n_low, high = n_high;
if (high == 0 && low)
{
in_p = ! in_p;
high = range_binop (MINUS_EXPR, NULL_TREE, low, 0,
integer_one_node, 0);
low = convert (type, integer_zero_node);
}
}
continue;
case NEGATE_EXPR:
n_low = range_binop (MINUS_EXPR, type,
convert (type, integer_zero_node), 0, high, 1);
n_high = range_binop (MINUS_EXPR, type,
convert (type, integer_zero_node), 0, low, 0);
low = n_low, high = n_high;
exp = arg0;
continue;
case BIT_NOT_EXPR:
exp = build (MINUS_EXPR, type, negate_expr (arg0),
convert (type, integer_one_node));
continue;
case PLUS_EXPR: case MINUS_EXPR:
if (TREE_CODE (arg1) != INTEGER_CST)
break;
n_low = range_binop (code == MINUS_EXPR ? PLUS_EXPR : MINUS_EXPR,
type, low, 0, arg1, 0);
n_high = range_binop (code == MINUS_EXPR ? PLUS_EXPR : MINUS_EXPR,
type, high, 1, arg1, 0);
if ((n_low != 0 && TREE_OVERFLOW (n_low))
|| (n_high != 0 && TREE_OVERFLOW (n_high)))
break;
if (n_low && n_high && tree_int_cst_lt (n_high, n_low))
{
low = range_binop (PLUS_EXPR, type, n_high, 0,
integer_one_node, 0);
high = range_binop (MINUS_EXPR, type, n_low, 0,
integer_one_node, 0);
if (tree_int_cst_equal (n_low, low)
&& tree_int_cst_equal (n_high, high))
low = high = 0;
else
in_p = ! in_p;
}
else
low = n_low, high = n_high;
exp = arg0;
continue;
case NOP_EXPR: case NON_LVALUE_EXPR: case CONVERT_EXPR:
if (TYPE_PRECISION (type) > TYPE_PRECISION (orig_type))
break;
if (! INTEGRAL_TYPE_P (type)
|| (low != 0 && ! int_fits_type_p (low, type))
|| (high != 0 && ! int_fits_type_p (high, type)))
break;
n_low = low, n_high = high;
if (n_low != 0)
n_low = convert (type, n_low);
if (n_high != 0)
n_high = convert (type, n_high);
if (TREE_UNSIGNED (type) && ! TREE_UNSIGNED (TREE_TYPE (exp)))
{
tree equiv_type = (*lang_hooks.types.type_for_mode)
(TYPE_MODE (type), 1);
tree high_positive;
high_positive
= TYPE_MAX_VALUE (equiv_type) ? TYPE_MAX_VALUE (equiv_type)
: TYPE_MAX_VALUE (type);
if (TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (exp)))
high_positive = fold (build (RSHIFT_EXPR, type,
convert (type, high_positive),
convert (type, integer_one_node)));
if (low != 0)
{
if (! merge_ranges (&n_in_p, &n_low, &n_high,
1, n_low, n_high,
1, convert (type, integer_zero_node),
high_positive))
break;
in_p = (n_in_p == in_p);
}
else
{
if (! merge_ranges (&n_in_p, &n_low, &n_high,
0, n_low, n_high,
1, convert (type, integer_zero_node),
high_positive))
break;
in_p = (in_p != n_in_p);
}
}
exp = arg0;
low = n_low, high = n_high;
continue;
default:
break;
}
break;
}
if (TREE_CODE (exp) == INTEGER_CST)
{
in_p = in_p == (integer_onep (range_binop (GE_EXPR, integer_type_node,
exp, 0, low, 0))
&& integer_onep (range_binop (LE_EXPR, integer_type_node,
exp, 1, high, 1)));
low = high = 0;
exp = 0;
}
*pin_p = in_p, *plow = low, *phigh = high;
return exp;
}
static tree
build_range_check (type, exp, in_p, low, high)
tree type;
tree exp;
int in_p;
tree low, high;
{
tree etype = TREE_TYPE (exp);
tree value;
if (! in_p
&& (0 != (value = build_range_check (type, exp, 1, low, high))))
return invert_truthvalue (value);
if (low == 0 && high == 0)
return convert (type, integer_one_node);
if (low == 0)
return fold (build (LE_EXPR, type, exp, high));
if (high == 0)
return fold (build (GE_EXPR, type, exp, low));
if (operand_equal_p (low, high, 0))
return fold (build (EQ_EXPR, type, exp, low));
if (integer_zerop (low))
{
if (! TREE_UNSIGNED (etype))
{
etype = (*lang_hooks.types.unsigned_type) (etype);
high = convert (etype, high);
exp = convert (etype, exp);
}
return build_range_check (type, exp, 1, 0, high);
}
if (integer_onep (low) && TREE_CODE (high) == INTEGER_CST)
{
unsigned HOST_WIDE_INT lo;
HOST_WIDE_INT hi;
int prec;
prec = TYPE_PRECISION (etype);
if (prec <= HOST_BITS_PER_WIDE_INT)
{
hi = 0;
lo = ((unsigned HOST_WIDE_INT) 1 << (prec - 1)) - 1;
}
else
{
hi = ((HOST_WIDE_INT) 1 << (prec - HOST_BITS_PER_WIDE_INT - 1)) - 1;
lo = (unsigned HOST_WIDE_INT) -1;
}
if (TREE_INT_CST_HIGH (high) == hi && TREE_INT_CST_LOW (high) == lo)
{
if (TREE_UNSIGNED (etype))
{
etype = (*lang_hooks.types.signed_type) (etype);
exp = convert (etype, exp);
}
return fold (build (GT_EXPR, type, exp,
convert (etype, integer_zero_node)));
}
}
if (0 != (value = const_binop (MINUS_EXPR, high, low, 0))
&& ! TREE_OVERFLOW (value))
return build_range_check (type,
fold (build (MINUS_EXPR, etype, exp, low)),
1, convert (etype, integer_zero_node), value);
return 0;
}
static int
merge_ranges (pin_p, plow, phigh, in0_p, low0, high0, in1_p, low1, high1)
int *pin_p;
tree *plow, *phigh;
int in0_p, in1_p;
tree low0, high0, low1, high1;
{
int no_overlap;
int subset;
int temp;
tree tem;
int in_p;
tree low, high;
int lowequal = ((low0 == 0 && low1 == 0)
|| integer_onep (range_binop (EQ_EXPR, integer_type_node,
low0, 0, low1, 0)));
int highequal = ((high0 == 0 && high1 == 0)
|| integer_onep (range_binop (EQ_EXPR, integer_type_node,
high0, 1, high1, 1)));
if (integer_onep (range_binop (GT_EXPR, integer_type_node,
low0, 0, low1, 0))
|| (lowequal
&& integer_onep (range_binop (GT_EXPR, integer_type_node,
high1, 1, high0, 1))))
{
temp = in0_p, in0_p = in1_p, in1_p = temp;
tem = low0, low0 = low1, low1 = tem;
tem = high0, high0 = high1, high1 = tem;
}
no_overlap = integer_onep (range_binop (LT_EXPR, integer_type_node,
high0, 1, low1, 0));
subset = integer_onep (range_binop (LE_EXPR, integer_type_node,
high1, 1, high0, 1));
if (in0_p && in1_p)
{
if (no_overlap)
in_p = 0, low = high = 0;
else if (subset)
in_p = 1, low = low1, high = high1;
else
in_p = 1, low = low1, high = high0;
}
else if (in0_p && ! in1_p)
{
if (no_overlap)
in_p = 1, low = low0, high = high0;
else if (lowequal && highequal)
in_p = 0, low = high = 0;
else if (subset && lowequal)
{
in_p = 1, high = high0;
low = range_binop (PLUS_EXPR, NULL_TREE, high1, 0,
integer_one_node, 0);
}
else if (! subset || highequal)
{
in_p = 1, low = low0;
high = range_binop (MINUS_EXPR, NULL_TREE, low1, 0,
integer_one_node, 0);
}
else
return 0;
}
else if (! in0_p && in1_p)
{
if (no_overlap)
in_p = 1, low = low1, high = high1;
else if (subset || highequal)
in_p = 0, low = high = 0;
else
{
in_p = 1, high = high1;
low = range_binop (PLUS_EXPR, NULL_TREE, high0, 1,
integer_one_node, 0);
}
}
else
{
if (no_overlap)
{
if (integer_onep (range_binop (EQ_EXPR, integer_type_node,
range_binop (PLUS_EXPR, NULL_TREE,
high0, 1,
integer_one_node, 1),
1, low1, 0)))
in_p = 0, low = low0, high = high1;
else
return 0;
}
else if (subset)
in_p = 0, low = low0, high = high0;
else
in_p = 0, low = low0, high = high1;
}
*pin_p = in_p, *plow = low, *phigh = high;
return 1;
}
static tree
fold_range_test (exp)
tree exp;
{
int or_op = (TREE_CODE (exp) == TRUTH_ORIF_EXPR
|| TREE_CODE (exp) == TRUTH_OR_EXPR);
int in0_p, in1_p, in_p;
tree low0, low1, low, high0, high1, high;
tree lhs = make_range (TREE_OPERAND (exp, 0), &in0_p, &low0, &high0);
tree rhs = make_range (TREE_OPERAND (exp, 1), &in1_p, &low1, &high1);
tree tem;
if (or_op)
in0_p = ! in0_p, in1_p = ! in1_p;
if ((lhs == 0 || rhs == 0 || operand_equal_p (lhs, rhs, 0))
&& merge_ranges (&in_p, &low, &high, in0_p, low0, high0,
in1_p, low1, high1)
&& 0 != (tem = (build_range_check (TREE_TYPE (exp),
lhs != 0 ? lhs
: rhs != 0 ? rhs : integer_zero_node,
in_p, low, high))))
return or_op ? invert_truthvalue (tem) : tem;
else if (BRANCH_COST >= 2
&& lhs != 0 && rhs != 0
&& (TREE_CODE (exp) == TRUTH_ANDIF_EXPR
|| TREE_CODE (exp) == TRUTH_ORIF_EXPR)
&& operand_equal_p (lhs, rhs, 0))
{
if (simple_operand_p (lhs))
return build (TREE_CODE (exp) == TRUTH_ANDIF_EXPR
? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
TREE_TYPE (exp), TREE_OPERAND (exp, 0),
TREE_OPERAND (exp, 1));
else if ((*lang_hooks.decls.global_bindings_p) () == 0
&& ! contains_placeholder_p (lhs))
{
tree common = save_expr (lhs);
if (0 != (lhs = build_range_check (TREE_TYPE (exp), common,
or_op ? ! in0_p : in0_p,
low0, high0))
&& (0 != (rhs = build_range_check (TREE_TYPE (exp), common,
or_op ? ! in1_p : in1_p,
low1, high1))))
return build (TREE_CODE (exp) == TRUTH_ANDIF_EXPR
? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
TREE_TYPE (exp), lhs, rhs);
}
}
return 0;
}
static tree
unextend (c, p, unsignedp, mask)
tree c;
int p;
int unsignedp;
tree mask;
{
tree type = TREE_TYPE (c);
int modesize = GET_MODE_BITSIZE (TYPE_MODE (type));
tree temp;
if (p == modesize || unsignedp)
return c;
temp = const_binop (RSHIFT_EXPR, c, size_int (p - 1), 0);
temp = const_binop (BIT_AND_EXPR, temp, size_int (1), 0);
if (TREE_UNSIGNED (type))
temp = convert ((*lang_hooks.types.signed_type) (type), temp);
temp = const_binop (LSHIFT_EXPR, temp, size_int (modesize - 1), 0);
temp = const_binop (RSHIFT_EXPR, temp, size_int (modesize - p - 1), 0);
if (mask != 0)
temp = const_binop (BIT_AND_EXPR, temp, convert (TREE_TYPE (c), mask), 0);
if (TREE_UNSIGNED (type))
temp = convert (type, temp);
return convert (type, const_binop (BIT_XOR_EXPR, c, temp, 0));
}
static tree
fold_truthop (code, truth_type, lhs, rhs)
enum tree_code code;
tree truth_type, lhs, rhs;
{
enum tree_code wanted_code;
enum tree_code lcode, rcode;
tree ll_arg, lr_arg, rl_arg, rr_arg;
tree ll_inner, lr_inner, rl_inner, rr_inner;
HOST_WIDE_INT ll_bitsize, ll_bitpos, lr_bitsize, lr_bitpos;
HOST_WIDE_INT rl_bitsize, rl_bitpos, rr_bitsize, rr_bitpos;
HOST_WIDE_INT xll_bitpos, xlr_bitpos, xrl_bitpos, xrr_bitpos;
HOST_WIDE_INT lnbitsize, lnbitpos, rnbitsize, rnbitpos;
int ll_unsignedp, lr_unsignedp, rl_unsignedp, rr_unsignedp;
enum machine_mode ll_mode, lr_mode, rl_mode, rr_mode;
enum machine_mode lnmode, rnmode;
tree ll_mask, lr_mask, rl_mask, rr_mask;
tree ll_and_mask, lr_and_mask, rl_and_mask, rr_and_mask;
tree l_const, r_const;
tree lntype, rntype, result;
int first_bit, end_bit;
int volatilep;
if (TREE_SIDE_EFFECTS (lhs) || TREE_SIDE_EFFECTS (rhs))
return 0;
lcode = TREE_CODE (lhs);
rcode = TREE_CODE (rhs);
if (lcode == BIT_AND_EXPR && integer_onep (TREE_OPERAND (lhs, 1)))
lcode = NE_EXPR, lhs = build (NE_EXPR, truth_type, lhs, integer_zero_node);
if (rcode == BIT_AND_EXPR && integer_onep (TREE_OPERAND (rhs, 1)))
rcode = NE_EXPR, rhs = build (NE_EXPR, truth_type, rhs, integer_zero_node);
if (TREE_CODE_CLASS (lcode) != '<' || TREE_CODE_CLASS (rcode) != '<')
return 0;
code = ((code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR)
? TRUTH_AND_EXPR : TRUTH_OR_EXPR);
ll_arg = TREE_OPERAND (lhs, 0);
lr_arg = TREE_OPERAND (lhs, 1);
rl_arg = TREE_OPERAND (rhs, 0);
rr_arg = TREE_OPERAND (rhs, 1);
if (simple_operand_p (ll_arg)
&& simple_operand_p (lr_arg)
&& !FLOAT_TYPE_P (TREE_TYPE (ll_arg)))
{
int compcode;
if (operand_equal_p (ll_arg, rl_arg, 0)
&& operand_equal_p (lr_arg, rr_arg, 0))
{
int lcompcode, rcompcode;
lcompcode = comparison_to_compcode (lcode);
rcompcode = comparison_to_compcode (rcode);
compcode = (code == TRUTH_AND_EXPR)
? lcompcode & rcompcode
: lcompcode | rcompcode;
}
else if (operand_equal_p (ll_arg, rr_arg, 0)
&& operand_equal_p (lr_arg, rl_arg, 0))
{
int lcompcode, rcompcode;
rcode = swap_tree_comparison (rcode);
lcompcode = comparison_to_compcode (lcode);
rcompcode = comparison_to_compcode (rcode);
compcode = (code == TRUTH_AND_EXPR)
? lcompcode & rcompcode
: lcompcode | rcompcode;
}
else
compcode = -1;
if (compcode == COMPCODE_TRUE)
return convert (truth_type, integer_one_node);
else if (compcode == COMPCODE_FALSE)
return convert (truth_type, integer_zero_node);
else if (compcode != -1)
return build (compcode_to_comparison (compcode),
truth_type, ll_arg, lr_arg);
}
if (BRANCH_COST >= 2
&& ! FLOAT_TYPE_P (TREE_TYPE (rl_arg))
&& simple_operand_p (rl_arg)
&& simple_operand_p (rr_arg))
{
if (code == TRUTH_OR_EXPR
&& lcode == NE_EXPR && integer_zerop (lr_arg)
&& rcode == NE_EXPR && integer_zerop (rr_arg)
&& TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg))
return build (NE_EXPR, truth_type,
build (BIT_IOR_EXPR, TREE_TYPE (ll_arg),
ll_arg, rl_arg),
integer_zero_node);
if (code == TRUTH_AND_EXPR
&& lcode == EQ_EXPR && integer_zerop (lr_arg)
&& rcode == EQ_EXPR && integer_zerop (rr_arg)
&& TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg))
return build (EQ_EXPR, truth_type,
build (BIT_IOR_EXPR, TREE_TYPE (ll_arg),
ll_arg, rl_arg),
integer_zero_node);
return build (code, truth_type, lhs, rhs);
}
if ((lcode != EQ_EXPR && lcode != NE_EXPR)
|| (rcode != EQ_EXPR && rcode != NE_EXPR))
return 0;
volatilep = 0;
ll_inner = decode_field_reference (ll_arg,
&ll_bitsize, &ll_bitpos, &ll_mode,
&ll_unsignedp, &volatilep, &ll_mask,
&ll_and_mask);
lr_inner = decode_field_reference (lr_arg,
&lr_bitsize, &lr_bitpos, &lr_mode,
&lr_unsignedp, &volatilep, &lr_mask,
&lr_and_mask);
rl_inner = decode_field_reference (rl_arg,
&rl_bitsize, &rl_bitpos, &rl_mode,
&rl_unsignedp, &volatilep, &rl_mask,
&rl_and_mask);
rr_inner = decode_field_reference (rr_arg,
&rr_bitsize, &rr_bitpos, &rr_mode,
&rr_unsignedp, &volatilep, &rr_mask,
&rr_and_mask);
if (volatilep || ll_inner == 0 || rl_inner == 0
|| ! operand_equal_p (ll_inner, rl_inner, 0))
return 0;
if (TREE_CODE (lr_arg) == INTEGER_CST
&& TREE_CODE (rr_arg) == INTEGER_CST)
l_const = lr_arg, r_const = rr_arg;
else if (lr_inner == 0 || rr_inner == 0
|| ! operand_equal_p (lr_inner, rr_inner, 0))
return 0;
else
l_const = r_const = 0;
wanted_code = (code == TRUTH_AND_EXPR ? EQ_EXPR : NE_EXPR);
if (lcode != wanted_code)
{
if (l_const && integer_zerop (l_const) && integer_pow2p (ll_mask))
{
ll_unsignedp = 1;
l_const = ll_mask;
}
else
return 0;
}
if (rcode != wanted_code)
{
if (r_const && integer_zerop (r_const) && integer_pow2p (rl_mask))
{
rl_unsignedp = 1;
r_const = rl_mask;
}
else
return 0;
}
if (! (*lang_hooks.can_use_bit_fields_p) ())
return 0;
first_bit = MIN (ll_bitpos, rl_bitpos);
end_bit = MAX (ll_bitpos + ll_bitsize, rl_bitpos + rl_bitsize);
lnmode = get_best_mode (end_bit - first_bit, first_bit,
TYPE_ALIGN (TREE_TYPE (ll_inner)), word_mode,
volatilep);
if (lnmode == VOIDmode)
return 0;
lnbitsize = GET_MODE_BITSIZE (lnmode);
lnbitpos = first_bit & ~ (lnbitsize - 1);
lntype = (*lang_hooks.types.type_for_size) (lnbitsize, 1);
xll_bitpos = ll_bitpos - lnbitpos, xrl_bitpos = rl_bitpos - lnbitpos;
if (BYTES_BIG_ENDIAN)
{
xll_bitpos = lnbitsize - xll_bitpos - ll_bitsize;
xrl_bitpos = lnbitsize - xrl_bitpos - rl_bitsize;
}
ll_mask = const_binop (LSHIFT_EXPR, convert (lntype, ll_mask),
size_int (xll_bitpos), 0);
rl_mask = const_binop (LSHIFT_EXPR, convert (lntype, rl_mask),
size_int (xrl_bitpos), 0);
if (l_const)
{
l_const = convert (lntype, l_const);
l_const = unextend (l_const, ll_bitsize, ll_unsignedp, ll_and_mask);
l_const = const_binop (LSHIFT_EXPR, l_const, size_int (xll_bitpos), 0);
if (! integer_zerop (const_binop (BIT_AND_EXPR, l_const,
fold (build1 (BIT_NOT_EXPR,
lntype, ll_mask)),
0)))
{
warning ("comparison is always %d", wanted_code == NE_EXPR);
return convert (truth_type,
wanted_code == NE_EXPR
? integer_one_node : integer_zero_node);
}
}
if (r_const)
{
r_const = convert (lntype, r_const);
r_const = unextend (r_const, rl_bitsize, rl_unsignedp, rl_and_mask);
r_const = const_binop (LSHIFT_EXPR, r_const, size_int (xrl_bitpos), 0);
if (! integer_zerop (const_binop (BIT_AND_EXPR, r_const,
fold (build1 (BIT_NOT_EXPR,
lntype, rl_mask)),
0)))
{
warning ("comparison is always %d", wanted_code == NE_EXPR);
return convert (truth_type,
wanted_code == NE_EXPR
? integer_one_node : integer_zero_node);
}
}
if (l_const == 0)
{
if (ll_bitsize != lr_bitsize || rl_bitsize != rr_bitsize
|| ll_unsignedp != lr_unsignedp || rl_unsignedp != rr_unsignedp
|| ll_bitpos - rl_bitpos != lr_bitpos - rr_bitpos)
return 0;
first_bit = MIN (lr_bitpos, rr_bitpos);
end_bit = MAX (lr_bitpos + lr_bitsize, rr_bitpos + rr_bitsize);
rnmode = get_best_mode (end_bit - first_bit, first_bit,
TYPE_ALIGN (TREE_TYPE (lr_inner)), word_mode,
volatilep);
if (rnmode == VOIDmode)
return 0;
rnbitsize = GET_MODE_BITSIZE (rnmode);
rnbitpos = first_bit & ~ (rnbitsize - 1);
rntype = (*lang_hooks.types.type_for_size) (rnbitsize, 1);
xlr_bitpos = lr_bitpos - rnbitpos, xrr_bitpos = rr_bitpos - rnbitpos;
if (BYTES_BIG_ENDIAN)
{
xlr_bitpos = rnbitsize - xlr_bitpos - lr_bitsize;
xrr_bitpos = rnbitsize - xrr_bitpos - rr_bitsize;
}
lr_mask = const_binop (LSHIFT_EXPR, convert (rntype, lr_mask),
size_int (xlr_bitpos), 0);
rr_mask = const_binop (LSHIFT_EXPR, convert (rntype, rr_mask),
size_int (xrr_bitpos), 0);
ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0);
lr_mask = const_binop (BIT_IOR_EXPR, lr_mask, rr_mask, 0);
if (lnbitsize == rnbitsize && xll_bitpos == xlr_bitpos)
{
lhs = make_bit_field_ref (ll_inner, lntype, lnbitsize, lnbitpos,
ll_unsignedp || rl_unsignedp);
if (! all_ones_mask_p (ll_mask, lnbitsize))
lhs = build (BIT_AND_EXPR, lntype, lhs, ll_mask);
rhs = make_bit_field_ref (lr_inner, rntype, rnbitsize, rnbitpos,
lr_unsignedp || rr_unsignedp);
if (! all_ones_mask_p (lr_mask, rnbitsize))
rhs = build (BIT_AND_EXPR, rntype, rhs, lr_mask);
return build (wanted_code, truth_type, lhs, rhs);
}
if ((ll_bitsize + ll_bitpos == rl_bitpos
&& lr_bitsize + lr_bitpos == rr_bitpos)
|| (ll_bitpos == rl_bitpos + rl_bitsize
&& lr_bitpos == rr_bitpos + rr_bitsize))
{
tree type;
lhs = make_bit_field_ref (ll_inner, lntype, ll_bitsize + rl_bitsize,
MIN (ll_bitpos, rl_bitpos), ll_unsignedp);
rhs = make_bit_field_ref (lr_inner, rntype, lr_bitsize + rr_bitsize,
MIN (lr_bitpos, rr_bitpos), lr_unsignedp);
ll_mask = const_binop (RSHIFT_EXPR, ll_mask,
size_int (MIN (xll_bitpos, xrl_bitpos)), 0);
lr_mask = const_binop (RSHIFT_EXPR, lr_mask,
size_int (MIN (xlr_bitpos, xrr_bitpos)), 0);
type = lntype;
if (lntype != rntype)
{
if (lnbitsize > rnbitsize)
{
lhs = convert (rntype, lhs);
ll_mask = convert (rntype, ll_mask);
type = rntype;
}
else if (lnbitsize < rnbitsize)
{
rhs = convert (lntype, rhs);
lr_mask = convert (lntype, lr_mask);
type = lntype;
}
}
if (! all_ones_mask_p (ll_mask, ll_bitsize + rl_bitsize))
lhs = build (BIT_AND_EXPR, type, lhs, ll_mask);
if (! all_ones_mask_p (lr_mask, lr_bitsize + rr_bitsize))
rhs = build (BIT_AND_EXPR, type, rhs, lr_mask);
return build (wanted_code, truth_type, lhs, rhs);
}
return 0;
}
result = const_binop (BIT_AND_EXPR, ll_mask, rl_mask, 0);
if (! integer_zerop (result)
&& simple_cst_equal (const_binop (BIT_AND_EXPR, result, l_const, 0),
const_binop (BIT_AND_EXPR, result, r_const, 0)) != 1)
{
if (wanted_code == NE_EXPR)
{
warning ("`or' of unmatched not-equal tests is always 1");
return convert (truth_type, integer_one_node);
}
else
{
warning ("`and' of mutually exclusive equal-tests is always 0");
return convert (truth_type, integer_zero_node);
}
}
result = make_bit_field_ref (ll_inner, lntype, lnbitsize, lnbitpos,
ll_unsignedp || rl_unsignedp);
ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask, 0);
if (! all_ones_mask_p (ll_mask, lnbitsize))
result = build (BIT_AND_EXPR, lntype, result, ll_mask);
return build (wanted_code, truth_type, result,
const_binop (BIT_IOR_EXPR, l_const, r_const, 0));
}
static tree
optimize_minmax_comparison (t)
tree t;
{
tree type = TREE_TYPE (t);
tree arg0 = TREE_OPERAND (t, 0);
enum tree_code op_code;
tree comp_const = TREE_OPERAND (t, 1);
tree minmax_const;
int consts_equal, consts_lt;
tree inner;
STRIP_SIGN_NOPS (arg0);
op_code = TREE_CODE (arg0);
minmax_const = TREE_OPERAND (arg0, 1);
consts_equal = tree_int_cst_equal (minmax_const, comp_const);
consts_lt = tree_int_cst_lt (minmax_const, comp_const);
inner = TREE_OPERAND (arg0, 0);
if ((op_code != MIN_EXPR && op_code != MAX_EXPR)
|| TREE_CODE (comp_const) != INTEGER_CST
|| TREE_CONSTANT_OVERFLOW (comp_const)
|| TREE_CODE (minmax_const) != INTEGER_CST
|| TREE_CONSTANT_OVERFLOW (minmax_const))
return t;
switch (TREE_CODE (t))
{
case NE_EXPR: case LT_EXPR: case LE_EXPR:
return
invert_truthvalue (optimize_minmax_comparison (invert_truthvalue (t)));
case GE_EXPR:
return
fold (build (TRUTH_ORIF_EXPR, type,
optimize_minmax_comparison
(build (EQ_EXPR, type, arg0, comp_const)),
optimize_minmax_comparison
(build (GT_EXPR, type, arg0, comp_const))));
case EQ_EXPR:
if (op_code == MAX_EXPR && consts_equal)
return fold (build (LE_EXPR, type, inner, comp_const));
else if (op_code == MAX_EXPR && consts_lt)
return fold (build (EQ_EXPR, type, inner, comp_const));
else if (op_code == MAX_EXPR)
return omit_one_operand (type, integer_zero_node, inner);
else if (consts_equal)
return fold (build (GE_EXPR, type, inner, comp_const));
else if (consts_lt)
return omit_one_operand (type, integer_zero_node, inner);
else
return fold (build (EQ_EXPR, type, inner, comp_const));
case GT_EXPR:
if (op_code == MAX_EXPR && (consts_equal || consts_lt))
return fold (build (GT_EXPR, type, inner, comp_const));
else if (op_code == MAX_EXPR)
return omit_one_operand (type, integer_one_node, inner);
else if (op_code == MIN_EXPR && (consts_equal || consts_lt))
return omit_one_operand (type, integer_zero_node, inner);
else
return fold (build (GT_EXPR, type, inner, comp_const));
default:
return t;
}
}
static tree
extract_muldiv (t, c, code, wide_type)
tree t;
tree c;
enum tree_code code;
tree wide_type;
{
static int depth;
tree ret;
if (depth > 3)
return NULL;
depth++;
ret = extract_muldiv_1 (t, c, code, wide_type);
depth--;
return ret;
}
static tree
extract_muldiv_1 (t, c, code, wide_type)
tree t;
tree c;
enum tree_code code;
tree wide_type;
{
tree type = TREE_TYPE (t);
enum tree_code tcode = TREE_CODE (t);
tree ctype = (wide_type != 0 && (GET_MODE_SIZE (TYPE_MODE (wide_type))
> GET_MODE_SIZE (TYPE_MODE (type)))
? wide_type : type);
tree t1, t2;
int same_p = tcode == code;
tree op0 = NULL_TREE, op1 = NULL_TREE;
if (integer_zerop (c))
return NULL_TREE;
if (TREE_CODE_CLASS (tcode) == '1')
op0 = TREE_OPERAND (t, 0);
if (TREE_CODE_CLASS (tcode) == '2')
op0 = TREE_OPERAND (t, 0), op1 = TREE_OPERAND (t, 1);
switch (tcode)
{
case INTEGER_CST:
if (code == MULT_EXPR
|| integer_zerop (const_binop (TRUNC_MOD_EXPR, t, c, 0)))
return const_binop (code, convert (ctype, t), convert (ctype, c), 0);
break;
case CONVERT_EXPR: case NON_LVALUE_EXPR: case NOP_EXPR:
if ((TREE_CODE_CLASS (TREE_CODE (op0)) == '<'
|| TREE_CODE_CLASS (TREE_CODE (op0)) == '1'
|| TREE_CODE_CLASS (TREE_CODE (op0)) == '2'
|| TREE_CODE_CLASS (TREE_CODE (op0)) == 'e')
&& ((TREE_UNSIGNED (TREE_TYPE (op0))
&& ! (TREE_CODE (TREE_TYPE (op0)) == INTEGER_TYPE
&& TYPE_IS_SIZETYPE (TREE_TYPE (op0)))
&& (GET_MODE_SIZE (TYPE_MODE (ctype))
> GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))))
|| (GET_MODE_SIZE (TYPE_MODE (ctype))
< GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0))))))
break;
if (0 != (t1 = extract_muldiv (op0, convert (TREE_TYPE (op0), c), code,
code == MULT_EXPR ? ctype : NULL_TREE)))
return t1;
break;
case NEGATE_EXPR: case ABS_EXPR:
if ((t1 = extract_muldiv (op0, c, code, wide_type)) != 0)
return fold (build1 (tcode, ctype, convert (ctype, t1)));
break;
case MIN_EXPR: case MAX_EXPR:
if (TREE_UNSIGNED (ctype) != TREE_UNSIGNED (type))
break;
if ((t1 = extract_muldiv (op0, c, code, wide_type)) != 0
&& (t2 = extract_muldiv (op1, c, code, wide_type)) != 0)
{
if (tree_int_cst_sgn (c) < 0)
tcode = (tcode == MIN_EXPR ? MAX_EXPR : MIN_EXPR);
return fold (build (tcode, ctype, convert (ctype, t1),
convert (ctype, t2)));
}
break;
case WITH_RECORD_EXPR:
if ((t1 = extract_muldiv (TREE_OPERAND (t, 0), c, code, wide_type)) != 0)
return build (WITH_RECORD_EXPR, TREE_TYPE (t1), t1,
TREE_OPERAND (t, 1));
break;
case SAVE_EXPR:
if (SAVE_EXPR_RTL (t) == 0 && ! TREE_SIDE_EFFECTS (TREE_OPERAND (t, 0))
&& 0 != (t1 = extract_muldiv (TREE_OPERAND (t, 0), c, code,
wide_type)))
{
t1 = save_expr (t1);
if (SAVE_EXPR_PERSISTENT_P (t) && TREE_CODE (t1) == SAVE_EXPR)
SAVE_EXPR_PERSISTENT_P (t1) = 1;
if (is_pending_size (t))
put_pending_size (t1);
return t1;
}
break;
case LSHIFT_EXPR: case RSHIFT_EXPR:
if (TREE_CODE (op1) == INTEGER_CST
&& TYPE_PRECISION (TREE_TYPE (size_one_node)) > TREE_INT_CST_LOW (op1)
&& TREE_INT_CST_HIGH (op1) == 0
&& 0 != (t1 = convert (ctype,
const_binop (LSHIFT_EXPR, size_one_node,
op1, 0)))
&& ! TREE_OVERFLOW (t1))
return extract_muldiv (build (tcode == LSHIFT_EXPR
? MULT_EXPR : FLOOR_DIV_EXPR,
ctype, convert (ctype, op0), t1),
c, code, wide_type);
break;
case PLUS_EXPR: case MINUS_EXPR:
t1 = extract_muldiv (op0, c, code, wide_type);
t2 = extract_muldiv (op1, c, code, wide_type);
if (t1 != 0 && t2 != 0
&& (code == MULT_EXPR
|| (multiple_of_p (ctype, op0, c)
&& multiple_of_p (ctype, op1, c))))
return fold (build (tcode, ctype, convert (ctype, t1),
convert (ctype, t2)));
if (tcode == MINUS_EXPR)
tcode = PLUS_EXPR, op1 = negate_expr (op1);
if (TREE_CODE (op1) != INTEGER_CST)
break;
if (tree_int_cst_sgn (op1) < 0 || tree_int_cst_sgn (c) < 0)
{
if (code == CEIL_DIV_EXPR)
code = FLOOR_DIV_EXPR;
else if (code == FLOOR_DIV_EXPR)
code = CEIL_DIV_EXPR;
else if (code != MULT_EXPR
&& code != CEIL_MOD_EXPR && code != FLOOR_MOD_EXPR)
break;
}
if (code == MULT_EXPR
|| integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c, 0)))
{
op1 = const_binop (code, convert (ctype, op1), convert (ctype, c), 0);
if (op1 == 0 || TREE_OVERFLOW (op1))
break;
}
else
break;
if (TREE_UNSIGNED (ctype)
&& ! (TREE_CODE (ctype) == INTEGER_TYPE && TYPE_IS_SIZETYPE (ctype))
&& ctype != type)
break;
if (t1 != 0 && (TREE_CODE (t1) != code || code == MULT_EXPR))
return fold (build (tcode, ctype, convert (ctype, t1), op1));
if (code == MULT_EXPR)
return fold (build (tcode, ctype, fold (build (code, ctype,
convert (ctype, op0),
convert (ctype, c))),
op1));
break;
case MULT_EXPR:
if ((code == TRUNC_MOD_EXPR || code == CEIL_MOD_EXPR
|| code == FLOOR_MOD_EXPR || code == ROUND_MOD_EXPR)
&& TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
&& integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c, 0)))
return omit_one_operand (type, integer_zero_node, op0);
if (TREE_CODE (op1) == INTEGER_CST && TREE_CODE (op0) != INTEGER_CST)
{
tree tmp = op0;
op0 = op1;
op1 = tmp;
}
case TRUNC_DIV_EXPR: case CEIL_DIV_EXPR: case FLOOR_DIV_EXPR:
case ROUND_DIV_EXPR: case EXACT_DIV_EXPR:
if (same_p
&& (t1 = extract_muldiv (op0, c, code, wide_type)) != 0)
return fold (build (tcode, ctype, convert (ctype, t1),
convert (ctype, op1)));
else if (tcode == MULT_EXPR && code == MULT_EXPR
&& (t1 = extract_muldiv (op1, c, code, wide_type)) != 0)
return fold (build (tcode, ctype, convert (ctype, op0),
convert (ctype, t1)));
else if (TREE_CODE (op1) != INTEGER_CST)
return 0;
if (tcode == code
&& 0 != (t1 = const_binop (MULT_EXPR, convert (ctype, op1),
convert (ctype, c), 0))
&& ! TREE_OVERFLOW (t1))
return fold (build (tcode, ctype, convert (ctype, op0), t1));
if ((! TREE_UNSIGNED (ctype)
|| (TREE_CODE (ctype) == INTEGER_TYPE && TYPE_IS_SIZETYPE (ctype)))
&& ((code == MULT_EXPR && tcode == EXACT_DIV_EXPR)
|| (tcode == MULT_EXPR
&& code != TRUNC_MOD_EXPR && code != CEIL_MOD_EXPR
&& code != FLOOR_MOD_EXPR && code != ROUND_MOD_EXPR)))
{
if (integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c, 0)))
return fold (build (tcode, ctype, convert (ctype, op0),
convert (ctype,
const_binop (TRUNC_DIV_EXPR,
op1, c, 0))));
else if (integer_zerop (const_binop (TRUNC_MOD_EXPR, c, op1, 0)))
return fold (build (code, ctype, convert (ctype, op0),
convert (ctype,
const_binop (TRUNC_DIV_EXPR,
c, op1, 0))));
}
break;
default:
break;
}
return 0;
}
static tree
strip_compound_expr (t, s)
tree t;
tree s;
{
enum tree_code code = TREE_CODE (t);
if (code == COMPOUND_EXPR && TREE_CODE (TREE_OPERAND (t, 0)) == CONVERT_EXPR
&& TREE_OPERAND (TREE_OPERAND (t, 0), 0) == s)
return TREE_OPERAND (t, 1);
else if (code == COND_EXPR)
{
TREE_OPERAND (t, 0) = strip_compound_expr (TREE_OPERAND (t, 0), s);
TREE_OPERAND (t, 1) = strip_compound_expr (TREE_OPERAND (t, 1), s);
TREE_OPERAND (t, 2) = strip_compound_expr (TREE_OPERAND (t, 2), s);
}
else if (TREE_CODE_CLASS (code) == '1')
TREE_OPERAND (t, 0) = strip_compound_expr (TREE_OPERAND (t, 0), s);
else if (TREE_CODE_CLASS (code) == '<'
|| TREE_CODE_CLASS (code) == '2')
{
TREE_OPERAND (t, 0) = strip_compound_expr (TREE_OPERAND (t, 0), s);
TREE_OPERAND (t, 1) = strip_compound_expr (TREE_OPERAND (t, 1), s);
}
return t;
}
static tree
constant_boolean_node (value, type)
int value;
tree type;
{
if (type == integer_type_node)
return value ? integer_one_node : integer_zero_node;
else if (TREE_CODE (type) == BOOLEAN_TYPE)
return (*lang_hooks.truthvalue_conversion) (value ? integer_one_node :
integer_zero_node);
else
{
tree t = build_int_2 (value, 0);
TREE_TYPE (t) = type;
return t;
}
}
static int
count_cond (expr, lim)
tree expr;
int lim;
{
int ctrue, cfalse;
if (TREE_CODE (expr) != COND_EXPR)
return 0;
else if (lim <= 0)
return 0;
ctrue = count_cond (TREE_OPERAND (expr, 1), lim - 1);
cfalse = count_cond (TREE_OPERAND (expr, 2), lim - 1 - ctrue);
return MIN (lim, 1 + ctrue + cfalse);
}
static tree
fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p)
enum tree_code code;
tree type;
tree cond;
tree arg;
int cond_first_p;
{
tree test, true_value, false_value;
tree lhs = NULL_TREE;
tree rhs = NULL_TREE;
tree *true_lhs;
tree *true_rhs;
tree *false_lhs;
tree *false_rhs;
enum tree_code lhs_code = code;
enum tree_code rhs_code = code;
tree lhs_type = type;
tree rhs_type = type;
int save = 0;
if (cond_first_p)
{
true_rhs = false_rhs = &arg;
true_lhs = &true_value;
false_lhs = &false_value;
}
else
{
true_lhs = false_lhs = &arg;
true_rhs = &true_value;
false_rhs = &false_value;
}
if (TREE_CODE (cond) == COND_EXPR)
{
test = TREE_OPERAND (cond, 0);
true_value = TREE_OPERAND (cond, 1);
false_value = TREE_OPERAND (cond, 2);
if (VOID_TYPE_P (TREE_TYPE (true_value)))
{
if (! cond_first_p)
{
lhs_code = COMPOUND_EXPR;
lhs_type = void_type_node;
}
else
lhs = true_value;
}
if (VOID_TYPE_P (TREE_TYPE (false_value)))
{
if (! cond_first_p)
{
rhs_code = COMPOUND_EXPR;
rhs_type = void_type_node;
}
else
rhs = false_value;
}
}
else
{
tree testtype = TREE_TYPE (cond);
test = cond;
true_value = convert (testtype, integer_one_node);
false_value = convert (testtype, integer_zero_node);
}
if (TREE_CODE (arg) == SAVE_EXPR)
save = 1;
else if (lhs == 0 && rhs == 0
&& !TREE_CONSTANT (arg)
&& (*lang_hooks.decls.global_bindings_p) () == 0
&& ((TREE_CODE (arg) != VAR_DECL && TREE_CODE (arg) != PARM_DECL)
|| TREE_SIDE_EFFECTS (arg)))
{
if (TREE_CODE (true_value) != COND_EXPR)
lhs = fold (build (lhs_code, lhs_type, *true_lhs, *true_rhs));
if (TREE_CODE (false_value) != COND_EXPR)
rhs = fold (build (rhs_code, rhs_type, *false_lhs, *false_rhs));
if ((lhs == 0 || ! TREE_CONSTANT (lhs))
&& (rhs == 0 || !TREE_CONSTANT (rhs)))
{
arg = save_expr (arg);
lhs = rhs = 0;
save = 1;
}
}
if (lhs == 0)
lhs = fold (build (lhs_code, lhs_type, *true_lhs, *true_rhs));
if (rhs == 0)
rhs = fold (build (rhs_code, rhs_type, *false_lhs, *false_rhs));
test = fold (build (COND_EXPR, type, test, lhs, rhs));
if (save)
return build (COMPOUND_EXPR, type,
convert (void_type_node, arg),
strip_compound_expr (test, arg));
else
return convert (type, test);
}
static bool
fold_real_zero_addition_p (type, addend, negate)
tree type, addend;
int negate;
{
if (!real_zerop (addend))
return false;
if (!HONOR_SIGNED_ZEROS (TYPE_MODE (type)))
return true;
if (TREE_CODE (addend) == REAL_CST
&& REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (addend)))
negate = !negate;
return negate && !HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type));
}
tree
fold (expr)
tree expr;
{
tree t = expr;
tree t1 = NULL_TREE;
tree tem;
tree type = TREE_TYPE (expr);
tree arg0 = NULL_TREE, arg1 = NULL_TREE;
enum tree_code code = TREE_CODE (t);
int kind = TREE_CODE_CLASS (code);
int invert;
int wins = 1;
if (code == RTL_EXPR || (code == SAVE_EXPR && SAVE_EXPR_RTL (t) != 0))
return t;
if (kind == 'c')
return t;
#ifdef MAX_INTEGER_COMPUTATION_MODE
check_max_integer_computation_mode (expr);
#endif
if (code == NOP_EXPR || code == FLOAT_EXPR || code == CONVERT_EXPR)
{
tree subop;
arg0 = TREE_OPERAND (t, 0);
if (arg0 != 0)
STRIP_SIGN_NOPS (arg0);
if (arg0 != 0 && TREE_CODE (arg0) == COMPLEX_CST)
subop = TREE_REALPART (arg0);
else
subop = arg0;
if (subop != 0 && TREE_CODE (subop) != INTEGER_CST
&& TREE_CODE (subop) != REAL_CST
)
wins = 0;
}
else if (IS_EXPR_CODE_CLASS (kind) || kind == 'r')
{
int len = first_rtl_op (code);
int i;
for (i = 0; i < len; i++)
{
tree op = TREE_OPERAND (t, i);
tree subop;
if (op == 0)
continue;
if (kind == '<' || code == RSHIFT_EXPR)
{
STRIP_SIGN_NOPS (op);
}
else
STRIP_NOPS (op);
if (TREE_CODE (op) == COMPLEX_CST)
subop = TREE_REALPART (op);
else
subop = op;
if (TREE_CODE (subop) != INTEGER_CST
&& TREE_CODE (subop) != REAL_CST)
wins = 0;
if (i == 0)
arg0 = op;
else if (i == 1)
arg1 = op;
}
}
if ((code == PLUS_EXPR || code == MULT_EXPR || code == MIN_EXPR
|| code == MAX_EXPR || code == BIT_IOR_EXPR || code == BIT_XOR_EXPR
|| code == BIT_AND_EXPR)
&& (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST))
{
tem = arg0; arg0 = arg1; arg1 = tem;
tem = TREE_OPERAND (t, 0); TREE_OPERAND (t, 0) = TREE_OPERAND (t, 1);
TREE_OPERAND (t, 1) = tem;
}
if ((code == BIT_AND_EXPR || code == BIT_IOR_EXPR
|| code == EQ_EXPR || code == NE_EXPR)
&& ((truth_value_p (TREE_CODE (arg0))
&& (truth_value_p (TREE_CODE (arg1))
|| (TREE_CODE (arg1) == BIT_AND_EXPR
&& integer_onep (TREE_OPERAND (arg1, 1)))))
|| (truth_value_p (TREE_CODE (arg1))
&& (truth_value_p (TREE_CODE (arg0))
|| (TREE_CODE (arg0) == BIT_AND_EXPR
&& integer_onep (TREE_OPERAND (arg0, 1)))))))
{
t = fold (build (code == BIT_AND_EXPR ? TRUTH_AND_EXPR
: code == BIT_IOR_EXPR ? TRUTH_OR_EXPR
: TRUTH_XOR_EXPR,
type, arg0, arg1));
if (code == EQ_EXPR)
t = invert_truthvalue (t);
return t;
}
if (TREE_CODE_CLASS (code) == '1')
{
if (TREE_CODE (arg0) == COMPOUND_EXPR)
return build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
fold (build1 (code, type, TREE_OPERAND (arg0, 1))));
else if (TREE_CODE (arg0) == COND_EXPR)
{
tree arg01 = TREE_OPERAND (arg0, 1);
tree arg02 = TREE_OPERAND (arg0, 2);
if (! VOID_TYPE_P (TREE_TYPE (arg01)))
arg01 = fold (build1 (code, type, arg01));
if (! VOID_TYPE_P (TREE_TYPE (arg02)))
arg02 = fold (build1 (code, type, arg02));
t = fold (build (COND_EXPR, type, TREE_OPERAND (arg0, 0),
arg01, arg02));
if ((code == NOP_EXPR || code == CONVERT_EXPR
|| code == NON_LVALUE_EXPR)
&& TREE_CODE (t) == COND_EXPR
&& TREE_CODE (TREE_OPERAND (t, 1)) == code
&& TREE_CODE (TREE_OPERAND (t, 2)) == code
&& ! VOID_TYPE_P (TREE_OPERAND (t, 1))
&& ! VOID_TYPE_P (TREE_OPERAND (t, 2))
&& (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 1), 0))
== TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 2), 0)))
&& ! (INTEGRAL_TYPE_P (TREE_TYPE (t))
&& (INTEGRAL_TYPE_P
(TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 1), 0))))
&& TYPE_PRECISION (TREE_TYPE (t)) <= BITS_PER_WORD))
t = build1 (code, type,
build (COND_EXPR,
TREE_TYPE (TREE_OPERAND
(TREE_OPERAND (t, 1), 0)),
TREE_OPERAND (t, 0),
TREE_OPERAND (TREE_OPERAND (t, 1), 0),
TREE_OPERAND (TREE_OPERAND (t, 2), 0)));
return t;
}
else if (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<')
return fold (build (COND_EXPR, type, arg0,
fold (build1 (code, type, integer_one_node)),
fold (build1 (code, type, integer_zero_node))));
}
else if (TREE_CODE_CLASS (code) == '2'
|| TREE_CODE_CLASS (code) == '<')
{
if (TREE_CODE (arg1) == COMPOUND_EXPR
&& ! TREE_SIDE_EFFECTS (TREE_OPERAND (arg1, 0))
&& ! TREE_SIDE_EFFECTS (arg0))
return build (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0),
fold (build (code, type,
arg0, TREE_OPERAND (arg1, 1))));
else if ((TREE_CODE (arg1) == COND_EXPR
|| (TREE_CODE_CLASS (TREE_CODE (arg1)) == '<'
&& TREE_CODE_CLASS (code) != '<'))
&& (TREE_CODE (arg0) != COND_EXPR
|| count_cond (arg0, 25) + count_cond (arg1, 25) <= 25)
&& (! TREE_SIDE_EFFECTS (arg0)
|| ((*lang_hooks.decls.global_bindings_p) () == 0
&& ! contains_placeholder_p (arg0))))
return
fold_binary_op_with_conditional_arg (code, type, arg1, arg0,
0);
else if (TREE_CODE (arg0) == COMPOUND_EXPR)
return build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
fold (build (code, type, TREE_OPERAND (arg0, 1), arg1)));
else if ((TREE_CODE (arg0) == COND_EXPR
|| (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
&& TREE_CODE_CLASS (code) != '<'))
&& (TREE_CODE (arg1) != COND_EXPR
|| count_cond (arg0, 25) + count_cond (arg1, 25) <= 25)
&& (! TREE_SIDE_EFFECTS (arg1)
|| ((*lang_hooks.decls.global_bindings_p) () == 0
&& ! contains_placeholder_p (arg1))))
return
fold_binary_op_with_conditional_arg (code, type, arg0, arg1,
1);
}
else if (TREE_CODE_CLASS (code) == '<'
&& TREE_CODE (arg0) == COMPOUND_EXPR)
return build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
fold (build (code, type, TREE_OPERAND (arg0, 1), arg1)));
else if (TREE_CODE_CLASS (code) == '<'
&& TREE_CODE (arg1) == COMPOUND_EXPR)
return build (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0),
fold (build (code, type, arg0, TREE_OPERAND (arg1, 1))));
switch (code)
{
case INTEGER_CST:
case REAL_CST:
case VECTOR_CST:
case STRING_CST:
case COMPLEX_CST:
case CONSTRUCTOR:
return t;
case CONST_DECL:
return fold (DECL_INITIAL (t));
case NOP_EXPR:
case FLOAT_EXPR:
case CONVERT_EXPR:
case FIX_TRUNC_EXPR:
if (TREE_TYPE (TREE_OPERAND (t, 0)) == TREE_TYPE (t))
return TREE_OPERAND (t, 0);
if (TREE_CODE (TREE_OPERAND (t, 0)) == NOP_EXPR
|| TREE_CODE (TREE_OPERAND (t, 0)) == CONVERT_EXPR)
{
tree inside_type = TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 0), 0));
tree inter_type = TREE_TYPE (TREE_OPERAND (t, 0));
tree final_type = TREE_TYPE (t);
int inside_int = INTEGRAL_TYPE_P (inside_type);
int inside_ptr = POINTER_TYPE_P (inside_type);
int inside_float = FLOAT_TYPE_P (inside_type);
unsigned int inside_prec = TYPE_PRECISION (inside_type);
int inside_unsignedp = TREE_UNSIGNED (inside_type);
int inter_int = INTEGRAL_TYPE_P (inter_type);
int inter_ptr = POINTER_TYPE_P (inter_type);
int inter_float = FLOAT_TYPE_P (inter_type);
unsigned int inter_prec = TYPE_PRECISION (inter_type);
int inter_unsignedp = TREE_UNSIGNED (inter_type);
int final_int = INTEGRAL_TYPE_P (final_type);
int final_ptr = POINTER_TYPE_P (final_type);
int final_float = FLOAT_TYPE_P (final_type);
unsigned int final_prec = TYPE_PRECISION (final_type);
int final_unsignedp = TREE_UNSIGNED (final_type);
if (TYPE_MAIN_VARIANT (inside_type) == TYPE_MAIN_VARIANT (final_type)
&& ((inter_int && final_int) || (inter_float && final_float))
&& inter_prec >= final_prec)
return convert (final_type, TREE_OPERAND (TREE_OPERAND (t, 0), 0));
if ((((inter_int || inter_ptr) && (inside_int || inside_ptr))
|| (inter_float && inside_float))
&& inter_prec >= inside_prec
&& (inter_float || inter_unsignedp == inside_unsignedp)
&& ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE (final_type))
&& TYPE_MODE (final_type) == TYPE_MODE (inter_type))
&& ! final_ptr)
return convert (final_type, TREE_OPERAND (TREE_OPERAND (t, 0), 0));
if (inside_int && inter_int && final_int
&& inside_prec < inter_prec && inter_prec < final_prec
&& inside_unsignedp && !inter_unsignedp)
return convert (final_type, TREE_OPERAND (TREE_OPERAND (t, 0), 0));
if (! inside_float && ! inter_float && ! final_float
&& (inter_prec > inside_prec || inter_prec > final_prec)
&& ! (inside_int && inter_int
&& inter_unsignedp != inside_unsignedp
&& inter_prec < final_prec)
&& ((inter_unsignedp && inter_prec > inside_prec)
== (final_unsignedp && final_prec > inter_prec))
&& ! (inside_ptr && inter_prec != final_prec)
&& ! (final_ptr && inside_prec != inter_prec)
&& ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE (final_type))
&& TYPE_MODE (final_type) == TYPE_MODE (inter_type))
&& ! final_ptr)
return convert (final_type, TREE_OPERAND (TREE_OPERAND (t, 0), 0));
}
if (TREE_CODE (TREE_OPERAND (t, 0)) == MODIFY_EXPR
&& TREE_CONSTANT (TREE_OPERAND (TREE_OPERAND (t, 0), 1))
&& !(TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)) == COMPONENT_REF
&& DECL_BIT_FIELD (TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (t, 0), 0), 1))))
{
tree prev = TREE_OPERAND (t, 0);
TREE_OPERAND (t, 0) = TREE_OPERAND (prev, 1);
t = build (COMPOUND_EXPR, TREE_TYPE (t), prev, fold (t));
TREE_USED (t) = 1;
return t;
}
if (INTEGRAL_TYPE_P (TREE_TYPE (t))
&& TREE_CODE (TREE_TYPE (t)) != BOOLEAN_TYPE
&& TREE_CODE (TREE_OPERAND (t, 0)) == BIT_AND_EXPR
&& TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 1)) == INTEGER_CST)
{
tree and = TREE_OPERAND (t, 0);
tree and0 = TREE_OPERAND (and, 0), and1 = TREE_OPERAND (and, 1);
int change = 0;
if (TREE_UNSIGNED (TREE_TYPE (and))
|| (TYPE_PRECISION (TREE_TYPE (t))
<= TYPE_PRECISION (TREE_TYPE (and))))
change = 1;
else if (TYPE_PRECISION (TREE_TYPE (and1))
<= HOST_BITS_PER_WIDE_INT
&& host_integerp (and1, 1))
{
unsigned HOST_WIDE_INT cst;
cst = tree_low_cst (and1, 1);
cst &= (HOST_WIDE_INT) -1
<< (TYPE_PRECISION (TREE_TYPE (and1)) - 1);
change = (cst == 0);
#ifdef LOAD_EXTEND_OP
if (change
&& (LOAD_EXTEND_OP (TYPE_MODE (TREE_TYPE (and0)))
== ZERO_EXTEND))
{
tree uns = (*lang_hooks.types.unsigned_type) (TREE_TYPE (and0));
and0 = convert (uns, and0);
and1 = convert (uns, and1);
}
#endif
}
if (change)
return fold (build (BIT_AND_EXPR, TREE_TYPE (t),
convert (TREE_TYPE (t), and0),
convert (TREE_TYPE (t), and1)));
}
if (!wins)
{
TREE_CONSTANT (t) = TREE_CONSTANT (arg0);
return t;
}
return fold_convert (t, arg0);
case VIEW_CONVERT_EXPR:
if (TREE_CODE (TREE_OPERAND (t, 0)) == VIEW_CONVERT_EXPR)
return build1 (VIEW_CONVERT_EXPR, type,
TREE_OPERAND (TREE_OPERAND (t, 0), 0));
return t;
case COMPONENT_REF:
if (TREE_CODE (arg0) == CONSTRUCTOR)
{
tree m = purpose_member (arg1, CONSTRUCTOR_ELTS (arg0));
if (m)
t = TREE_VALUE (m);
}
return t;
case RANGE_EXPR:
TREE_CONSTANT (t) = wins;
return t;
case NEGATE_EXPR:
if (wins)
{
if (TREE_CODE (arg0) == INTEGER_CST)
{
unsigned HOST_WIDE_INT low;
HOST_WIDE_INT high;
int overflow = neg_double (TREE_INT_CST_LOW (arg0),
TREE_INT_CST_HIGH (arg0),
&low, &high);
t = build_int_2 (low, high);
TREE_TYPE (t) = type;
TREE_OVERFLOW (t)
= (TREE_OVERFLOW (arg0)
| force_fit_type (t, overflow && !TREE_UNSIGNED (type)));
TREE_CONSTANT_OVERFLOW (t)
= TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg0);
}
else if (TREE_CODE (arg0) == REAL_CST)
t = build_real (type, REAL_VALUE_NEGATE (TREE_REAL_CST (arg0)));
}
else if (TREE_CODE (arg0) == NEGATE_EXPR)
return TREE_OPERAND (arg0, 0);
else if (TREE_CODE (arg0) == MINUS_EXPR
&& (! FLOAT_TYPE_P (type) || flag_unsafe_math_optimizations))
return build (MINUS_EXPR, type, TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg0, 0));
return t;
case ABS_EXPR:
if (wins)
{
if (TREE_CODE (arg0) == INTEGER_CST)
{
if (TREE_UNSIGNED (type))
return arg0;
else if (INT_CST_LT (integer_minus_one_node, arg0))
return arg0;
else
{
unsigned HOST_WIDE_INT low;
HOST_WIDE_INT high;
int overflow = neg_double (TREE_INT_CST_LOW (arg0),
TREE_INT_CST_HIGH (arg0),
&low, &high);
t = build_int_2 (low, high);
TREE_TYPE (t) = type;
TREE_OVERFLOW (t)
= (TREE_OVERFLOW (arg0)
| force_fit_type (t, overflow));
TREE_CONSTANT_OVERFLOW (t)
= TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg0);
}
}
else if (TREE_CODE (arg0) == REAL_CST)
{
if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg0)))
t = build_real (type,
REAL_VALUE_NEGATE (TREE_REAL_CST (arg0)));
}
}
else if (TREE_CODE (arg0) == ABS_EXPR || TREE_CODE (arg0) == NEGATE_EXPR)
return build1 (ABS_EXPR, type, TREE_OPERAND (arg0, 0));
return t;
case CONJ_EXPR:
if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
return convert (type, arg0);
else if (TREE_CODE (arg0) == COMPLEX_EXPR)
return build (COMPLEX_EXPR, type,
TREE_OPERAND (arg0, 0),
negate_expr (TREE_OPERAND (arg0, 1)));
else if (TREE_CODE (arg0) == COMPLEX_CST)
return build_complex (type, TREE_REALPART (arg0),
negate_expr (TREE_IMAGPART (arg0)));
else if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
return fold (build (TREE_CODE (arg0), type,
fold (build1 (CONJ_EXPR, type,
TREE_OPERAND (arg0, 0))),
fold (build1 (CONJ_EXPR,
type, TREE_OPERAND (arg0, 1)))));
else if (TREE_CODE (arg0) == CONJ_EXPR)
return TREE_OPERAND (arg0, 0);
return t;
case BIT_NOT_EXPR:
if (wins)
{
t = build_int_2 (~ TREE_INT_CST_LOW (arg0),
~ TREE_INT_CST_HIGH (arg0));
TREE_TYPE (t) = type;
force_fit_type (t, 0);
TREE_OVERFLOW (t) = TREE_OVERFLOW (arg0);
TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (arg0);
}
else if (TREE_CODE (arg0) == BIT_NOT_EXPR)
return TREE_OPERAND (arg0, 0);
return t;
case PLUS_EXPR:
if (TREE_CODE (arg1) == NEGATE_EXPR)
return fold (build (MINUS_EXPR, type, arg0, TREE_OPERAND (arg1, 0)));
if (TREE_CODE (arg0) == NEGATE_EXPR)
return fold (build (MINUS_EXPR, type, arg1, TREE_OPERAND (arg0, 0)));
else if (! FLOAT_TYPE_P (type))
{
if (integer_zerop (arg1))
return non_lvalue (convert (type, arg0));
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (arg1) == BIT_AND_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
&& integer_zerop (const_binop (BIT_AND_EXPR,
TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 1), 0)))
{
code = BIT_IOR_EXPR;
goto bit_ior;
}
if ((TREE_CODE (arg0) == PLUS_EXPR
&& TREE_CODE (arg1) == MULT_EXPR)
|| (TREE_CODE (arg1) == PLUS_EXPR
&& TREE_CODE (arg0) == MULT_EXPR))
{
tree parg0, parg1, parg, marg;
if (TREE_CODE (arg0) == PLUS_EXPR)
parg = arg0, marg = arg1;
else
parg = arg1, marg = arg0;
parg0 = TREE_OPERAND (parg, 0);
parg1 = TREE_OPERAND (parg, 1);
STRIP_NOPS (parg0);
STRIP_NOPS (parg1);
if (TREE_CODE (parg0) == MULT_EXPR
&& TREE_CODE (parg1) != MULT_EXPR)
return fold (build (PLUS_EXPR, type,
fold (build (PLUS_EXPR, type, parg0, marg)),
parg1));
if (TREE_CODE (parg0) != MULT_EXPR
&& TREE_CODE (parg1) == MULT_EXPR)
return fold (build (PLUS_EXPR, type,
fold (build (PLUS_EXPR, type, parg1, marg)),
parg0));
}
if (TREE_CODE (arg0) == MULT_EXPR && TREE_CODE (arg1) == MULT_EXPR)
{
tree arg00, arg01, arg10, arg11;
tree alt0 = NULL_TREE, alt1 = NULL_TREE, same;
arg00 = TREE_OPERAND (arg0, 0);
arg01 = TREE_OPERAND (arg0, 1);
arg10 = TREE_OPERAND (arg1, 0);
arg11 = TREE_OPERAND (arg1, 1);
same = NULL_TREE;
if (operand_equal_p (arg01, arg11, 0))
same = arg01, alt0 = arg00, alt1 = arg10;
else if (operand_equal_p (arg00, arg10, 0))
same = arg00, alt0 = arg01, alt1 = arg11;
else if (operand_equal_p (arg00, arg11, 0))
same = arg00, alt0 = arg01, alt1 = arg10;
else if (operand_equal_p (arg01, arg10, 0))
same = arg01, alt0 = arg00, alt1 = arg11;
else if (TREE_CODE (arg01) == INTEGER_CST
&& TREE_CODE (arg11) == INTEGER_CST
&& TREE_INT_CST_HIGH (arg01) == 0
&& TREE_INT_CST_HIGH (arg11) == 0)
{
HOST_WIDE_INT int01, int11, tmp;
int01 = TREE_INT_CST_LOW (arg01);
int11 = TREE_INT_CST_LOW (arg11);
if ((int01 >= 0 ? int01 : -int01)
< (int11 >= 0 ? int11 : -int11))
{
tmp = int01, int01 = int11, int11 = tmp;
alt0 = arg00, arg00 = arg10, arg10 = alt0;
alt0 = arg01, arg01 = arg11, arg11 = alt0;
}
if (exact_log2 (int11) > 0 && int01 % int11 == 0)
{
alt0 = fold (build (MULT_EXPR, type, arg00,
build_int_2 (int01 / int11, 0)));
alt1 = arg10;
same = arg11;
}
}
if (same)
return fold (build (MULT_EXPR, type,
fold (build (PLUS_EXPR, type, alt0, alt1)),
same));
}
}
else if (fold_real_zero_addition_p (TREE_TYPE (arg0), arg1, 0))
return non_lvalue (convert (type, arg0));
else if (fold_real_zero_addition_p (TREE_TYPE (arg1), arg0, 0))
return non_lvalue (convert (type, arg1));
bit_rotate:
{
enum tree_code code0, code1;
code0 = TREE_CODE (arg0);
code1 = TREE_CODE (arg1);
if (((code0 == RSHIFT_EXPR && code1 == LSHIFT_EXPR)
|| (code1 == RSHIFT_EXPR && code0 == LSHIFT_EXPR))
&& operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0), 0)
&& TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0))))
{
tree tree01, tree11;
enum tree_code code01, code11;
tree01 = TREE_OPERAND (arg0, 1);
tree11 = TREE_OPERAND (arg1, 1);
STRIP_NOPS (tree01);
STRIP_NOPS (tree11);
code01 = TREE_CODE (tree01);
code11 = TREE_CODE (tree11);
if (code01 == INTEGER_CST
&& code11 == INTEGER_CST
&& TREE_INT_CST_HIGH (tree01) == 0
&& TREE_INT_CST_HIGH (tree11) == 0
&& ((TREE_INT_CST_LOW (tree01) + TREE_INT_CST_LOW (tree11))
== TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)))))
return build (LROTATE_EXPR, type, TREE_OPERAND (arg0, 0),
code0 == LSHIFT_EXPR ? tree01 : tree11);
else if (code11 == MINUS_EXPR)
{
tree tree110, tree111;
tree110 = TREE_OPERAND (tree11, 0);
tree111 = TREE_OPERAND (tree11, 1);
STRIP_NOPS (tree110);
STRIP_NOPS (tree111);
if (TREE_CODE (tree110) == INTEGER_CST
&& 0 == compare_tree_int (tree110,
TYPE_PRECISION
(TREE_TYPE (TREE_OPERAND
(arg0, 0))))
&& operand_equal_p (tree01, tree111, 0))
return build ((code0 == LSHIFT_EXPR
? LROTATE_EXPR
: RROTATE_EXPR),
type, TREE_OPERAND (arg0, 0), tree01);
}
else if (code01 == MINUS_EXPR)
{
tree tree010, tree011;
tree010 = TREE_OPERAND (tree01, 0);
tree011 = TREE_OPERAND (tree01, 1);
STRIP_NOPS (tree010);
STRIP_NOPS (tree011);
if (TREE_CODE (tree010) == INTEGER_CST
&& 0 == compare_tree_int (tree010,
TYPE_PRECISION
(TREE_TYPE (TREE_OPERAND
(arg0, 0))))
&& operand_equal_p (tree11, tree011, 0))
return build ((code0 != LSHIFT_EXPR
? LROTATE_EXPR
: RROTATE_EXPR),
type, TREE_OPERAND (arg0, 0), tree11);
}
}
}
associate:
if (! wins
&& (! FLOAT_TYPE_P (type)
|| (flag_unsafe_math_optimizations && code == MULT_EXPR)))
{
tree var0, con0, lit0, minus_lit0;
tree var1, con1, lit1, minus_lit1;
var0 = split_tree (arg0, code, &con0, &lit0, &minus_lit0, 0);
var1 = split_tree (arg1, code, &con1, &lit1, &minus_lit1,
code == MINUS_EXPR);
if (2 < ((var0 != 0) + (var1 != 0)
+ (con0 != 0) + (con1 != 0)
+ (lit0 != 0) + (lit1 != 0)
+ (minus_lit0 != 0) + (minus_lit1 != 0)))
{
if (code == MINUS_EXPR)
code = PLUS_EXPR;
var0 = associate_trees (var0, var1, code, type);
con0 = associate_trees (con0, con1, code, type);
lit0 = associate_trees (lit0, lit1, code, type);
minus_lit0 = associate_trees (minus_lit0, minus_lit1, code, type);
if (minus_lit0 && lit0)
{
if (tree_int_cst_lt (lit0, minus_lit0))
{
minus_lit0 = associate_trees (minus_lit0, lit0,
MINUS_EXPR, type);
lit0 = 0;
}
else
{
lit0 = associate_trees (lit0, minus_lit0,
MINUS_EXPR, type);
minus_lit0 = 0;
}
}
if (minus_lit0)
{
if (con0 == 0)
return convert (type, associate_trees (var0, minus_lit0,
MINUS_EXPR, type));
else
{
con0 = associate_trees (con0, minus_lit0,
MINUS_EXPR, type);
return convert (type, associate_trees (var0, con0,
PLUS_EXPR, type));
}
}
con0 = associate_trees (con0, lit0, code, type);
return convert (type, associate_trees (var0, con0, code, type));
}
}
binary:
if (wins)
t1 = const_binop (code, arg0, arg1, 0);
if (t1 != NULL_TREE)
{
if (TREE_TYPE (t1) != TREE_TYPE (t))
t1 = convert (TREE_TYPE (t), t1);
return t1;
}
return t;
case MINUS_EXPR:
if (TREE_CODE (arg1) == NEGATE_EXPR)
return fold (build (PLUS_EXPR, type, arg0, TREE_OPERAND (arg1, 0)));
if (TREE_CODE (arg0) == NEGATE_EXPR && TREE_CODE (arg1) == REAL_CST)
return
fold (build (MINUS_EXPR, type,
build_real (TREE_TYPE (arg1),
REAL_VALUE_NEGATE (TREE_REAL_CST (arg1))),
TREE_OPERAND (arg0, 0)));
if (! FLOAT_TYPE_P (type))
{
if (! wins && integer_zerop (arg0))
return negate_expr (convert (type, arg1));
if (integer_zerop (arg1))
return non_lvalue (convert (type, arg0));
if (TREE_CODE (arg0) == MULT_EXPR && TREE_CODE (arg1) == MULT_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 1), 0))
return fold (build (MULT_EXPR, type,
fold (build (MINUS_EXPR, type,
TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0))),
TREE_OPERAND (arg0, 1)));
}
else if (fold_real_zero_addition_p (TREE_TYPE (arg0), arg1, 1))
return non_lvalue (convert (type, arg0));
else if (!wins && fold_real_zero_addition_p (TREE_TYPE (arg1), arg0, 0))
return negate_expr (convert (type, arg1));
if ((! FLOAT_TYPE_P (type) || flag_unsafe_math_optimizations)
&& operand_equal_p (arg0, arg1, 0))
return convert (type, integer_zero_node);
goto associate;
case MULT_EXPR:
if (TREE_CODE (arg0) == NEGATE_EXPR && TREE_CODE (arg1) == NEGATE_EXPR)
return fold (build (MULT_EXPR, type, TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0)));
if (! FLOAT_TYPE_P (type))
{
if (integer_zerop (arg1))
return omit_one_operand (type, arg1, arg0);
if (integer_onep (arg1))
return non_lvalue (convert (type, arg0));
if (TREE_CODE (arg1) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (arg1, 0)))
return fold (build (LSHIFT_EXPR, type, arg0,
TREE_OPERAND (arg1, 1)));
if (TREE_CODE (arg0) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (arg0, 0)))
return fold (build (LSHIFT_EXPR, type, arg1,
TREE_OPERAND (arg0, 1)));
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (TREE_OPERAND (t, 0), arg1,
code, NULL_TREE)))
return convert (type, tem);
}
else
{
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_zerop (arg1))
return omit_one_operand (type, arg1, arg0);
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_onep (arg1))
return non_lvalue (convert (type, arg0));
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_minus_onep (arg1))
return fold (build1 (NEGATE_EXPR, type, arg0));
if (! wins && real_twop (arg1)
&& (*lang_hooks.decls.global_bindings_p) () == 0
&& ! contains_placeholder_p (arg0))
{
tree arg = save_expr (arg0);
return build (PLUS_EXPR, type, arg, arg);
}
}
goto associate;
case BIT_IOR_EXPR:
bit_ior:
if (integer_all_onesp (arg1))
return omit_one_operand (type, arg1, arg0);
if (integer_zerop (arg1))
return non_lvalue (convert (type, arg0));
t1 = distribute_bit_expr (code, type, arg0, arg1);
if (t1 != NULL_TREE)
return t1;
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& TREE_CODE (arg1) == BIT_NOT_EXPR)
{
return fold (build1 (BIT_NOT_EXPR, type,
build (BIT_AND_EXPR, type,
TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0))));
}
goto bit_rotate;
case BIT_XOR_EXPR:
if (integer_zerop (arg1))
return non_lvalue (convert (type, arg0));
if (integer_all_onesp (arg1))
return fold (build1 (BIT_NOT_EXPR, type, arg0));
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (arg1) == BIT_AND_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
&& integer_zerop (const_binop (BIT_AND_EXPR,
TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 1), 0)))
{
code = BIT_IOR_EXPR;
goto bit_ior;
}
goto bit_rotate;
case BIT_AND_EXPR:
bit_and:
if (integer_all_onesp (arg1))
return non_lvalue (convert (type, arg0));
if (integer_zerop (arg1))
return omit_one_operand (type, arg1, arg0);
t1 = distribute_bit_expr (code, type, arg0, arg1);
if (t1 != NULL_TREE)
return t1;
if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg0) == NOP_EXPR
&& TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0))))
{
unsigned int prec
= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)));
if (prec < BITS_PER_WORD && prec < HOST_BITS_PER_WIDE_INT
&& (~TREE_INT_CST_LOW (arg1)
& (((HOST_WIDE_INT) 1 << prec) - 1)) == 0)
return build1 (NOP_EXPR, type, TREE_OPERAND (arg0, 0));
}
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& TREE_CODE (arg1) == BIT_NOT_EXPR)
{
return fold (build1 (BIT_NOT_EXPR, type,
build (BIT_IOR_EXPR, type,
TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0))));
}
goto associate;
case BIT_ANDTC_EXPR:
if (integer_all_onesp (arg0))
return non_lvalue (convert (type, arg1));
if (integer_zerop (arg0))
return omit_one_operand (type, arg0, arg1);
if (TREE_CODE (arg1) == INTEGER_CST)
{
arg1 = fold (build1 (BIT_NOT_EXPR, type, arg1));
code = BIT_AND_EXPR;
goto bit_and;
}
goto binary;
case RDIV_EXPR:
if (TREE_CODE (arg1) == REAL_CST
&& !MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg1)))
&& real_zerop (arg1))
return t;
if (TREE_CODE (arg0) == NEGATE_EXPR && TREE_CODE (arg1) == NEGATE_EXPR)
return fold (build (RDIV_EXPR, type, TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0)));
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_onep (arg1))
return non_lvalue (convert (type, arg0));
if (TREE_CODE (arg1) == REAL_CST)
{
if (flag_unsafe_math_optimizations
&& 0 != (tem = const_binop (code, build_real (type, dconst1),
arg1, 0)))
return fold (build (MULT_EXPR, type, arg0, tem));
else if (optimize)
{
REAL_VALUE_TYPE r;
r = TREE_REAL_CST (arg1);
if (exact_real_inverse (TYPE_MODE(TREE_TYPE(arg0)), &r))
{
tem = build_real (type, r);
return fold (build (MULT_EXPR, type, arg0, tem));
}
}
}
if (flag_unsafe_math_optimizations
&& TREE_CODE (arg0) == RDIV_EXPR)
{
return fold (build (RDIV_EXPR, type, TREE_OPERAND (arg0, 0),
build (MULT_EXPR, type, TREE_OPERAND (arg0, 1),
arg1)));
}
if (flag_unsafe_math_optimizations
&& TREE_CODE (arg1) == RDIV_EXPR)
{
return fold (build (MULT_EXPR, type,
build (RDIV_EXPR, type, arg0,
TREE_OPERAND (arg1, 0)),
TREE_OPERAND (arg1, 1)));
}
goto binary;
case TRUNC_DIV_EXPR:
case ROUND_DIV_EXPR:
case FLOOR_DIV_EXPR:
case CEIL_DIV_EXPR:
case EXACT_DIV_EXPR:
if (integer_onep (arg1))
return non_lvalue (convert (type, arg0));
if (integer_zerop (arg1))
return t;
if ((code == CEIL_DIV_EXPR || code == FLOOR_DIV_EXPR)
&& multiple_of_p (type, arg0, arg1))
return fold (build (EXACT_DIV_EXPR, type, arg0, arg1));
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (TREE_OPERAND (t, 0), arg1,
code, NULL_TREE)))
return convert (type, tem);
goto binary;
case CEIL_MOD_EXPR:
case FLOOR_MOD_EXPR:
case ROUND_MOD_EXPR:
case TRUNC_MOD_EXPR:
if (integer_onep (arg1))
return omit_one_operand (type, integer_zero_node, arg0);
if (integer_zerop (arg1))
return t;
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (TREE_OPERAND (t, 0), arg1,
code, NULL_TREE)))
return convert (type, tem);
goto binary;
case LSHIFT_EXPR:
case RSHIFT_EXPR:
case LROTATE_EXPR:
case RROTATE_EXPR:
if (integer_zerop (arg1))
return non_lvalue (convert (type, arg0));
if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_sgn (arg1) < 0)
return t;
if (code == LROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST)
{
TREE_SET_CODE (t, RROTATE_EXPR);
code = RROTATE_EXPR;
TREE_OPERAND (t, 1) = arg1
= const_binop
(MINUS_EXPR,
convert (TREE_TYPE (arg1),
build_int_2 (GET_MODE_BITSIZE (TYPE_MODE (type)), 0)),
arg1, 0);
if (tree_int_cst_sgn (arg1) < 0)
return t;
}
if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST
&& (TREE_CODE (arg0) == BIT_AND_EXPR
|| TREE_CODE (arg0) == BIT_ANDTC_EXPR
|| TREE_CODE (arg0) == BIT_IOR_EXPR
|| TREE_CODE (arg0) == BIT_XOR_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
return fold (build (TREE_CODE (arg0), type,
fold (build (code, type,
TREE_OPERAND (arg0, 0), arg1)),
fold (build (code, type,
TREE_OPERAND (arg0, 1), arg1))));
if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (arg0) == RROTATE_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& TREE_INT_CST_HIGH (arg1) == 0
&& TREE_INT_CST_HIGH (TREE_OPERAND (arg0, 1)) == 0
&& ((TREE_INT_CST_LOW (arg1)
+ TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)))
== (unsigned int) GET_MODE_BITSIZE (TYPE_MODE (type))))
return TREE_OPERAND (arg0, 0);
goto binary;
case MIN_EXPR:
if (operand_equal_p (arg0, arg1, 0))
return omit_one_operand (type, arg0, arg1);
if (INTEGRAL_TYPE_P (type)
&& operand_equal_p (arg1, TYPE_MIN_VALUE (type), 1))
return omit_one_operand (type, arg1, arg0);
goto associate;
case MAX_EXPR:
if (operand_equal_p (arg0, arg1, 0))
return omit_one_operand (type, arg0, arg1);
if (INTEGRAL_TYPE_P (type)
&& TYPE_MAX_VALUE (type)
&& operand_equal_p (arg1, TYPE_MAX_VALUE (type), 1))
return omit_one_operand (type, arg1, arg0);
goto associate;
case TRUTH_NOT_EXPR:
tem = invert_truthvalue (arg0);
if (TREE_CODE (tem) == TRUTH_NOT_EXPR)
return t;
return convert (type, tem);
case TRUTH_ANDIF_EXPR:
if (integer_zerop (arg0))
return convert (type, arg0);
case TRUTH_AND_EXPR:
if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
return non_lvalue (convert (type, arg1));
if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1)
&& (code != TRUTH_ANDIF_EXPR || ! TREE_SIDE_EFFECTS (arg0)))
return non_lvalue (convert (type, arg0));
if (integer_zerop (arg1))
return omit_one_operand (type, arg1, arg0);
if (integer_zerop (arg0))
return omit_one_operand (type, arg0, arg1);
truth_andor:
if (!optimize)
return t;
if (TREE_CODE (arg0) == TREE_CODE (arg1)
&& (TREE_CODE (arg0) == TRUTH_ANDIF_EXPR
|| TREE_CODE (arg0) == TRUTH_ORIF_EXPR
|| TREE_CODE (arg0) == TRUTH_AND_EXPR
|| TREE_CODE (arg0) == TRUTH_OR_EXPR)
&& ! TREE_SIDE_EFFECTS (TREE_OPERAND (arg0, 1)))
{
tree a00 = TREE_OPERAND (arg0, 0);
tree a01 = TREE_OPERAND (arg0, 1);
tree a10 = TREE_OPERAND (arg1, 0);
tree a11 = TREE_OPERAND (arg1, 1);
int commutative = ((TREE_CODE (arg0) == TRUTH_OR_EXPR
|| TREE_CODE (arg0) == TRUTH_AND_EXPR)
&& (code == TRUTH_AND_EXPR
|| code == TRUTH_OR_EXPR));
if (operand_equal_p (a00, a10, 0))
return fold (build (TREE_CODE (arg0), type, a00,
fold (build (code, type, a01, a11))));
else if (commutative && operand_equal_p (a00, a11, 0))
return fold (build (TREE_CODE (arg0), type, a00,
fold (build (code, type, a01, a10))));
else if (commutative && operand_equal_p (a01, a10, 0))
return fold (build (TREE_CODE (arg0), type, a01,
fold (build (code, type, a00, a11))));
else if ((commutative || ! TREE_SIDE_EFFECTS (a10))
&& operand_equal_p (a01, a11, 0))
return fold (build (TREE_CODE (arg0), type,
fold (build (code, type, a00, a10)),
a01));
}
if (0 != (tem = fold_range_test (t)))
return tem;
if (TREE_CODE (arg0) == code
&& 0 != (tem = fold_truthop (code, type,
TREE_OPERAND (arg0, 1), arg1)))
return fold (build (code, type, TREE_OPERAND (arg0, 0), tem));
if ((tem = fold_truthop (code, type, arg0, arg1)) != 0)
return tem;
return t;
case TRUTH_ORIF_EXPR:
if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
return convert (type, arg0);
case TRUTH_OR_EXPR:
if (TREE_CODE (arg0) == INTEGER_CST && integer_zerop (arg0))
return non_lvalue (convert (type, arg1));
if (TREE_CODE (arg1) == INTEGER_CST && integer_zerop (arg1)
&& (code != TRUTH_ORIF_EXPR || ! TREE_SIDE_EFFECTS (arg0)))
return non_lvalue (convert (type, arg0));
if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1))
return omit_one_operand (type, arg1, arg0);
if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
return omit_one_operand (type, arg0, arg1);
goto truth_andor;
case TRUTH_XOR_EXPR:
if (integer_zerop (arg0))
return non_lvalue (convert (type, arg1));
if (integer_zerop (arg1))
return non_lvalue (convert (type, arg0));
if (integer_onep (arg0))
return non_lvalue (convert (type, invert_truthvalue (arg1)));
if (integer_onep (arg1))
return non_lvalue (convert (type, invert_truthvalue (arg0)));
return t;
case EQ_EXPR:
case NE_EXPR:
case LT_EXPR:
case GT_EXPR:
case LE_EXPR:
case GE_EXPR:
if ((TREE_CODE (arg0) == INTEGER_CST
&& TREE_CODE (arg1) != INTEGER_CST)
|| (TREE_CODE (arg0) == REAL_CST
&& TREE_CODE (arg0) != REAL_CST))
{
TREE_OPERAND (t, 0) = arg1;
TREE_OPERAND (t, 1) = arg0;
arg0 = TREE_OPERAND (t, 0);
arg1 = TREE_OPERAND (t, 1);
code = swap_tree_comparison (code);
TREE_SET_CODE (t, code);
}
if (integer_zerop (arg1) && INTEGRAL_TYPE_P (TREE_TYPE (arg0))
&& TREE_UNSIGNED (TREE_TYPE (arg0)))
{
if (code == GT_EXPR)
{
code = NE_EXPR;
TREE_SET_CODE (t, code);
}
else if (code==LE_EXPR)
{
code = EQ_EXPR;
TREE_SET_CODE (t, code);
}
}
if (FLOAT_TYPE_P (TREE_TYPE (arg0)))
{
if (TREE_CODE (arg0) == NEGATE_EXPR
&& TREE_CODE (arg1) == NEGATE_EXPR)
return fold (build (code, type, TREE_OPERAND (arg1, 0),
TREE_OPERAND (arg0, 0)));
if (TREE_CODE (arg0) == NEGATE_EXPR && TREE_CODE (arg1) == REAL_CST)
return
fold (build
(swap_tree_comparison (code), type,
TREE_OPERAND (arg0, 0),
build_real (TREE_TYPE (arg1),
REAL_VALUE_NEGATE (TREE_REAL_CST (arg1)))));
if (TREE_CODE (arg1) == REAL_CST
&& REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (arg1)))
return fold (build (code, type, arg0,
build_real (TREE_TYPE (arg1), dconst0)));
if (flag_unsafe_math_optimizations
&& TREE_CODE (arg1) == REAL_CST
&& (TREE_CODE (arg0) == PLUS_EXPR
|| TREE_CODE (arg0) == MINUS_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == REAL_CST
&& 0 != (tem = const_binop (TREE_CODE (arg0) == PLUS_EXPR
? MINUS_EXPR : PLUS_EXPR,
arg1, TREE_OPERAND (arg0, 1), 0))
&& ! TREE_CONSTANT_OVERFLOW (tem))
return fold (build (code, type, TREE_OPERAND (arg0, 0), tem));
}
{
tree constop = 0, varop = NULL_TREE;
int constopnum = -1;
if (TREE_CONSTANT (arg1))
constopnum = 1, constop = arg1, varop = arg0;
if (TREE_CONSTANT (arg0))
constopnum = 0, constop = arg0, varop = arg1;
if (constop && TREE_CODE (varop) == POSTINCREMENT_EXPR)
{
if (POINTER_TYPE_P (TREE_TYPE (varop))
|| (! FLOAT_TYPE_P (TREE_TYPE (varop))
&& (code == EQ_EXPR || code == NE_EXPR)))
{
tree newconst
= fold (build (PLUS_EXPR, TREE_TYPE (varop),
constop, TREE_OPERAND (varop, 1)));
varop = build (PREINCREMENT_EXPR, TREE_TYPE (varop),
TREE_OPERAND (varop, 0),
TREE_OPERAND (varop, 1));
if (TREE_CODE (TREE_OPERAND (varop, 0)) == COMPONENT_REF
&& DECL_BIT_FIELD(TREE_OPERAND
(TREE_OPERAND (varop, 0), 1)))
{
int size
= TREE_INT_CST_LOW (DECL_SIZE
(TREE_OPERAND
(TREE_OPERAND (varop, 0), 1)));
tree mask, unsigned_type;
unsigned int precision;
tree folded_compare;
if (constopnum == 0)
folded_compare = fold (build (code, type, constop,
TREE_OPERAND (varop, 0)));
else
folded_compare = fold (build (code, type,
TREE_OPERAND (varop, 0),
constop));
if (integer_zerop (folded_compare)
|| integer_onep (folded_compare))
return omit_one_operand (type, folded_compare, varop);
unsigned_type = (*lang_hooks.types.type_for_size)(size, 1);
precision = TYPE_PRECISION (unsigned_type);
mask = build_int_2 (~0, ~0);
TREE_TYPE (mask) = unsigned_type;
force_fit_type (mask, 0);
mask = const_binop (RSHIFT_EXPR, mask,
size_int (precision - size), 0);
newconst = fold (build (BIT_AND_EXPR,
TREE_TYPE (varop), newconst,
convert (TREE_TYPE (varop),
mask)));
}
t = build (code, type,
(constopnum == 0) ? newconst : varop,
(constopnum == 1) ? newconst : varop);
return t;
}
}
else if (constop && TREE_CODE (varop) == POSTDECREMENT_EXPR)
{
if (POINTER_TYPE_P (TREE_TYPE (varop))
|| (! FLOAT_TYPE_P (TREE_TYPE (varop))
&& (code == EQ_EXPR || code == NE_EXPR)))
{
tree newconst
= fold (build (MINUS_EXPR, TREE_TYPE (varop),
constop, TREE_OPERAND (varop, 1)));
varop = build (PREDECREMENT_EXPR, TREE_TYPE (varop),
TREE_OPERAND (varop, 0),
TREE_OPERAND (varop, 1));
if (TREE_CODE (TREE_OPERAND (varop, 0)) == COMPONENT_REF
&& DECL_BIT_FIELD(TREE_OPERAND
(TREE_OPERAND (varop, 0), 1)))
{
int size
= TREE_INT_CST_LOW (DECL_SIZE
(TREE_OPERAND
(TREE_OPERAND (varop, 0), 1)));
tree mask, unsigned_type;
unsigned int precision;
tree folded_compare;
if (constopnum == 0)
folded_compare = fold (build (code, type, constop,
TREE_OPERAND (varop, 0)));
else
folded_compare = fold (build (code, type,
TREE_OPERAND (varop, 0),
constop));
if (integer_zerop (folded_compare)
|| integer_onep (folded_compare))
return omit_one_operand (type, folded_compare, varop);
unsigned_type = (*lang_hooks.types.type_for_size)(size, 1);
precision = TYPE_PRECISION (unsigned_type);
mask = build_int_2 (~0, ~0);
TREE_TYPE (mask) = TREE_TYPE (varop);
force_fit_type (mask, 0);
mask = const_binop (RSHIFT_EXPR, mask,
size_int (precision - size), 0);
newconst = fold (build (BIT_AND_EXPR,
TREE_TYPE (varop), newconst,
convert (TREE_TYPE (varop),
mask)));
}
t = build (code, type,
(constopnum == 0) ? newconst : varop,
(constopnum == 1) ? newconst : varop);
return t;
}
}
}
if (TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (arg0) != INTEGER_CST
&& tree_int_cst_sgn (arg1) > 0)
{
switch (code)
{
case GE_EXPR:
code = GT_EXPR;
arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0);
t = build (code, type, TREE_OPERAND (t, 0), arg1);
break;
case LT_EXPR:
code = LE_EXPR;
arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0);
t = build (code, type, TREE_OPERAND (t, 0), arg1);
break;
default:
break;
}
}
{
int width = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (arg1)));
if (TREE_CODE (arg1) == INTEGER_CST
&& ! TREE_CONSTANT_OVERFLOW (arg1)
&& width <= HOST_BITS_PER_WIDE_INT
&& (INTEGRAL_TYPE_P (TREE_TYPE (arg1))
|| POINTER_TYPE_P (TREE_TYPE (arg1))))
{
unsigned HOST_WIDE_INT signed_max;
unsigned HOST_WIDE_INT max, min;
signed_max = ((unsigned HOST_WIDE_INT) 1 << (width - 1)) - 1;
if (TREE_UNSIGNED (TREE_TYPE (arg1)))
{
max = ((unsigned HOST_WIDE_INT) 2 << (width - 1)) - 1;
min = 0;
}
else
{
max = signed_max;
min = ((unsigned HOST_WIDE_INT) -1 << (width - 1));
}
if (TREE_INT_CST_HIGH (arg1) == 0
&& TREE_INT_CST_LOW (arg1) == max)
switch (code)
{
case GT_EXPR:
return omit_one_operand (type,
convert (type, integer_zero_node),
arg0);
case GE_EXPR:
code = EQ_EXPR;
TREE_SET_CODE (t, EQ_EXPR);
break;
case LE_EXPR:
return omit_one_operand (type,
convert (type, integer_one_node),
arg0);
case LT_EXPR:
code = NE_EXPR;
TREE_SET_CODE (t, NE_EXPR);
break;
default:
break;
}
else if (TREE_INT_CST_HIGH (arg1) == 0
&& TREE_INT_CST_LOW (arg1) == max - 1)
switch (code)
{
case GT_EXPR:
code = EQ_EXPR;
arg1 = const_binop (PLUS_EXPR, arg1, integer_one_node, 0);
t = build (code, type, TREE_OPERAND (t, 0), arg1);
break;
case LE_EXPR:
code = NE_EXPR;
arg1 = const_binop (PLUS_EXPR, arg1, integer_one_node, 0);
t = build (code, type, TREE_OPERAND (t, 0), arg1);
break;
default:
break;
}
else if (TREE_INT_CST_HIGH (arg1) == (min ? -1 : 0)
&& TREE_INT_CST_LOW (arg1) == min)
switch (code)
{
case LT_EXPR:
return omit_one_operand (type,
convert (type, integer_zero_node),
arg0);
case LE_EXPR:
code = EQ_EXPR;
TREE_SET_CODE (t, EQ_EXPR);
break;
case GE_EXPR:
return omit_one_operand (type,
convert (type, integer_one_node),
arg0);
case GT_EXPR:
code = NE_EXPR;
TREE_SET_CODE (t, NE_EXPR);
break;
default:
break;
}
else if (TREE_INT_CST_HIGH (arg1) == (min ? -1 : 0)
&& TREE_INT_CST_LOW (arg1) == min + 1)
switch (code)
{
case GE_EXPR:
code = NE_EXPR;
arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0);
t = build (code, type, TREE_OPERAND (t, 0), arg1);
break;
case LT_EXPR:
code = EQ_EXPR;
arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0);
t = build (code, type, TREE_OPERAND (t, 0), arg1);
break;
default:
break;
}
else if (TREE_INT_CST_HIGH (arg1) == 0
&& TREE_INT_CST_LOW (arg1) == signed_max
&& TREE_UNSIGNED (TREE_TYPE (arg1))
&& INTEGRAL_TYPE_P (TREE_TYPE (arg1)))
{
if (code == LE_EXPR || code == GT_EXPR)
{
tree st0, st1;
st0 = (*lang_hooks.types.signed_type) (TREE_TYPE (arg0));
st1 = (*lang_hooks.types.signed_type) (TREE_TYPE (arg1));
return fold
(build (code == LE_EXPR ? GE_EXPR: LT_EXPR,
type, convert (st0, arg0),
convert (st1, integer_zero_node)));
}
}
}
}
if ((code == EQ_EXPR || code == NE_EXPR)
&& TREE_CODE (arg1) == INTEGER_CST
&& (TREE_CODE (arg0) == PLUS_EXPR
|| TREE_CODE (arg0) == MINUS_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& 0 != (tem = const_binop (TREE_CODE (arg0) == PLUS_EXPR
? MINUS_EXPR : PLUS_EXPR,
arg1, TREE_OPERAND (arg0, 1), 0))
&& ! TREE_CONSTANT_OVERFLOW (tem))
return fold (build (code, type, TREE_OPERAND (arg0, 0), tem));
else if ((code == EQ_EXPR || code == NE_EXPR)
&& TREE_CODE (arg0) == NEGATE_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = negate_expr (arg1))
&& TREE_CODE (tem) == INTEGER_CST
&& ! TREE_CONSTANT_OVERFLOW (tem))
return fold (build (code, type, TREE_OPERAND (arg0, 0), tem));
else if ((code == NE_EXPR || code == EQ_EXPR)
&& integer_zerop (arg1) && TREE_CODE (arg0) == MINUS_EXPR)
return fold (build (code, type,
TREE_OPERAND (arg0, 0), TREE_OPERAND (arg0, 1)));
else if (TREE_CODE (TREE_TYPE (arg0)) == INTEGER_TYPE
&& TREE_CODE (arg0) == NOP_EXPR
&& (tem = get_unwidened (arg0, NULL_TREE)) != arg0
&& (t1 = get_unwidened (arg1, TREE_TYPE (tem))) != 0
&& (TREE_TYPE (t1) == TREE_TYPE (tem)
|| (TREE_CODE (t1) == INTEGER_CST
&& int_fits_type_p (t1, TREE_TYPE (tem)))))
return fold (build (code, type, tem, convert (TREE_TYPE (tem), t1)));
else if (TREE_CODE (arg1) == INTEGER_CST
&& (TREE_CODE (arg0) == MIN_EXPR
|| TREE_CODE (arg0) == MAX_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
return optimize_minmax_comparison (t);
else if (code == LE_EXPR && TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (arg0) == ABS_EXPR
&& ! TREE_SIDE_EFFECTS (arg0)
&& (0 != (tem = negate_expr (arg1)))
&& TREE_CODE (tem) == INTEGER_CST
&& ! TREE_CONSTANT_OVERFLOW (tem))
return fold (build (TRUTH_ANDIF_EXPR, type,
build (GE_EXPR, type, TREE_OPERAND (arg0, 0), tem),
build (LE_EXPR, type,
TREE_OPERAND (arg0, 0), arg1)));
if (integer_zerop (arg1) && (code == EQ_EXPR || code == NE_EXPR)
&& TREE_CODE (arg0) == BIT_AND_EXPR)
{
if (TREE_CODE (TREE_OPERAND (arg0, 0)) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (TREE_OPERAND (arg0, 0), 0)))
return
fold (build (code, type,
build (BIT_AND_EXPR, TREE_TYPE (arg0),
build (RSHIFT_EXPR,
TREE_TYPE (TREE_OPERAND (arg0, 0)),
TREE_OPERAND (arg0, 1),
TREE_OPERAND (TREE_OPERAND (arg0, 0), 1)),
convert (TREE_TYPE (arg0),
integer_one_node)),
arg1));
else if (TREE_CODE (TREE_OPERAND (arg0, 1)) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (TREE_OPERAND (arg0, 1), 0)))
return
fold (build (code, type,
build (BIT_AND_EXPR, TREE_TYPE (arg0),
build (RSHIFT_EXPR,
TREE_TYPE (TREE_OPERAND (arg0, 1)),
TREE_OPERAND (arg0, 0),
TREE_OPERAND (TREE_OPERAND (arg0, 1), 1)),
convert (TREE_TYPE (arg0),
integer_one_node)),
arg1));
}
if ((code == NE_EXPR || code == EQ_EXPR)
&& integer_zerop (arg1)
&& ! TREE_UNSIGNED (TREE_TYPE (arg0))
&& (TREE_CODE (arg0) == TRUNC_MOD_EXPR
|| TREE_CODE (arg0) == CEIL_MOD_EXPR
|| TREE_CODE (arg0) == FLOOR_MOD_EXPR
|| TREE_CODE (arg0) == ROUND_MOD_EXPR)
&& integer_pow2p (TREE_OPERAND (arg0, 1)))
{
tree newtype = (*lang_hooks.types.unsigned_type) (TREE_TYPE (arg0));
tree newmod = build (TREE_CODE (arg0), newtype,
convert (newtype, TREE_OPERAND (arg0, 0)),
convert (newtype, TREE_OPERAND (arg0, 1)));
return build (code, type, newmod, convert (newtype, arg1));
}
if (code == NE_EXPR && integer_zerop (arg1)
&& TREE_CODE (arg0) == BIT_AND_EXPR
&& integer_onep (TREE_OPERAND (arg0, 1)))
return convert (type, arg0);
if ((code == EQ_EXPR || code == NE_EXPR)
&& TREE_CODE (arg0) == BIT_AND_EXPR
&& integer_pow2p (TREE_OPERAND (arg0, 1))
&& operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
return fold (build (code == EQ_EXPR ? NE_EXPR : EQ_EXPR, type,
arg0, integer_zero_node));
if ((code == EQ_EXPR || code == NE_EXPR)
&& TREE_CODE (arg0) == BIT_AND_EXPR
&& integer_zerop (arg1))
{
tree arg00 = sign_bit_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg0, 1));
if (arg00 != NULL_TREE)
{
tree stype = (*lang_hooks.types.signed_type) (TREE_TYPE (arg00));
return fold (build (code == EQ_EXPR ? GE_EXPR : LT_EXPR, type,
convert (stype, arg00),
convert (stype, integer_zero_node)));
}
}
if ((code == LT_EXPR || code == GE_EXPR)
&& TREE_UNSIGNED (TREE_TYPE (arg0))
&& TREE_CODE (arg1) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (arg1, 0)))
return build (code == LT_EXPR ? EQ_EXPR : NE_EXPR, type,
build (RSHIFT_EXPR, TREE_TYPE (arg0), arg0,
TREE_OPERAND (arg1, 1)),
convert (TREE_TYPE (arg0), integer_zero_node));
else if ((code == LT_EXPR || code == GE_EXPR)
&& TREE_UNSIGNED (TREE_TYPE (arg0))
&& (TREE_CODE (arg1) == NOP_EXPR
|| TREE_CODE (arg1) == CONVERT_EXPR)
&& TREE_CODE (TREE_OPERAND (arg1, 0)) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (TREE_OPERAND (arg1, 0), 0)))
return
build (code == LT_EXPR ? EQ_EXPR : NE_EXPR, type,
convert (TREE_TYPE (arg0),
build (RSHIFT_EXPR, TREE_TYPE (arg0), arg0,
TREE_OPERAND (TREE_OPERAND (arg1, 0), 1))),
convert (TREE_TYPE (arg0), integer_zero_node));
if (operand_equal_p (arg0, arg1, 0))
{
switch (code)
{
case EQ_EXPR:
case GE_EXPR:
case LE_EXPR:
if (! FLOAT_TYPE_P (TREE_TYPE (arg0)))
return constant_boolean_node (1, type);
code = EQ_EXPR;
TREE_SET_CODE (t, code);
break;
case NE_EXPR:
if (FLOAT_TYPE_P (TREE_TYPE (arg0)))
break;
case GT_EXPR:
case LT_EXPR:
return constant_boolean_node (0, type);
default:
abort ();
}
}
if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg0) != INTEGER_CST)
{
tree cval1 = 0, cval2 = 0;
int save_p = 0;
if (twoval_comparison_p (arg0, &cval1, &cval2, &save_p)
&& cval1 != 0 && cval2 != 0
&& ! (TREE_CONSTANT (cval1) && TREE_CONSTANT (cval2))
&& TREE_TYPE (cval1) == TREE_TYPE (cval2)
&& INTEGRAL_TYPE_P (TREE_TYPE (cval1))
&& TYPE_MAX_VALUE (TREE_TYPE (cval1))
&& TYPE_MAX_VALUE (TREE_TYPE (cval2))
&& ! operand_equal_p (TYPE_MIN_VALUE (TREE_TYPE (cval1)),
TYPE_MAX_VALUE (TREE_TYPE (cval2)), 0))
{
tree maxval = TYPE_MAX_VALUE (TREE_TYPE (cval1));
tree minval = TYPE_MIN_VALUE (TREE_TYPE (cval1));
tree high_result
= fold (build (code, type,
eval_subst (arg0, cval1, maxval, cval2, minval),
arg1));
tree equal_result
= fold (build (code, type,
eval_subst (arg0, cval1, maxval, cval2, maxval),
arg1));
tree low_result
= fold (build (code, type,
eval_subst (arg0, cval1, minval, cval2, maxval),
arg1));
if ((integer_zerop (high_result)
|| integer_onep (high_result))
&& (integer_zerop (equal_result)
|| integer_onep (equal_result))
&& (integer_zerop (low_result)
|| integer_onep (low_result)))
{
switch ((integer_onep (high_result) * 4)
+ (integer_onep (equal_result) * 2)
+ integer_onep (low_result))
{
case 0:
return omit_one_operand (type, integer_zero_node, arg0);
case 1:
code = LT_EXPR;
break;
case 2:
code = EQ_EXPR;
break;
case 3:
code = LE_EXPR;
break;
case 4:
code = GT_EXPR;
break;
case 5:
code = NE_EXPR;
break;
case 6:
code = GE_EXPR;
break;
case 7:
return omit_one_operand (type, integer_one_node, arg0);
}
t = build (code, type, cval1, cval2);
if (save_p)
return save_expr (t);
else
return fold (t);
}
}
}
if (((TREE_CODE (arg0) == COMPONENT_REF
&& (*lang_hooks.can_use_bit_fields_p) ())
|| TREE_CODE (arg0) == BIT_FIELD_REF)
&& (code == EQ_EXPR || code == NE_EXPR)
&& (optimize || TREE_CODE (arg1) == INTEGER_CST))
{
t1 = optimize_bit_field_compare (code, type, arg0, arg1);
return t1 ? t1 : t;
}
if ((code == EQ_EXPR || code == NE_EXPR)
&& TREE_CODE (TREE_TYPE (arg0)) == COMPLEX_TYPE
&& (TREE_CODE (arg0) == COMPLEX_EXPR
|| TREE_CODE (arg1) == COMPLEX_EXPR
|| TREE_CODE (arg0) == COMPLEX_CST
|| TREE_CODE (arg1) == COMPLEX_CST))
{
tree subtype = TREE_TYPE (TREE_TYPE (arg0));
tree real0, imag0, real1, imag1;
arg0 = save_expr (arg0);
arg1 = save_expr (arg1);
real0 = fold (build1 (REALPART_EXPR, subtype, arg0));
imag0 = fold (build1 (IMAGPART_EXPR, subtype, arg0));
real1 = fold (build1 (REALPART_EXPR, subtype, arg1));
imag1 = fold (build1 (IMAGPART_EXPR, subtype, arg1));
return fold (build ((code == EQ_EXPR ? TRUTH_ANDIF_EXPR
: TRUTH_ORIF_EXPR),
type,
fold (build (code, type, real0, real1)),
fold (build (code, type, imag0, imag1))));
}
if ((code == EQ_EXPR || code == NE_EXPR)
&& integer_zerop (arg1)
&& TREE_CODE (arg0) == CALL_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == ADDR_EXPR)
{
tree fndecl = TREE_OPERAND (TREE_OPERAND (arg0, 0), 0);
tree arglist;
if (TREE_CODE (fndecl) == FUNCTION_DECL
&& DECL_BUILT_IN (fndecl)
&& DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_MD
&& DECL_FUNCTION_CODE (fndecl) == BUILT_IN_STRLEN
&& (arglist = TREE_OPERAND (arg0, 1))
&& TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) == POINTER_TYPE
&& ! TREE_CHAIN (arglist))
return fold (build (code, type,
build1 (INDIRECT_REF, char_type_node,
TREE_VALUE(arglist)),
integer_zero_node));
}
if (code == LE_EXPR || code == GT_EXPR)
{
tem = arg0, arg0 = arg1, arg1 = tem;
code = swap_tree_comparison (code);
}
t1 = NULL_TREE;
invert = 0;
if (code == NE_EXPR || code == GE_EXPR)
{
invert = 1;
code = invert_tree_comparison (code);
}
if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
{
if (code == EQ_EXPR)
t1 = build_int_2 (tree_int_cst_equal (arg0, arg1), 0);
else
t1 = build_int_2 ((TREE_UNSIGNED (TREE_TYPE (arg0))
? INT_CST_LT_UNSIGNED (arg0, arg1)
: INT_CST_LT (arg0, arg1)),
0);
}
#if 0
else if (TREE_CODE (arg1) == INTEGER_CST
&& !integer_zerop (arg1)
&& TREE_CONSTANT (arg0)
&& TREE_CODE (arg0) == ADDR_EXPR
&& code == EQ_EXPR)
t1 = build_int_2 (0, 0);
#endif
else if (TREE_CODE (arg0) == REAL_CST && TREE_CODE (arg1) == REAL_CST)
{
if (REAL_VALUE_ISNAN (TREE_REAL_CST (arg0))
|| REAL_VALUE_ISNAN (TREE_REAL_CST (arg1)))
t1 = build_int_2 (invert && code == LT_EXPR, 0);
else if (code == EQ_EXPR)
t1 = build_int_2 (REAL_VALUES_EQUAL (TREE_REAL_CST (arg0),
TREE_REAL_CST (arg1)),
0);
else
t1 = build_int_2 (REAL_VALUES_LESS (TREE_REAL_CST (arg0),
TREE_REAL_CST (arg1)),
0);
}
if (t1 == NULL_TREE)
return t;
if (invert)
TREE_INT_CST_LOW (t1) ^= 1;
TREE_TYPE (t1) = type;
if (TREE_CODE (type) == BOOLEAN_TYPE)
return (*lang_hooks.truthvalue_conversion) (t1);
return t1;
case COND_EXPR:
if (TREE_CODE (arg0) == INTEGER_CST)
return pedantic_non_lvalue
(TREE_OPERAND (t, (integer_zerop (arg0) ? 2 : 1)));
else if (operand_equal_p (arg1, TREE_OPERAND (expr, 2), 0))
return pedantic_omit_one_operand (type, arg1, arg0);
if (integer_zerop (arg1)
|| (TREE_CONSTANT (arg1) && ! TREE_CONSTANT (TREE_OPERAND (t, 2)))
|| (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
&& operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (t, 2),
TREE_OPERAND (arg0, 1))))
{
tem = invert_truthvalue (arg0);
if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
{
t = build (code, type, tem,
TREE_OPERAND (t, 2), TREE_OPERAND (t, 1));
arg0 = tem;
arg1 = TREE_OPERAND (t, 1);
STRIP_NOPS (arg1);
}
}
if (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
&& operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0),
arg1, TREE_OPERAND (arg0, 1))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg1))))
{
tree arg2 = TREE_OPERAND (t, 2);
enum tree_code comp_code = TREE_CODE (arg0);
STRIP_NOPS (arg2);
if ((FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (arg0, 1)))
? real_zerop (TREE_OPERAND (arg0, 1))
: integer_zerop (TREE_OPERAND (arg0, 1)))
&& TREE_CODE (arg2) == NEGATE_EXPR
&& operand_equal_p (TREE_OPERAND (arg2, 0), arg1, 0))
switch (comp_code)
{
case EQ_EXPR:
return
pedantic_non_lvalue
(convert (type,
negate_expr
(convert (TREE_TYPE (TREE_OPERAND (t, 1)),
arg1))));
case NE_EXPR:
return pedantic_non_lvalue (convert (type, arg1));
case GE_EXPR:
case GT_EXPR:
if (TREE_UNSIGNED (TREE_TYPE (arg1)))
arg1 = convert ((*lang_hooks.types.signed_type)
(TREE_TYPE (arg1)), arg1);
return pedantic_non_lvalue
(convert (type, fold (build1 (ABS_EXPR,
TREE_TYPE (arg1), arg1))));
case LE_EXPR:
case LT_EXPR:
if (TREE_UNSIGNED (TREE_TYPE (arg1)))
arg1 = convert ((lang_hooks.types.signed_type)
(TREE_TYPE (arg1)), arg1);
return pedantic_non_lvalue
(negate_expr (convert (type,
fold (build1 (ABS_EXPR,
TREE_TYPE (arg1),
arg1)))));
default:
abort ();
}
if (integer_zerop (TREE_OPERAND (arg0, 1)) && integer_zerop (arg2))
{
if (comp_code == NE_EXPR)
return pedantic_non_lvalue (convert (type, arg1));
else if (comp_code == EQ_EXPR)
return pedantic_non_lvalue (convert (type, integer_zero_node));
}
if (operand_equal_for_comparison_p (TREE_OPERAND (arg0, 1),
arg2, TREE_OPERAND (arg0, 0)))
{
tree comp_op0 = TREE_OPERAND (arg0, 0);
tree comp_op1 = TREE_OPERAND (arg0, 1);
tree comp_type = TREE_TYPE (comp_op0);
if (TYPE_MAIN_VARIANT (comp_type) == TYPE_MAIN_VARIANT (type))
comp_type = type;
switch (comp_code)
{
case EQ_EXPR:
return pedantic_non_lvalue (convert (type, arg2));
case NE_EXPR:
return pedantic_non_lvalue (convert (type, arg1));
case LE_EXPR:
case LT_EXPR:
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1))))
return pedantic_non_lvalue
(convert (type, fold (build (MIN_EXPR, comp_type,
(comp_code == LE_EXPR
? comp_op0 : comp_op1),
(comp_code == LE_EXPR
? comp_op1 : comp_op0)))));
break;
case GE_EXPR:
case GT_EXPR:
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1))))
return pedantic_non_lvalue
(convert (type, fold (build (MAX_EXPR, comp_type,
(comp_code == GE_EXPR
? comp_op0 : comp_op1),
(comp_code == GE_EXPR
? comp_op1 : comp_op0)))));
break;
default:
abort ();
}
}
if (INTEGRAL_TYPE_P (type)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& TREE_CODE (arg2) == INTEGER_CST)
switch (comp_code)
{
case EQ_EXPR:
arg1 = convert (type, TREE_OPERAND (arg0, 1));
t = build (code, type, TREE_OPERAND (t, 0), arg1,
TREE_OPERAND (t, 2));
break;
case LT_EXPR:
if (! operand_equal_p (arg2, TYPE_MAX_VALUE (type), 1)
&& operand_equal_p (TREE_OPERAND (arg0, 1),
const_binop (PLUS_EXPR, arg2,
integer_one_node, 0), 1))
return pedantic_non_lvalue
(fold (build (MIN_EXPR, type, arg1, arg2)));
break;
case LE_EXPR:
if (! operand_equal_p (arg2, TYPE_MIN_VALUE (type), 1)
&& operand_equal_p (TREE_OPERAND (arg0, 1),
const_binop (MINUS_EXPR, arg2,
integer_one_node, 0), 1))
return pedantic_non_lvalue
(fold (build (MIN_EXPR, type, arg1, arg2)));
break;
case GT_EXPR:
if (! operand_equal_p (arg2, TYPE_MIN_VALUE (type), 1)
&& operand_equal_p (TREE_OPERAND (arg0, 1),
const_binop (MINUS_EXPR, arg2,
integer_one_node, 0), 1))
return pedantic_non_lvalue
(fold (build (MAX_EXPR, type, arg1, arg2)));
break;
case GE_EXPR:
if (! operand_equal_p (arg2, TYPE_MAX_VALUE (type), 1)
&& operand_equal_p (TREE_OPERAND (arg0, 1),
const_binop (PLUS_EXPR, arg2,
integer_one_node, 0), 1))
return pedantic_non_lvalue
(fold (build (MAX_EXPR, type, arg1, arg2)));
break;
case NE_EXPR:
break;
default:
abort ();
}
}
if ((TREE_CONSTANT (arg1) || DECL_P (arg1)
|| TREE_CODE (arg1) == SAVE_EXPR)
&& ! (TREE_CONSTANT (TREE_OPERAND (t, 2))
|| DECL_P (TREE_OPERAND (t, 2))
|| TREE_CODE (TREE_OPERAND (t, 2)) == SAVE_EXPR))
{
tem = invert_truthvalue (arg0);
if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
{
t = build (code, type, tem,
TREE_OPERAND (t, 2), TREE_OPERAND (t, 1));
arg0 = tem;
arg1 = TREE_OPERAND (t, 1);
STRIP_NOPS (arg1);
}
}
if (integer_onep (TREE_OPERAND (t, 1))
&& integer_zerop (TREE_OPERAND (t, 2))
&& type == TREE_TYPE (arg0))
return pedantic_non_lvalue (arg0);
if (integer_zerop (TREE_OPERAND (t, 1))
&& integer_onep (TREE_OPERAND (t, 2))
&& truth_value_p (TREE_CODE (arg0)))
return pedantic_non_lvalue (convert (type,
invert_truthvalue (arg0)));
if (integer_zerop (TREE_OPERAND (t, 2))
&& TREE_CODE (arg0) == NE_EXPR
&& integer_zerop (TREE_OPERAND (arg0, 1))
&& integer_pow2p (arg1)
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == BIT_AND_EXPR
&& operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1),
arg1, 1))
return pedantic_non_lvalue (convert (type, TREE_OPERAND (arg0, 0)));
if (integer_zerop (TREE_OPERAND (t, 2))
&& truth_value_p (TREE_CODE (arg0))
&& truth_value_p (TREE_CODE (arg1)))
return pedantic_non_lvalue (fold (build (TRUTH_ANDIF_EXPR, type,
arg0, arg1)));
if (integer_onep (TREE_OPERAND (t, 2))
&& truth_value_p (TREE_CODE (arg0))
&& truth_value_p (TREE_CODE (arg1)))
{
tem = invert_truthvalue (arg0);
if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
return pedantic_non_lvalue (fold (build (TRUTH_ORIF_EXPR, type,
tem, arg1)));
}
return t;
case COMPOUND_EXPR:
if (TREE_SIDE_EFFECTS (arg0) || pedantic)
return t;
if (integer_zerop (arg1))
return build1 (NOP_EXPR, type, arg1);
return convert (type, arg1);
case COMPLEX_EXPR:
if (wins)
return build_complex (type, arg0, arg1);
return t;
case REALPART_EXPR:
if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
return t;
else if (TREE_CODE (arg0) == COMPLEX_EXPR)
return omit_one_operand (type, TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg0, 1));
else if (TREE_CODE (arg0) == COMPLEX_CST)
return TREE_REALPART (arg0);
else if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
return fold (build (TREE_CODE (arg0), type,
fold (build1 (REALPART_EXPR, type,
TREE_OPERAND (arg0, 0))),
fold (build1 (REALPART_EXPR,
type, TREE_OPERAND (arg0, 1)))));
return t;
case IMAGPART_EXPR:
if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
return convert (type, integer_zero_node);
else if (TREE_CODE (arg0) == COMPLEX_EXPR)
return omit_one_operand (type, TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg0, 0));
else if (TREE_CODE (arg0) == COMPLEX_CST)
return TREE_IMAGPART (arg0);
else if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
return fold (build (TREE_CODE (arg0), type,
fold (build1 (IMAGPART_EXPR, type,
TREE_OPERAND (arg0, 0))),
fold (build1 (IMAGPART_EXPR, type,
TREE_OPERAND (arg0, 1)))));
return t;
case CLEANUP_POINT_EXPR:
if (! has_cleanups (arg0))
return TREE_OPERAND (t, 0);
{
enum tree_code code0 = TREE_CODE (arg0);
int kind0 = TREE_CODE_CLASS (code0);
tree arg00 = TREE_OPERAND (arg0, 0);
tree arg01;
if (kind0 == '1' || code0 == TRUTH_NOT_EXPR)
return fold (build1 (code0, type,
fold (build1 (CLEANUP_POINT_EXPR,
TREE_TYPE (arg00), arg00))));
if (kind0 == '<' || kind0 == '2'
|| code0 == TRUTH_ANDIF_EXPR || code0 == TRUTH_ORIF_EXPR
|| code0 == TRUTH_AND_EXPR || code0 == TRUTH_OR_EXPR
|| code0 == TRUTH_XOR_EXPR)
{
arg01 = TREE_OPERAND (arg0, 1);
if (TREE_CONSTANT (arg00)
|| ((code0 == TRUTH_ANDIF_EXPR || code0 == TRUTH_ORIF_EXPR)
&& ! has_cleanups (arg00)))
return fold (build (code0, type, arg00,
fold (build1 (CLEANUP_POINT_EXPR,
TREE_TYPE (arg01), arg01))));
if (TREE_CONSTANT (arg01))
return fold (build (code0, type,
fold (build1 (CLEANUP_POINT_EXPR,
TREE_TYPE (arg00), arg00)),
arg01));
}
return t;
}
case CALL_EXPR:
if (TREE_CODE (TREE_OPERAND (expr, 0)) == ADDR_EXPR
&& (TREE_CODE (TREE_OPERAND (TREE_OPERAND (expr, 0), 0))
== FUNCTION_DECL)
&& DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (expr, 0), 0)))
{
tree tmp = fold_builtin (expr);
if (tmp)
return tmp;
}
return t;
default:
return t;
}
}
static int
multiple_of_p (type, top, bottom)
tree type;
tree top;
tree bottom;
{
if (operand_equal_p (top, bottom, 0))
return 1;
if (TREE_CODE (type) != INTEGER_TYPE)
return 0;
switch (TREE_CODE (top))
{
case MULT_EXPR:
return (multiple_of_p (type, TREE_OPERAND (top, 0), bottom)
|| multiple_of_p (type, TREE_OPERAND (top, 1), bottom));
case PLUS_EXPR:
case MINUS_EXPR:
return (multiple_of_p (type, TREE_OPERAND (top, 0), bottom)
&& multiple_of_p (type, TREE_OPERAND (top, 1), bottom));
case LSHIFT_EXPR:
if (TREE_CODE (TREE_OPERAND (top, 1)) == INTEGER_CST)
{
tree op1, t1;
op1 = TREE_OPERAND (top, 1);
if (TYPE_PRECISION (TREE_TYPE (size_one_node))
> TREE_INT_CST_LOW (op1)
&& TREE_INT_CST_HIGH (op1) == 0
&& 0 != (t1 = convert (type,
const_binop (LSHIFT_EXPR, size_one_node,
op1, 0)))
&& ! TREE_OVERFLOW (t1))
return multiple_of_p (type, t1, bottom);
}
return 0;
case NOP_EXPR:
if ((TREE_CODE (TREE_TYPE (TREE_OPERAND (top, 0))) != INTEGER_TYPE)
|| (TYPE_PRECISION (type)
< TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (top, 0)))))
return 0;
case SAVE_EXPR:
return multiple_of_p (type, TREE_OPERAND (top, 0), bottom);
case INTEGER_CST:
if (TREE_CODE (bottom) != INTEGER_CST
|| (TREE_UNSIGNED (type)
&& (tree_int_cst_sgn (top) < 0
|| tree_int_cst_sgn (bottom) < 0)))
return 0;
return integer_zerop (const_binop (TRUNC_MOD_EXPR,
top, bottom, 0));
default:
return 0;
}
}
int
tree_expr_nonnegative_p (t)
tree t;
{
switch (TREE_CODE (t))
{
case ABS_EXPR:
case FFS_EXPR:
return 1;
case INTEGER_CST:
return tree_int_cst_sgn (t) >= 0;
case TRUNC_DIV_EXPR:
case CEIL_DIV_EXPR:
case FLOOR_DIV_EXPR:
case ROUND_DIV_EXPR:
return tree_expr_nonnegative_p (TREE_OPERAND (t, 0))
&& tree_expr_nonnegative_p (TREE_OPERAND (t, 1));
case TRUNC_MOD_EXPR:
case CEIL_MOD_EXPR:
case FLOOR_MOD_EXPR:
case ROUND_MOD_EXPR:
return tree_expr_nonnegative_p (TREE_OPERAND (t, 0));
case COND_EXPR:
return tree_expr_nonnegative_p (TREE_OPERAND (t, 1))
&& tree_expr_nonnegative_p (TREE_OPERAND (t, 2));
case COMPOUND_EXPR:
return tree_expr_nonnegative_p (TREE_OPERAND (t, 1));
case MIN_EXPR:
return tree_expr_nonnegative_p (TREE_OPERAND (t, 0))
&& tree_expr_nonnegative_p (TREE_OPERAND (t, 1));
case MAX_EXPR:
return tree_expr_nonnegative_p (TREE_OPERAND (t, 0))
|| tree_expr_nonnegative_p (TREE_OPERAND (t, 1));
case MODIFY_EXPR:
return tree_expr_nonnegative_p (TREE_OPERAND (t, 1));
case BIND_EXPR:
return tree_expr_nonnegative_p (TREE_OPERAND (t, 1));
case SAVE_EXPR:
return tree_expr_nonnegative_p (TREE_OPERAND (t, 0));
case NON_LVALUE_EXPR:
return tree_expr_nonnegative_p (TREE_OPERAND (t, 0));
case RTL_EXPR:
return rtl_expr_nonnegative_p (RTL_EXPR_RTL (t));
default:
if (truth_value_p (TREE_CODE (t)))
return 1;
else
return 0;
}
}
int
rtl_expr_nonnegative_p (r)
rtx r;
{
switch (GET_CODE (r))
{
case CONST_INT:
return INTVAL (r) >= 0;
case CONST_DOUBLE:
if (GET_MODE (r) == VOIDmode)
return CONST_DOUBLE_HIGH (r) >= 0;
return 0;
case CONST_VECTOR:
{
int units, i;
rtx elt;
units = CONST_VECTOR_NUNITS (r);
for (i = 0; i < units; ++i)
{
elt = CONST_VECTOR_ELT (r, i);
if (!rtl_expr_nonnegative_p (elt))
return 0;
}
return 1;
}
case SYMBOL_REF:
case LABEL_REF:
return 1;
default:
return 0;
}
}
#include "gt-fold-const.h"