This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Faster compilation speed
- From: Mike Stump <mrs at apple dot com>
- To: Mike Stump <mrs at apple dot com>
- Cc: Neil Booth <neil at daikokuya dot co dot uk>, gcc at gcc dot gnu dot org
- Date: Mon, 12 Aug 2002 19:17:38 -0700
- Subject: Re: Faster compilation speed
On Monday, August 12, 2002, at 12:11 PM, Mike Stump wrote:
On Friday, August 9, 2002, at 02:27 PM, Neil Booth wrote:
(e.g. I think we try to constant fold
things that we've already tried to constant fold and failed,
repeatedly,
and we don't do the constant folding we do do in an optimal way.
Hum. 82,000 calls to fold. [ typing ] [ can I just remove it, more
typing, nope. ]
Hum. I'll have to jot that down on my list of things to look at. :-)
Ok, I looked at it. A straight forward check to see it is has been
folded first with the use of an existing unused bit in the tree speeds
it up by 1.0003, or not enough to bother with all the code and the use
of the extra bit that someone else may find more valuable. :-(
This is why benchmarking things is so important, yes, it is a theoretic
speedup, but in reality, it really isn't worth it.
I'll include the code below, just in case anyone wants to try it on
other source codes... Or suggest other ways...
Doing diffs in tree.h.~1.348.~:
*** tree.h.~1.348.~ Mon Aug 12 17:44:32 2002
--- tree.h Mon Aug 12 18:42:33 2002
*************** struct tree_common GTY(())
*** 133,139 ****
unsigned readonly_flag : 1;
unsigned unsigned_flag : 1;
unsigned asm_written_flag: 1;
! unsigned unused_0 : 1;
unsigned used_flag : 1;
unsigned nothrow_flag : 1;
--- 133,139 ----
unsigned readonly_flag : 1;
unsigned unsigned_flag : 1;
unsigned asm_written_flag: 1;
! unsigned folded_flag : 1;
unsigned used_flag : 1;
unsigned nothrow_flag : 1;
*************** extern void tree_class_check_failed PARA
*** 609,614 ****
--- 609,616 ----
if the sdb debugging info for the type has been written.
In a BLOCK node, nonzero if reorder_blocks has already seen this
block. */
#define TREE_ASM_WRITTEN(NODE) ((NODE)->common.asm_written_flag)
+
+ #define TREE_FOLDED(NODE) ((NODE)->common.folded_flag)
/* Nonzero in a _DECL if the name is used in its scope.
Nonzero in an expr node means inhibit warning if value is unused.
--------------
Doing diffs in tree.h.~1~:
*** tree.h.~1~ Fri Aug 9 10:17:40 2002
--- tree.h Mon Aug 12 18:42:33 2002
*************** struct tree_common GTY(())
*** 133,139 ****
unsigned readonly_flag : 1;
unsigned unsigned_flag : 1;
unsigned asm_written_flag: 1;
! unsigned unused_0 : 1;
unsigned used_flag : 1;
unsigned nothrow_flag : 1;
--- 133,139 ----
unsigned readonly_flag : 1;
unsigned unsigned_flag : 1;
unsigned asm_written_flag: 1;
! unsigned folded_flag : 1;
unsigned used_flag : 1;
unsigned nothrow_flag : 1;
*************** extern void tree_class_check_failed PARA
*** 609,614 ****
--- 609,616 ----
if the sdb debugging info for the type has been written.
In a BLOCK node, nonzero if reorder_blocks has already seen this
block. */
#define TREE_ASM_WRITTEN(NODE) ((NODE)->common.asm_written_flag)
+
+ #define TREE_FOLDED(NODE) ((NODE)->common.folded_flag)
/* Nonzero in a _DECL if the name is used in its scope.
Nonzero in an expr node means inhibit warning if value is unused.
--------------
bash-2.05a$ diff -c -p fold-const.c.~1~ fold-const.c.~2~
*** fold-const.c.~1~ Fri Aug 9 10:17:36 2002
--- fold-const.c.~2~ Mon Aug 12 18:56:20 2002
*************** fold (expr)
*** 4581,4594 ****
if all operands are constant. */
int wins = 1;
/* Don't try to process an RTL_EXPR since its operands aren't trees.
Likewise for a SAVE_EXPR that's already been evaluated. */
if (code == RTL_EXPR || (code == SAVE_EXPR && SAVE_EXPR_RTL (t) !=
0))
! return t;
/* Return right away if a constant. */
if (kind == 'c')
! return t;
#ifdef MAX_INTEGER_COMPUTATION_MODE
check_max_integer_computation_mode (expr);
--- 4581,4603 ----
if all operands are constant. */
int wins = 1;
+ if (SPEEDCOMPILE && TREE_FOLDED (t))
+ return t;
+
/* Don't try to process an RTL_EXPR since its operands aren't trees.
Likewise for a SAVE_EXPR that's already been evaluated. */
if (code == RTL_EXPR || (code == SAVE_EXPR && SAVE_EXPR_RTL (t) !=
0))
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Return right away if a constant. */
if (kind == 'c')
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
#ifdef MAX_INTEGER_COMPUTATION_MODE
check_max_integer_computation_mode (expr);
*************** fold (expr)
*** 4709,4722 ****
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)
{
t = fold (build (COND_EXPR, type, TREE_OPERAND (arg0, 0),
--- 4718,4736 ----
if (code == EQ_EXPR)
t = invert_truthvalue (t);
+ TREE_FOLDED (t) = 1;
return t;
}
if (TREE_CODE_CLASS (code) == '1')
{
if (TREE_CODE (arg0) == COMPOUND_EXPR)
! {
! t = build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
! fold (build1 (code, type, TREE_OPERAND (arg0,
1))));
! TREE_FOLDED (t) = 1;
! return t;
! }
else if (TREE_CODE (arg0) == COND_EXPR)
{
t = fold (build (COND_EXPR, type, TREE_OPERAND (arg0, 0),
*************** fold (expr)
*** 4750,4769 ****
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)
! 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) != '<'))
--- 4764,4792 ----
TREE_OPERAND (t, 0),
TREE_OPERAND (TREE_OPERAND (t, 1), 0),
TREE_OPERAND (TREE_OPERAND (t, 2), 0)));
+ TREE_FOLDED (t) = 1;
return t;
}
else if (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<')
! {
! t = fold (build (COND_EXPR, type, arg0,
! fold (build1 (code, type, integer_one_node)),
! fold (build1 (code, type,
integer_zero_node))));
! TREE_FOLDED (t) = 1;
! return t;
! }
}
else if (TREE_CODE_CLASS (code) == '2'
|| TREE_CODE_CLASS (code) == '<')
{
if (TREE_CODE (arg1) == COMPOUND_EXPR)
! {
! t = build (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0),
! fold (build (code, type,
! arg0, TREE_OPERAND (arg1, 1))));
! TREE_FOLDED (t) = 1;
! return t;
! }
else if ((TREE_CODE (arg1) == COND_EXPR
|| (TREE_CODE_CLASS (TREE_CODE (arg1)) == '<'
&& TREE_CODE_CLASS (code) != '<'))
*************** fold (expr)
*** 4772,4783 ****
&& (! 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,
! /*cond_first_p=*/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) != '<'))
--- 4795,4813 ----
&& (! TREE_SIDE_EFFECTS (arg0)
|| ((*lang_hooks.decls.global_bindings_p) () == 0
&& ! contains_placeholder_p (arg0))))
! {
! t = fold_binary_op_with_conditional_arg (code, type, arg1,
arg0,
! /*cond_first_p=*/0);
! TREE_FOLDED (t) = 1;
! return t;
! }
else if (TREE_CODE (arg0) == COMPOUND_EXPR)
! {
! t = build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
! fold (build (code, type, TREE_OPERAND (arg0, 1),
arg1)));
! TREE_FOLDED (t) = 1;
! return t;
! }
else if ((TREE_CODE (arg0) == COND_EXPR
|| (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
&& TREE_CODE_CLASS (code) != '<'))
*************** fold (expr)
*** 4786,4803 ****
&& (! 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,
! /*cond_first_p=*/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)
{
--- 4816,4844 ----
&& (! TREE_SIDE_EFFECTS (arg1)
|| ((*lang_hooks.decls.global_bindings_p) () == 0
&& ! contains_placeholder_p (arg1))))
! {
! t = fold_binary_op_with_conditional_arg (code, type, arg0,
arg1,
! /*cond_first_p=*/1);
! TREE_FOLDED (t) = 1;
! return t;
! }
}
else if (TREE_CODE_CLASS (code) == '<'
&& TREE_CODE (arg0) == COMPOUND_EXPR)
! {
! t = build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
fold (build (code, type, TREE_OPERAND (arg0, 1),
arg1)));
+ TREE_FOLDED (t) = 1;
+ return t;
+ }
else if (TREE_CODE_CLASS (code) == '<'
&& TREE_CODE (arg1) == COMPOUND_EXPR)
! {
! t = build (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0),
! fold (build (code, type, arg0, TREE_OPERAND (arg1,
1))));
! TREE_FOLDED (t) = 1;
! return t;
! }
switch (code)
{
*************** fold (expr)
*** 4807,4812 ****
--- 4848,4854 ----
case STRING_CST:
case COMPLEX_CST:
case CONSTRUCTOR:
+ TREE_FOLDED (t) = 1;
return t;
case CONST_DECL:
*************** fold (expr)
*** 4851,4857 ****
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));
/* Likewise, if the intermediate and final types are either
both
float or both integer, we don't need the middle conversion
if
--- 4893,4903 ----
if (TYPE_MAIN_VARIANT (inside_type) == TYPE_MAIN_VARIANT
(final_type)
&& ((inter_int && final_int) || (inter_float &&
final_float))
&& inter_prec >= final_prec)
! {
! t = convert (final_type, TREE_OPERAND (TREE_OPERAND (t,
0), 0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Likewise, if the intermediate and final types are either
both
float or both integer, we don't need the middle conversion
if
*************** fold (expr)
*** 4866,4879 ****
&& ! (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 we have a sign-extension of a zero-extended value, we
can
replace that by a single zero-extension. */
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));
/* Two conversions in a row are not needed unless:
- some conversion is floating-point (overstrict for now),
or
--- 4912,4933 ----
&& ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE
(final_type))
&& TYPE_MODE (final_type) == TYPE_MODE (inter_type))
&& ! final_ptr)
! {
! t = convert (final_type, TREE_OPERAND (TREE_OPERAND (t,
0), 0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* If we have a sign-extension of a zero-extended value, we
can
replace that by a single zero-extension. */
if (inside_int && inter_int && final_int
&& inside_prec < inter_prec && inter_prec < final_prec
&& inside_unsignedp && !inter_unsignedp)
! {
! t = convert (final_type, TREE_OPERAND (TREE_OPERAND (t,
0), 0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Two conversions in a row are not needed unless:
- some conversion is floating-point (overstrict for now),
or
*************** fold (expr)
*** 4897,4903 ****
&& ! (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
--- 4951,4961 ----
&& ! (final_prec != GET_MODE_BITSIZE (TYPE_MODE
(final_type))
&& TYPE_MODE (final_type) == TYPE_MODE (inter_type))
&& ! final_ptr)
! {
! t = convert (final_type, TREE_OPERAND (TREE_OPERAND (t,
0), 0));
! TREE_FOLDED (t) = 1;
! return t;
! }
}
if (TREE_CODE (TREE_OPERAND (t, 0)) == MODIFY_EXPR
*************** fold (expr)
*** 4913,4918 ****
--- 4971,4977 ----
/* First do the assignment, then return converted constant.
*/
t = build (COMPOUND_EXPR, TREE_TYPE (t), prev, fold (t));
TREE_USED (t) = 1;
+ TREE_FOLDED (t) = 1;
return t;
}
*************** fold (expr)
*** 4962,4975 ****
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:
--- 5021,5038 ----
if (!wins)
{
TREE_CONSTANT (t) = TREE_CONSTANT (arg0);
+ TREE_FOLDED (t) = 1;
return t;
}
! t = fold_convert (t, arg0);
! TREE_FOLDED (t) = 1;
! return t;
case VIEW_CONVERT_EXPR:
if (TREE_CODE (TREE_OPERAND (t, 0)) == VIEW_CONVERT_EXPR)
! t = build1 (VIEW_CONVERT_EXPR, type,
! TREE_OPERAND (TREE_OPERAND (t, 0), 0));
! TREE_FOLDED (t) = 1;
return t;
case COMPONENT_REF:
*************** fold (expr)
*** 4979,4988 ****
--- 5042,5053 ----
if (m)
t = TREE_VALUE (m);
}
+ TREE_FOLDED (t) = 1;
return t;
case RANGE_EXPR:
TREE_CONSTANT (t) = wins;
+ TREE_FOLDED (t) = 1;
return t;
case NEGATE_EXPR:
*************** fold (expr)
*** 5012,5020 ****
/* Convert - (a - b) to (b - a) for non-floating-point. */
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:
--- 5077,5086 ----
/* Convert - (a - b) to (b - a) for non-floating-point. */
else if (TREE_CODE (arg0) == MINUS_EXPR
&& (! FLOAT_TYPE_P (type) ||
flag_unsafe_math_optimizations))
! t = build (MINUS_EXPR, type, TREE_OPERAND (arg0, 1),
! TREE_OPERAND (arg0, 0));
+ TREE_FOLDED (t) = 1;
return t;
case ABS_EXPR:
*************** fold (expr)
*** 5055,5073 ****
}
}
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,
--- 5121,5140 ----
}
}
else if (TREE_CODE (arg0) == ABS_EXPR || TREE_CODE (arg0) ==
NEGATE_EXPR)
! t = build1 (ABS_EXPR, type, TREE_OPERAND (arg0, 0));
! TREE_FOLDED (t) = 1;
return t;
case CONJ_EXPR:
if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
! t = convert (type, arg0);
else if (TREE_CODE (arg0) == COMPLEX_EXPR)
! t = build (COMPLEX_EXPR, type,
! TREE_OPERAND (arg0, 0),
! negate_expr (TREE_OPERAND (arg0, 1)));
else if (TREE_CODE (arg0) == COMPLEX_CST)
! t = 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,
*************** fold (expr)
*** 5076,5081 ****
--- 5143,5149 ----
type, TREE_OPERAND (arg0,
1)))));
else if (TREE_CODE (arg0) == CONJ_EXPR)
return TREE_OPERAND (arg0, 0);
+ TREE_FOLDED (t) = 1;
return t;
case BIT_NOT_EXPR:
*************** fold (expr)
*** 5090,5095 ****
--- 5158,5164 ----
}
else if (TREE_CODE (arg0) == BIT_NOT_EXPR)
return TREE_OPERAND (arg0, 0);
+ TREE_FOLDED (t) = 1;
return t;
case PLUS_EXPR:
*************** fold (expr)
*** 5102,5108 ****
else if (! FLOAT_TYPE_P (type))
{
if (integer_zerop (arg1))
! return non_lvalue (convert (type, arg0));
/* If we are adding two BIT_AND_EXPR's, both of which are
and'ing
with a constant, and the two constants have no bits in
common,
--- 5171,5181 ----
else if (! FLOAT_TYPE_P (type))
{
if (integer_zerop (arg1))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* If we are adding two BIT_AND_EXPR's, both of which are
and'ing
with a constant, and the two constants have no bits in
common,
*************** fold (expr)
*** 5215,5225 ****
/* See if ARG1 is zero and X + ARG1 reduces to X. */
else if (fold_real_zero_addition_p (TREE_TYPE (arg0), arg1, 0))
! return non_lvalue (convert (type, arg0));
/* Likewise if the operands are reversed. */
else if (fold_real_zero_addition_p (TREE_TYPE (arg1), arg0, 0))
! return non_lvalue (convert (type, arg1));
bit_rotate:
/* (A << C1) + (A >> C2) if A is unsigned and C1+C2 is the size
of A
--- 5288,5306 ----
/* See if ARG1 is zero and X + ARG1 reduces to X. */
else if (fold_real_zero_addition_p (TREE_TYPE (arg0), arg1, 0))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Likewise if the operands are reversed. */
else if (fold_real_zero_addition_p (TREE_TYPE (arg1), arg0, 0))
! {
! t = non_lvalue (convert (type, arg1));
! TREE_FOLDED (t) = 1;
! return t;
! }
bit_rotate:
/* (A << C1) + (A >> C2) if A is unsigned and C1+C2 is the size
of A
*************** fold (expr)
*** 5251,5258 ****
&& 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;
--- 5332,5343 ----
&& TREE_INT_CST_HIGH (tree11) == 0
&& ((TREE_INT_CST_LOW (tree01) + TREE_INT_CST_LOW
(tree11))
== TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0,
0)))))
! {
! t = build (LROTATE_EXPR, type, TREE_OPERAND (arg0, 0),
! code0 == LSHIFT_EXPR ? tree01 : tree11);
! TREE_FOLDED (t) = 1;
! return t;
! }
else if (code11 == MINUS_EXPR)
{
tree tree110, tree111;
*************** fold (expr)
*** 5266,5275 ****
(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)
{
--- 5351,5364 ----
(TREE_TYPE (TREE_OPERAND
(arg0, 0))))
&& operand_equal_p (tree01, tree111, 0))
! {
! t = build ((code0 == LSHIFT_EXPR
! ? LROTATE_EXPR
! : RROTATE_EXPR),
! type, TREE_OPERAND (arg0, 0), tree01);
! TREE_FOLDED (t) = 1;
! return t;
! }
}
else if (code01 == MINUS_EXPR)
{
*************** fold (expr)
*** 5284,5293 ****
(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);
}
}
}
--- 5373,5386 ----
(TREE_TYPE (TREE_OPERAND
(arg0, 0))))
&& operand_equal_p (tree11, tree011, 0))
! {
! t = build ((code0 != LSHIFT_EXPR
! ? LROTATE_EXPR
! : RROTATE_EXPR),
! type, TREE_OPERAND (arg0, 0), tree11);
! TREE_FOLDED (t) = 1;
! return t;
! }
}
}
}
*************** fold (expr)
*** 5354,5372 ****
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));
}
}
--- 5447,5473 ----
if (minus_lit0)
{
if (con0 == 0)
! {
! t = convert (type, associate_trees (var0,
minus_lit0,
! MINUS_EXPR,
type));
! TREE_FOLDED (t) = 1;
! return t;
! }
else
{
con0 = associate_trees (con0, minus_lit0,
MINUS_EXPR, type);
! t = convert (type, associate_trees (var0, con0,
! PLUS_EXPR,
type));
! TREE_FOLDED (t) = 1;
! return t;
}
}
con0 = associate_trees (con0, lit0, code, type);
! t = convert (type, associate_trees (var0, con0, code,
type));
! TREE_FOLDED (t) = 1;
! return t;
}
}
*************** fold (expr)
*** 5380,5387 ****
--- 5481,5490 ----
if (TREE_TYPE (t1) != TREE_TYPE (t))
t1 = convert (TREE_TYPE (t), t1);
+ TREE_FOLDED (t1) = 1;
return t1;
}
+ TREE_FOLDED (t) = 1;
return t;
case MINUS_EXPR:
*************** fold (expr)
*** 5399,5407 ****
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));
/* (A * C) - (B * C) -> (A-B) * C. Since we are most
concerned
about the case where C is a constant, just try one of the
--- 5502,5518 ----
if (! FLOAT_TYPE_P (type))
{
if (! wins && integer_zerop (arg0))
! {
! t = negate_expr (convert (type, arg1));
! TREE_FOLDED (t) = 1;
! return t;
! }
if (integer_zerop (arg1))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* (A * C) - (B * C) -> (A-B) * C. Since we are most
concerned
about the case where C is a constant, just try one of the
*************** fold (expr)
*** 5419,5431 ****
/* See if ARG1 is zero and X - ARG1 reduces to X. */
else if (fold_real_zero_addition_p (TREE_TYPE (arg0), arg1, 1))
! return non_lvalue (convert (type, arg0));
/* (ARG0 - ARG1) is the same as (-ARG1 + ARG0). So check
whether
ARG0 is zero and X + ARG0 reduces to X, since that would mean
(-ARG1 + ARG0) reduces to -ARG1. */
else if (!wins && fold_real_zero_addition_p (TREE_TYPE (arg1),
arg0, 0))
! return negate_expr (convert (type, arg1));
/* Fold &x - &x. This can happen from &x.foo - &x.
This is unsafe for certain floats even in non-IEEE formats.
--- 5530,5550 ----
/* See if ARG1 is zero and X - ARG1 reduces to X. */
else if (fold_real_zero_addition_p (TREE_TYPE (arg0), arg1, 1))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* (ARG0 - ARG1) is the same as (-ARG1 + ARG0). So check
whether
ARG0 is zero and X + ARG0 reduces to X, since that would mean
(-ARG1 + ARG0) reduces to -ARG1. */
else if (!wins && fold_real_zero_addition_p (TREE_TYPE (arg1),
arg0, 0))
! {
! t = negate_expr (convert (type, arg1));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Fold &x - &x. This can happen from &x.foo - &x.
This is unsafe for certain floats even in non-IEEE formats.
*************** fold (expr)
*** 5435,5441 ****
if ((! FLOAT_TYPE_P (type) || flag_unsafe_math_optimizations)
&& operand_equal_p (arg0, arg1, 0))
! return convert (type, integer_zero_node);
goto associate;
--- 5554,5564 ----
if ((! FLOAT_TYPE_P (type) || flag_unsafe_math_optimizations)
&& operand_equal_p (arg0, arg1, 0))
! {
! t = convert (type, integer_zero_node);
! TREE_FOLDED (t) = 1;
! return t;
! }
goto associate;
*************** fold (expr)
*** 5448,5456 ****
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));
/* (a * (1 << b)) is (a << b) */
if (TREE_CODE (arg1) == LSHIFT_EXPR
--- 5571,5587 ----
if (! FLOAT_TYPE_P (type))
{
if (integer_zerop (arg1))
! {
! t = omit_one_operand (type, arg1, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
if (integer_onep (arg1))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* (a * (1 << b)) is (a << b) */
if (TREE_CODE (arg1) == LSHIFT_EXPR
*************** fold (expr)
*** 5465,5471 ****
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (TREE_OPERAND (t, 0), arg1,
code, NULL_TREE)))
! return convert (type, tem);
}
else
--- 5596,5606 ----
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (TREE_OPERAND (t, 0), arg1,
code, NULL_TREE)))
! {
! t = convert (type, tem);
! TREE_FOLDED (t) = 1;
! return t;
! }
}
else
*************** fold (expr)
*** 5477,5487 ****
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);
/* In IEEE floating point, x*1 is not equivalent to x for
snans. */
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_onep (arg1))
! return non_lvalue (convert (type, arg0));
/* Transform x * -1.0 into -x. */
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
--- 5612,5630 ----
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_zerop (arg1))
! {
! t = omit_one_operand (type, arg1, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
/* In IEEE floating point, x*1 is not equivalent to x for
snans. */
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_onep (arg1))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Transform x * -1.0 into -x. */
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
*************** fold (expr)
*** 5494,5500 ****
&& ! contains_placeholder_p (arg0))
{
tree arg = save_expr (arg0);
! return build (PLUS_EXPR, type, arg, arg);
}
}
goto associate;
--- 5637,5645 ----
&& ! contains_placeholder_p (arg0))
{
tree arg = save_expr (arg0);
! t = build (PLUS_EXPR, type, arg, arg);
! TREE_FOLDED (t) = 1;
! return t;
}
}
goto associate;
*************** fold (expr)
*** 5502,5513 ****
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;
/* Convert (or (not arg0) (not arg1)) to (not (and (arg0)
(arg1))).
--- 5647,5669 ----
case BIT_IOR_EXPR:
bit_ior:
if (integer_all_onesp (arg1))
! {
! t = omit_one_operand (type, arg1, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
if (integer_zerop (arg1))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
t1 = distribute_bit_expr (code, type, arg0, arg1);
if (t1 != NULL_TREE)
! {
! TREE_FOLDED (t1) = 1;
! return t1;
! }
/* Convert (or (not arg0) (not arg1)) to (not (and (arg0)
(arg1))).
*************** fold (expr)
*** 5530,5536 ****
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));
--- 5686,5696 ----
case BIT_XOR_EXPR:
if (integer_zerop (arg1))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
if (integer_all_onesp (arg1))
return fold (build1 (BIT_NOT_EXPR, type, arg0));
*************** fold (expr)
*** 5557,5568 ****
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;
/* Simplify ((int)c & 0x377) into (int)c, if c is unsigned
char. */
if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg0) ==
NOP_EXPR
&& TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0))))
--- 5717,5739 ----
case BIT_AND_EXPR:
bit_and:
if (integer_all_onesp (arg1))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
if (integer_zerop (arg1))
! {
! t = omit_one_operand (type, arg1, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
t1 = distribute_bit_expr (code, type, arg0, arg1);
if (t1 != NULL_TREE)
! {
! TREE_FOLDED (t1) = 1;
! return t1;
! }
/* Simplify ((int)c & 0x377) into (int)c, if c is unsigned
char. */
if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg0) ==
NOP_EXPR
&& TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0))))
*************** fold (expr)
*** 5573,5579 ****
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));
}
/* Convert (and (not arg0) (not arg1)) to (not (or (arg0)
(arg1))).
--- 5744,5754 ----
if (prec < BITS_PER_WORD && prec < HOST_BITS_PER_WIDE_INT
&& (~TREE_INT_CST_LOW (arg1)
& (((HOST_WIDE_INT) 1 << prec) - 1)) == 0)
! {
! t = build1 (NOP_EXPR, type, TREE_OPERAND (arg0, 0));
! TREE_FOLDED (t) = 1;
! return t;
! }
}
/* Convert (and (not arg0) (not arg1)) to (not (or (arg0)
(arg1))).
*************** fold (expr)
*** 5595,5603 ****
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));
--- 5770,5786 ----
case BIT_ANDTC_EXPR:
if (integer_all_onesp (arg0))
! {
! t = non_lvalue (convert (type, arg1));
! TREE_FOLDED (t) = 1;
! return t;
! }
if (integer_zerop (arg0))
! {
! t = omit_one_operand (type, arg0, arg1);
! TREE_FOLDED (t) = 1;
! return t;
! }
if (TREE_CODE (arg1) == INTEGER_CST)
{
arg1 = fold (build1 (BIT_NOT_EXPR, type, arg1));
*************** fold (expr)
*** 5612,5618 ****
if (TREE_CODE (arg1) == REAL_CST
&& !MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg1)))
&& real_zerop (arg1))
! return t;
/* (-A) / (-B) -> A / B */
if (TREE_CODE (arg0) == NEGATE_EXPR && TREE_CODE (arg1) ==
NEGATE_EXPR)
--- 5795,5804 ----
if (TREE_CODE (arg1) == REAL_CST
&& !MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg1)))
&& real_zerop (arg1))
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
/* (-A) / (-B) -> A / B */
if (TREE_CODE (arg0) == NEGATE_EXPR && TREE_CODE (arg1) ==
NEGATE_EXPR)
*************** fold (expr)
*** 5622,5628 ****
/* In IEEE floating point, x/1 is not equivalent to x for
snans. */
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_onep (arg1))
! return non_lvalue (convert (type, arg0));
/* If ARG1 is a constant, we can convert this to a multiply by
the
reciprocal. This does not have the same rounding properties,
--- 5808,5818 ----
/* In IEEE floating point, x/1 is not equivalent to x for
snans. */
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_onep (arg1))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* If ARG1 is a constant, we can convert this to a multiply by
the
reciprocal. This does not have the same rounding properties,
*************** fold (expr)
*** 5672,5680 ****
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 arg0 is a multiple of arg1, then rewrite to the fastest
div
operation, EXACT_DIV_EXPR.
--- 5862,5877 ----
case CEIL_DIV_EXPR:
case EXACT_DIV_EXPR:
if (integer_onep (arg1))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
if (integer_zerop (arg1))
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
/* If arg0 is a multiple of arg1, then rewrite to the fastest
div
operation, EXACT_DIV_EXPR.
*************** fold (expr)
*** 5689,5695 ****
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (TREE_OPERAND (t, 0), arg1,
code, NULL_TREE)))
! return convert (type, tem);
goto binary;
--- 5886,5896 ----
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (TREE_OPERAND (t, 0), arg1,
code, NULL_TREE)))
! {
! t = convert (type, tem);
! TREE_FOLDED (t) = 1;
! return t;
! }
goto binary;
*************** fold (expr)
*** 5698,5711 ****
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;
--- 5899,5923 ----
case ROUND_MOD_EXPR:
case TRUNC_MOD_EXPR:
if (integer_onep (arg1))
! {
! t = omit_one_operand (type, integer_zero_node, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
if (integer_zerop (arg1))
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (TREE_OPERAND (t, 0), arg1,
code, NULL_TREE)))
! {
! t = convert (type, tem);
! TREE_FOLDED (t) = 1;
! return t;
! }
goto binary;
*************** fold (expr)
*** 5714,5724 ****
case LROTATE_EXPR:
case RROTATE_EXPR:
if (integer_zerop (arg1))
! return non_lvalue (convert (type, arg0));
/* Since negative shift count is not well-defined,
don't try to compute it in the compiler. */
if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_sgn (arg1)
< 0)
! return t;
/* Rewrite an LROTATE_EXPR by a constant into an
RROTATE_EXPR by a new constant. */
if (code == LROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST)
--- 5926,5943 ----
case LROTATE_EXPR:
case RROTATE_EXPR:
if (integer_zerop (arg1))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Since negative shift count is not well-defined,
don't try to compute it in the compiler. */
if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_sgn (arg1)
< 0)
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Rewrite an LROTATE_EXPR by a constant into an
RROTATE_EXPR by a new constant. */
if (code == LROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST)
*************** fold (expr)
*** 5732,5738 ****
build_int_2 (GET_MODE_BITSIZE (TYPE_MODE
(type)), 0)),
arg1, 0);
if (tree_int_cst_sgn (arg1) < 0)
! return t;
}
/* If we have a rotate of a bit operation with the rotate count
and
--- 5951,5960 ----
build_int_2 (GET_MODE_BITSIZE (TYPE_MODE
(type)), 0)),
arg1, 0);
if (tree_int_cst_sgn (arg1) < 0)
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
}
/* If we have a rotate of a bit operation with the rotate count
and
*************** fold (expr)
*** 5766,5784 ****
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:
--- 5988,6022 ----
case MIN_EXPR:
if (operand_equal_p (arg0, arg1, 0))
! {
! t = omit_one_operand (type, arg0, arg1);
! TREE_FOLDED (t) = 1;
! return t;
! }
if (INTEGRAL_TYPE_P (type)
&& operand_equal_p (arg1, TYPE_MIN_VALUE (type), 1))
! {
! t = omit_one_operand (type, arg1, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
goto associate;
case MAX_EXPR:
if (operand_equal_p (arg0, arg1, 0))
! {
! t = omit_one_operand (type, arg0, arg1);
! TREE_FOLDED (t) = 1;
! return t;
! }
if (INTEGRAL_TYPE_P (type)
&& TYPE_MAX_VALUE (type)
&& operand_equal_p (arg1, TYPE_MAX_VALUE (type), 1))
! {
! t = omit_one_operand (type, arg1, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
goto associate;
case TRUTH_NOT_EXPR:
*************** fold (expr)
*** 5789,5796 ****
tem = invert_truthvalue (arg0);
/* Avoid infinite recursion. */
if (TREE_CODE (tem) == TRUTH_NOT_EXPR)
! return t;
! return convert (type, tem);
case TRUTH_ANDIF_EXPR:
/* Note that the operands of this must be ints
--- 6027,6039 ----
tem = invert_truthvalue (arg0);
/* Avoid infinite recursion. */
if (TREE_CODE (tem) == TRUTH_NOT_EXPR)
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
! t = convert (type, tem);
! TREE_FOLDED (t) = 1;
! return t;
case TRUTH_ANDIF_EXPR:
/* Note that the operands of this must be ints
*************** fold (expr)
*** 5798,5825 ****
("true" is a fixed value perhaps depending on the language.)
*/
/* If first arg is constant zero, return it. */
if (integer_zerop (arg0))
! return convert (type, arg0);
case TRUTH_AND_EXPR:
/* If either arg is constant true, drop it. */
if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
! return non_lvalue (convert (type, arg1));
if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1)
/* Preserve sequence points. */
&& (code != TRUTH_ANDIF_EXPR || ! TREE_SIDE_EFFECTS (arg0)))
! return non_lvalue (convert (type, arg0));
/* If second arg is constant zero, result is zero, but first arg
must be evaluated. */
if (integer_zerop (arg1))
! return omit_one_operand (type, arg1, arg0);
/* Likewise for first arg, but note that only the TRUTH_AND_EXPR
case will be handled here. */
if (integer_zerop (arg0))
! return omit_one_operand (type, arg0, arg1);
truth_andor:
/* We only do these simplifications if we are optimizing. */
if (!optimize)
! return t;
/* Check for things like (A || B) && (A || C). We can convert
this
to A || (B && C). Note that either operator can be any of the
four
--- 6041,6091 ----
("true" is a fixed value perhaps depending on the language.)
*/
/* If first arg is constant zero, return it. */
if (integer_zerop (arg0))
! {
! t = convert (type, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
case TRUTH_AND_EXPR:
/* If either arg is constant true, drop it. */
if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
! {
! t = non_lvalue (convert (type, arg1));
! TREE_FOLDED (t) = 1;
! return t;
! }
if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1)
/* Preserve sequence points. */
&& (code != TRUTH_ANDIF_EXPR || ! TREE_SIDE_EFFECTS (arg0)))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* If second arg is constant zero, result is zero, but first arg
must be evaluated. */
if (integer_zerop (arg1))
! {
! t = omit_one_operand (type, arg1, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Likewise for first arg, but note that only the TRUTH_AND_EXPR
case will be handled here. */
if (integer_zerop (arg0))
! {
! t = omit_one_operand (type, arg0, arg1);
! TREE_FOLDED (t) = 1;
! return t;
! }
truth_andor:
/* We only do these simplifications if we are optimizing. */
if (!optimize)
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Check for things like (A || B) && (A || C). We can convert
this
to A || (B && C). Note that either operator can be any of the
four
*************** fold (expr)
*** 5865,5871 ****
/* See if we can build a range comparison. */
if (0 != (tem = fold_range_test (t)))
! return tem;
/* Check for the possibility of merging component references.
If our
lhs is another similar operation, try to merge its rhs with our
--- 6131,6140 ----
/* See if we can build a range comparison. */
if (0 != (tem = fold_range_test (t)))
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Check for the possibility of merging component references.
If our
lhs is another similar operation, try to merge its rhs with our
*************** fold (expr)
*** 5876,5883 ****
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:
--- 6145,6157 ----
return fold (build (code, type, TREE_OPERAND (arg0, 0), tem));
if ((tem = fold_truthop (code, type, arg0, arg1)) != 0)
! {
! t = tem;
! TREE_FOLDED (t) = 1;
! return t;
! }
+ TREE_FOLDED (t) = 1;
return t;
case TRUTH_ORIF_EXPR:
*************** fold (expr)
*** 5886,5921 ****
("true" is a fixed value perhaps depending on the language.)
*/
/* If first arg is constant true, return it. */
if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
! return convert (type, arg0);
case TRUTH_OR_EXPR:
/* If either arg is constant zero, drop it. */
if (TREE_CODE (arg0) == INTEGER_CST && integer_zerop (arg0))
! return non_lvalue (convert (type, arg1));
if (TREE_CODE (arg1) == INTEGER_CST && integer_zerop (arg1)
/* Preserve sequence points. */
&& (code != TRUTH_ORIF_EXPR || ! TREE_SIDE_EFFECTS (arg0)))
! return non_lvalue (convert (type, arg0));
/* If second arg is constant true, result is true, but we must
evaluate first arg. */
if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1))
! return omit_one_operand (type, arg1, arg0);
/* Likewise for first arg, but note this only occurs here for
TRUTH_OR_EXPR. */
if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
! return omit_one_operand (type, arg0, arg1);
goto truth_andor;
case TRUTH_XOR_EXPR:
/* If either arg is constant zero, drop it. */
if (integer_zerop (arg0))
! return non_lvalue (convert (type, arg1));
if (integer_zerop (arg1))
! return non_lvalue (convert (type, arg0));
/* If either arg is constant true, this is a logical inversion.
*/
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:
--- 6160,6232 ----
("true" is a fixed value perhaps depending on the language.)
*/
/* If first arg is constant true, return it. */
if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
! {
! t = convert (type, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
case TRUTH_OR_EXPR:
/* If either arg is constant zero, drop it. */
if (TREE_CODE (arg0) == INTEGER_CST && integer_zerop (arg0))
! {
! t = non_lvalue (convert (type, arg1));
! TREE_FOLDED (t) = 1;
! return t;
! }
if (TREE_CODE (arg1) == INTEGER_CST && integer_zerop (arg1)
/* Preserve sequence points. */
&& (code != TRUTH_ORIF_EXPR || ! TREE_SIDE_EFFECTS (arg0)))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* If second arg is constant true, result is true, but we must
evaluate first arg. */
if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1))
! {
! t = omit_one_operand (type, arg1, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Likewise for first arg, but note this only occurs here for
TRUTH_OR_EXPR. */
if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
! {
! t = omit_one_operand (type, arg0, arg1);
! TREE_FOLDED (t) = 1;
! return t;
! }
goto truth_andor;
case TRUTH_XOR_EXPR:
/* If either arg is constant zero, drop it. */
if (integer_zerop (arg0))
! {
! t = non_lvalue (convert (type, arg1));
! TREE_FOLDED (t) = 1;
! return t;
! }
if (integer_zerop (arg1))
! {
! t = non_lvalue (convert (type, arg0));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* If either arg is constant true, this is a logical inversion.
*/
if (integer_onep (arg0))
! {
! t = non_lvalue (convert (type, invert_truthvalue (arg1)));
! TREE_FOLDED (t) = 1;
! return t;
! }
if (integer_onep (arg1))
! {
! t = non_lvalue (convert (type, invert_truthvalue (arg0)));
! TREE_FOLDED (t) = 1;
! return t;
! }
! TREE_FOLDED (t) = 1;
return t;
case EQ_EXPR:
*************** fold (expr)
*** 5947,5964 ****
TREE_OPERAND (arg0, 0)));
/* (-a) CMP CST -> a swap(CMP) (-CST) */
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)))));
/* IEEE doesn't distinguish +0 and -0 in comparisons. */
/* a CMP (-0) -> a CMP 0 */
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 this is a comparison of a real constant with a PLUS_EXPR
or a MINUS_EXPR of a real constant, we can convert it into
a
--- 6258,6282 ----
TREE_OPERAND (arg0, 0)));
/* (-a) CMP CST -> a swap(CMP) (-CST) */
if (TREE_CODE (arg0) == NEGATE_EXPR && TREE_CODE (arg1) ==
REAL_CST)
! {
! t = fold (build
! (swap_tree_comparison (code), type,
! TREE_OPERAND (arg0, 0),
! build_real (TREE_TYPE (arg1),
! REAL_VALUE_NEGATE (TREE_REAL_CST
(arg1)))));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* IEEE doesn't distinguish +0 and -0 in comparisons. */
/* a CMP (-0) -> a CMP 0 */
if (TREE_CODE (arg1) == REAL_CST
&& REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (arg1)))
! {
! t = fold (build (code, type, arg0,
build_real (TREE_TYPE (arg1),
dconst0)));
+ TREE_FOLDED (t) = 1;
+ return t;
+ }
/* If this is a comparison of a real constant with a PLUS_EXPR
or a MINUS_EXPR of a real constant, we can convert it into
a
*************** fold (expr)
*** 5973,5979 ****
? MINUS_EXPR : PLUS_EXPR,
arg1, TREE_OPERAND (arg0, 1),
0))
&& ! TREE_CONSTANT_OVERFLOW (tem))
! return fold (build (code, type, TREE_OPERAND (arg0, 0),
tem));
}
/* Convert foo++ == CONST into ++foo == CONST + INCR.
--- 6291,6301 ----
? MINUS_EXPR : PLUS_EXPR,
arg1, TREE_OPERAND (arg0, 1),
0))
&& ! TREE_CONSTANT_OVERFLOW (tem))
! {
! t = fold (build (code, type, TREE_OPERAND (arg0, 0),
tem));
! TREE_FOLDED (t) = 1;
! return t;
! }
}
/* Convert foo++ == CONST into ++foo == CONST + INCR.
*************** fold (expr)
*** 6037,6043 ****
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);
--- 6359,6369 ----
constop));
if (integer_zerop (folded_compare)
|| integer_onep (folded_compare))
! {
! t = omit_one_operand (type, folded_compare,
varop);
! TREE_FOLDED (t) = 1;
! return t;
! }
unsigned_type =
(*lang_hooks.types.type_for_size)(size, 1);
precision = TYPE_PRECISION (unsigned_type);
*************** fold (expr)
*** 6055,6060 ****
--- 6381,6387 ----
t = build (code, type,
(constopnum == 0) ? newconst : varop,
(constopnum == 1) ? newconst : varop);
+ TREE_FOLDED (t) = 1;
return t;
}
}
*************** fold (expr)
*** 6098,6104 ****
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);
--- 6425,6435 ----
constop));
if (integer_zerop (folded_compare)
|| integer_onep (folded_compare))
! {
! t = omit_one_operand (type, folded_compare,
varop);
! TREE_FOLDED (t) = 1;
! return t;
! }
unsigned_type =
(*lang_hooks.types.type_for_size)(size, 1);
precision = TYPE_PRECISION (unsigned_type);
*************** fold (expr)
*** 6116,6121 ****
--- 6447,6453 ----
t = build (code, type,
(constopnum == 0) ? newconst : varop,
(constopnum == 1) ? newconst : varop);
+ TREE_FOLDED (t) = 1;
return t;
}
}
*************** fold (expr)
*** 6179,6195 ****
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);
--- 6511,6535 ----
switch (code)
{
case GT_EXPR:
! {
! t = omit_one_operand (type,
! convert (type,
integer_zero_node),
! arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
case GE_EXPR:
code = EQ_EXPR;
TREE_SET_CODE (t, EQ_EXPR);
break;
case LE_EXPR:
! {
! t = omit_one_operand (type,
! convert (type,
integer_one_node),
! arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
case LT_EXPR:
code = NE_EXPR;
TREE_SET_CODE (t, NE_EXPR);
*************** fold (expr)
*** 6223,6240 ****
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);
--- 6563,6588 ----
switch (code)
{
case LT_EXPR:
! {
! t = omit_one_operand (type,
! convert (type,
integer_zero_node),
! arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
case LE_EXPR:
code = EQ_EXPR;
TREE_SET_CODE (t, EQ_EXPR);
break;
case GE_EXPR:
! {
! t = omit_one_operand (type,
! convert (type,
integer_one_node),
! arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
case GT_EXPR:
code = NE_EXPR;
TREE_SET_CODE (t, NE_EXPR);
*************** fold (expr)
*** 6331,6337 ****
&& (TREE_CODE (arg0) == MIN_EXPR
|| TREE_CODE (arg0) == MAX_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
! return optimize_minmax_comparison (t);
/* If we are comparing an ABS_EXPR with a constant, we can
convert all the cases into explicit comparisons, but they may
--- 6679,6689 ----
&& (TREE_CODE (arg0) == MIN_EXPR
|| TREE_CODE (arg0) == MAX_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
! {
! t = optimize_minmax_comparison (t);
! TREE_FOLDED (t) = 1;
! return t;
! }
/* If we are comparing an ABS_EXPR with a constant, we can
convert all the cases into explicit comparisons, but they may
*************** fold (expr)
*** 6400,6406 ****
convert (newtype, TREE_OPERAND (arg0,
0)),
convert (newtype, TREE_OPERAND (arg0,
1)));
! return build (code, type, newmod, convert (newtype, arg1));
}
/* If this is an NE comparison of zero with an AND of one,
remove the
--- 6752,6760 ----
convert (newtype, TREE_OPERAND (arg0,
0)),
convert (newtype, TREE_OPERAND (arg0,
1)));
! t = build (code, type, newmod, convert (newtype, arg1));
! TREE_FOLDED (t) = 1;
! return t;
}
/* If this is an NE comparison of zero with an AND of one,
remove the
*************** fold (expr)
*** 6408,6414 ****
if (code == NE_EXPR && integer_zerop (arg1)
&& TREE_CODE (arg0) == BIT_AND_EXPR
&& integer_onep (TREE_OPERAND (arg0, 1)))
! return convert (type, arg0);
/* If we have (A & C) == C where C is a power of 2, convert
this into
(A & C) != 0. Similarly for NE_EXPR. */
--- 6762,6772 ----
if (code == NE_EXPR && integer_zerop (arg1)
&& TREE_CODE (arg0) == BIT_AND_EXPR
&& integer_onep (TREE_OPERAND (arg0, 1)))
! {
! t = convert (type, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
/* If we have (A & C) == C where C is a power of 2, convert
this into
(A & C) != 0. Similarly for NE_EXPR. */
*************** fold (expr)
*** 6442,6451 ****
&& 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))
--- 6800,6813 ----
&& TREE_UNSIGNED (TREE_TYPE (arg0))
&& TREE_CODE (arg1) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (arg1, 0)))
! {
! t = 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));
! TREE_FOLDED (t) = 1;
! return t;
! }
else if ((code == LT_EXPR || code == GE_EXPR)
&& TREE_UNSIGNED (TREE_TYPE (arg0))
*************** fold (expr)
*** 6453,6464 ****
|| 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));
/* Simplify comparison of something with itself. (For IEEE
floating-point, we can only do some of these simplifications.)
*/
--- 6815,6829 ----
|| TREE_CODE (arg1) == CONVERT_EXPR)
&& TREE_CODE (TREE_OPERAND (arg1, 0)) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (TREE_OPERAND (arg1, 0),
0)))
! {
! t = 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));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Simplify comparison of something with itself. (For IEEE
floating-point, we can only do some of these simplifications.)
*/
*************** fold (expr)
*** 6470,6476 ****
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;
--- 6835,6845 ----
case GE_EXPR:
case LE_EXPR:
if (! FLOAT_TYPE_P (TREE_TYPE (arg0)))
! {
! t = constant_boolean_node (1, type);
! TREE_FOLDED (t) = 1;
! return t;
! }
code = EQ_EXPR;
TREE_SET_CODE (t, code);
break;
*************** fold (expr)
*** 6482,6488 ****
/* ... fall through ... */
case GT_EXPR:
case LT_EXPR:
! return constant_boolean_node (0, type);
default:
abort ();
}
--- 6851,6861 ----
/* ... fall through ... */
case GT_EXPR:
case LT_EXPR:
! {
! t = constant_boolean_node (0, type);
! TREE_FOLDED (t) = 1;
! return t;
! }
default:
abort ();
}
*************** fold (expr)
*** 6556,6562 ****
{
case 0:
/* Always false. */
! return omit_one_operand (type, integer_zero_node,
arg0);
case 1:
code = LT_EXPR;
break;
--- 6929,6939 ----
{
case 0:
/* Always false. */
! {
! t = omit_one_operand (type, integer_zero_node,
arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
case 1:
code = LT_EXPR;
break;
*************** fold (expr)
*** 6577,6588 ****
break;
case 7:
/* Always true. */
! 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);
}
--- 6954,6971 ----
break;
case 7:
/* Always true. */
! t = omit_one_operand (type, integer_one_node,
arg0);
! TREE_FOLDED (t) = 1;
! return t;
}
t = build (code, type, cval1, cval2);
if (save_p)
! {
! t = save_expr (t);
! TREE_FOLDED (t) = 1;
! return t;
! }
else
return fold (t);
}
*************** fold (expr)
*** 6598,6604 ****
&& (optimize || TREE_CODE (arg1) == INTEGER_CST))
{
t1 = optimize_bit_field_compare (code, type, arg0, arg1);
! return t1 ? t1 : t;
}
/* If this is a comparison of complex values and either or both
sides
--- 6981,6989 ----
&& (optimize || TREE_CODE (arg1) == INTEGER_CST))
{
t1 = optimize_bit_field_compare (code, type, arg0, arg1);
! t = t1 ? t1 : t;
! TREE_FOLDED (t) = 1;
! return t;
}
/* If this is a comparison of complex values and either or both
sides
*************** fold (expr)
*** 6733,6756 ****
}
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:
/* Pedantic ANSI C says that a conditional expression is never
an lvalue,
so all simple results must be passed through
pedantic_non_lvalue. */
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 the second operand is zero, invert the comparison and swap
the second and third operands. Likewise if the second operand
--- 7118,7158 ----
}
if (t1 == NULL_TREE)
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
if (invert)
TREE_INT_CST_LOW (t1) ^= 1;
TREE_TYPE (t1) = type;
if (TREE_CODE (type) == BOOLEAN_TYPE)
! {
! t = (*lang_hooks.truthvalue_conversion) (t1);
! TREE_FOLDED (t) = 1;
! return t;
! }
! t = t1;
! TREE_FOLDED (t) = 1;
! return t;
case COND_EXPR:
/* Pedantic ANSI C says that a conditional expression is never
an lvalue,
so all simple results must be passed through
pedantic_non_lvalue. */
if (TREE_CODE (arg0) == INTEGER_CST)
! {
! t = pedantic_non_lvalue
! (TREE_OPERAND (t, (integer_zerop (arg0) ? 2 : 1)));
! TREE_FOLDED (t) = 1;
! return t;
! }
else if (operand_equal_p (arg1, TREE_OPERAND (expr, 2), 0))
! {
! t = pedantic_omit_one_operand (type, arg1, arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
/* If the second operand is zero, invert the comparison and swap
the second and third operands. Likewise if the second operand
*************** fold (expr)
*** 6822,6853 ****
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 ();
}
--- 7224,7266 ----
switch (comp_code)
{
case EQ_EXPR:
! {
! t = pedantic_non_lvalue
(convert (type,
negate_expr
(convert (TREE_TYPE (TREE_OPERAND (t, 1)),
arg1))));
+ TREE_FOLDED (t) = 1;
+ return t;
+ }
case NE_EXPR:
! {
! t = pedantic_non_lvalue (convert (type, arg1));
! TREE_FOLDED (t) = 1;
! return t;
! }
case GE_EXPR:
case GT_EXPR:
if (TREE_UNSIGNED (TREE_TYPE (arg1)))
arg1 = convert ((*lang_hooks.types.signed_type)
(TREE_TYPE (arg1)), arg1);
! t = pedantic_non_lvalue
(convert (type, fold (build1 (ABS_EXPR,
TREE_TYPE (arg1),
arg1))));
+ TREE_FOLDED (t) = 1;
+ return t;
case LE_EXPR:
case LT_EXPR:
if (TREE_UNSIGNED (TREE_TYPE (arg1)))
arg1 = convert ((lang_hooks.types.signed_type)
(TREE_TYPE (arg1)), arg1);
! t = pedantic_non_lvalue
(negate_expr (convert (type,
fold (build1 (ABS_EXPR,
TREE_TYPE (arg1),
arg1)))));
+ TREE_FOLDED (t) = 1;
+ return t;
default:
abort ();
}
*************** fold (expr)
*** 6860,6868 ****
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));
}
/* Try some transformations of A op B ? A : B.
--- 7273,7289 ----
if (integer_zerop (TREE_OPERAND (arg0, 1)) && integer_zerop
(arg2))
{
if (comp_code == NE_EXPR)
! {
! t = pedantic_non_lvalue (convert (type, arg1));
! TREE_FOLDED (t) = 1;
! return t;
! }
else if (comp_code == EQ_EXPR)
! {
! t = pedantic_non_lvalue (convert (type,
integer_zero_node));
! TREE_FOLDED (t) = 1;
! return t;
! }
}
/* Try some transformations of A op B ? A : B.
*************** fold (expr)
*** 6905,6913 ****
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:
/* In C++ a ?: expression can be an lvalue, so put the
--- 7326,7342 ----
switch (comp_code)
{
case EQ_EXPR:
! {
! t = pedantic_non_lvalue (convert (type, arg2));
! TREE_FOLDED (t) = 1;
! return t;
! }
case NE_EXPR:
! {
! t = pedantic_non_lvalue (convert (type, arg1));
! TREE_FOLDED (t) = 1;
! return t;
! }
case LE_EXPR:
case LT_EXPR:
/* In C++ a ?: expression can be an lvalue, so put the
*************** fold (expr)
*** 6915,6936 ****
so that we can convert this back to the
corresponding COND_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 ();
--- 7344,7373 ----
so that we can convert this back to the
corresponding COND_EXPR. */
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1))))
! {
! t = 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)))));
! TREE_FOLDED (t) = 1;
! return t;
! }
break;
case GE_EXPR:
case GT_EXPR:
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1))))
! {
! t = 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)))));
! TREE_FOLDED (t) = 1;
! return t;
! }
break;
default:
abort ();
*************** fold (expr)
*** 6961,6968 ****
&& 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:
--- 7398,7409 ----
&& operand_equal_p (TREE_OPERAND (arg0, 1),
const_binop (PLUS_EXPR, arg2,
integer_one_node,
0), 1))
! {
! t = pedantic_non_lvalue
! (fold (build (MIN_EXPR, type, arg1, arg2)));
! TREE_FOLDED (t) = 1;
! return t;
! }
break;
case LE_EXPR:
*************** fold (expr)
*** 6971,6978 ****
&& 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:
--- 7412,7423 ----
&& operand_equal_p (TREE_OPERAND (arg0, 1),
const_binop (MINUS_EXPR, arg2,
integer_one_node,
0), 1))
! {
! t = pedantic_non_lvalue
! (fold (build (MIN_EXPR, type, arg1, arg2)));
! TREE_FOLDED (t) = 1;
! return t;
! }
break;
case GT_EXPR:
*************** fold (expr)
*** 6981,6988 ****
&& 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:
--- 7426,7437 ----
&& operand_equal_p (TREE_OPERAND (arg0, 1),
const_binop (MINUS_EXPR, arg2,
integer_one_node,
0), 1))
! {
! t = pedantic_non_lvalue
! (fold (build (MAX_EXPR, type, arg1, arg2)));
! TREE_FOLDED (t) = 1;
! return t;
! }
break;
case GE_EXPR:
*************** fold (expr)
*** 6991,6998 ****
&& 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;
--- 7440,7451 ----
&& operand_equal_p (TREE_OPERAND (arg0, 1),
const_binop (PLUS_EXPR, arg2,
integer_one_node,
0), 1))
! {
! t = pedantic_non_lvalue
! (fold (build (MAX_EXPR, type, arg1, arg2)));
! TREE_FOLDED (t) = 1;
! return t;
! }
break;
case NE_EXPR:
break;
*************** fold (expr)
*** 7033,7047 ****
a COND, which will recurse. In that case, the COND_EXPR
is probably the best choice, so leave it alone. */
&& type == TREE_TYPE (arg0))
! return pedantic_non_lvalue (arg0);
/* Convert A ? 0 : 1 to !A. This prefers the use of NOT_EXPR
over COND_EXPR in cases such as floating point comparisons. */
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)));
/* Look for expressions of the form A & 2 ? 2 : 0. The result
of this
operation is simply A & 2. */
--- 7486,7508 ----
a COND, which will recurse. In that case, the COND_EXPR
is probably the best choice, so leave it alone. */
&& type == TREE_TYPE (arg0))
! {
! t = pedantic_non_lvalue (arg0);
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Convert A ? 0 : 1 to !A. This prefers the use of NOT_EXPR
over COND_EXPR in cases such as floating point comparisons. */
if (integer_zerop (TREE_OPERAND (t, 1))
&& integer_onep (TREE_OPERAND (t, 2))
&& truth_value_p (TREE_CODE (arg0)))
! {
! t = pedantic_non_lvalue (convert (type,
! invert_truthvalue (arg0)));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Look for expressions of the form A & 2 ? 2 : 0. The result
of this
operation is simply A & 2. */
*************** fold (expr)
*** 7053,7066 ****
&& 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)));
/* Convert A ? B : 0 into A && B if A and B are truth values.
*/
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)));
/* Convert A ? B : 1 into !A || B if A and B are truth values.
*/
if (integer_onep (TREE_OPERAND (t, 2))
--- 7514,7535 ----
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == BIT_AND_EXPR
&& operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1),
arg1, 1))
! {
! t = pedantic_non_lvalue (convert (type, TREE_OPERAND (arg0,
0)));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Convert A ? B : 0 into A && B if A and B are truth values.
*/
if (integer_zerop (TREE_OPERAND (t, 2))
&& truth_value_p (TREE_CODE (arg0))
&& truth_value_p (TREE_CODE (arg1)))
! {
! t = pedantic_non_lvalue (fold (build (TRUTH_ANDIF_EXPR, type,
! arg0, arg1)));
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Convert A ? B : 1 into !A || B if A and B are truth values.
*/
if (integer_onep (TREE_OPERAND (t, 2))
*************** fold (expr)
*** 7070,7102 ****
/* Only perform transformation if ARG0 is easily inverted. */
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:
/* When pedantic, a compound expression can be neither an lvalue
nor an integer constant expression. */
if (TREE_SIDE_EFFECTS (arg0) || pedantic)
! return t;
/* Don't let (0, 0) be null pointer constant. */
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)
--- 7539,7595 ----
/* Only perform transformation if ARG0 is easily inverted. */
tem = invert_truthvalue (arg0);
if (TREE_CODE (tem) != TRUTH_NOT_EXPR)
! {
! t = pedantic_non_lvalue (fold (build (TRUTH_ORIF_EXPR,
type,
! tem, arg1)));
! TREE_FOLDED (t) = 1;
! return t;
! }
}
+ TREE_FOLDED (t) = 1;
return t;
case COMPOUND_EXPR:
/* When pedantic, a compound expression can be neither an lvalue
nor an integer constant expression. */
if (TREE_SIDE_EFFECTS (arg0) || pedantic)
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
/* Don't let (0, 0) be null pointer constant. */
if (integer_zerop (arg1))
! {
! t = build1 (NOP_EXPR, type, arg1);
! TREE_FOLDED (t) = 1;
! return t;
! }
! t = convert (type, arg1);
! TREE_FOLDED (t) = 1;
! return t;
case COMPLEX_EXPR:
if (wins)
! {
! t = build_complex (type, arg0, arg1);
! }
! TREE_FOLDED (t) = 1;
return t;
case REALPART_EXPR:
if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
! {
! TREE_FOLDED (t) = 1;
! return t;
! }
else if (TREE_CODE (arg0) == COMPLEX_EXPR)
! {
! t = omit_one_operand (type, TREE_OPERAND (arg0, 0),
! TREE_OPERAND (arg0, 1));
! TREE_FOLDED (t) = 1;
! return t;
! }
else if (TREE_CODE (arg0) == COMPLEX_CST)
return TREE_REALPART (arg0);
else if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) ==
MINUS_EXPR)
*************** fold (expr)
*** 7105,7118 ****
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)
--- 7598,7620 ----
TREE_OPERAND (arg0, 0))),
fold (build1 (REALPART_EXPR,
type, TREE_OPERAND (arg0,
1)))));
+ TREE_FOLDED (t) = 1;
return t;
case IMAGPART_EXPR:
if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
! {
! t = convert (type, integer_zero_node);
! TREE_FOLDED (t) = 1;
! return t;
! }
else if (TREE_CODE (arg0) == COMPLEX_EXPR)
! {
! t = omit_one_operand (type, TREE_OPERAND (arg0, 1),
! TREE_OPERAND (arg0, 0));
! TREE_FOLDED (t) = 1;
! return t;
! }
else if (TREE_CODE (arg0) == COMPLEX_CST)
return TREE_IMAGPART (arg0);
else if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) ==
MINUS_EXPR)
*************** fold (expr)
*** 7121,7126 ****
--- 7623,7629 ----
TREE_OPERAND (arg0, 0))),
fold (build1 (IMAGPART_EXPR, type,
TREE_OPERAND (arg0, 1)))));
+ TREE_FOLDED (t) = 1;
return t;
/* Pull arithmetic ops out of the CLEANUP_POINT_EXPR where
*************** fold (expr)
*** 7161,7166 ****
--- 7664,7670 ----
arg01));
}
+ TREE_FOLDED (t) = 1;
return t;
}
*************** fold (expr)
*** 7173,7183 ****
{
tree tmp = fold_builtin (expr);
if (tmp)
! return tmp;
}
return t;
default:
return t;
} /* switch (code) */
}
--- 7677,7689 ----
{
tree tmp = fold_builtin (expr);
if (tmp)
! t = tmp;
}
+ TREE_FOLDED (t) = 1;
return t;
default:
+ TREE_FOLDED (t) = 1;
return t;
} /* switch (code) */
}
-----------------