This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[3.4 PATCH] Backport PR middle-end/13696 fixes (part 1/2)
- From: Roger Sayle <roger at eyesopen dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sun, 15 Feb 2004 10:30:19 -0700 (MST)
- Subject: [3.4 PATCH] Backport PR middle-end/13696 fixes (part 1/2)
Hi Mark,
I'd like permission to backport the following four patches from
mainline to the gcc-3_4-branch to resolve PR middle-end/13696 which
is an ICE on legal targeted for 3.4. These four patches have been
on mainline for a while without any further problems.
Backport from mainline:
2004-01-20 Roger Sayle <roger@eyesopen.com>
* fold-const.c (fold_convert): Rename to fold_convert_const.
(fold_convert_const): Change arguments to take a tree_code,
a type and the operand/expression to be converted. Return
NULL_TREE if no simplification is possible.
(fold): Adjust call to fold_convert to match new fold_convert_const.
Avoid modifying the tree based to fold in-place.
2004-02-07 Roger Sayle <roger@eyesopen.com>
PR middle-end/13696
* fold-const.c (fold_convert): New function to provide type
conversion to the middle-end without using convert.
(negate_expr, associate_trees, size_diffop, omit_one_operand,
operand_equal_for_comparison_p, pedantic_omit_one_operand,
invert_truthvalue, optimize_bit_field_compare, range_binop,
decode_field_reference, make_range, build_range_check, unextend,
fold_truthop, extract_muldiv_1, fold_mathfn_compare,
fold_binary_op_with_conditional_arg, fold_inf_compare,
fold_single_bit_test, fold, multiple_of_p): Replace all calls to
convert with calls to fold_convert.
2004-02-09 Roger Sayle <roger@eyesopen.com>
* fold-const.c (fold) <NOP_EXPR>: Use the original type conversion
tree code rather than call fold_convert, which doesn't specify a
default floating point to integer conversion.
2004-02-10 Paolo Bonzini <bonzini@gnu.org>
PR c/14092
* fold-const.c (fold) <NEGATE_EXPR>: Convert result of
negate_expr back to the original type.
The first is a pre-requisite clean-up, the second is the main PR fix,
and the remaining two are related latent bug fixes. Both of these last
two bugs already exist on 3.4, the first was exposed by the second patch
and the other by unrelated changes on mainline. However, I'd prefer to
include Paolo's patch in this set and address all known "fold conversion"
issues at the same time (rather than discover that we've introduced a
regression by exposing it with the first three patches).
The original patches were discussed here:
http://gcc.gnu.org/ml/gcc-patches/2004-01/msg01951.html
http://gcc.gnu.org/ml/gcc-patches/2004-01/msg02694.html
http://gcc.gnu.org/ml/gcc-patches/2004-02/msg00804.html
http://gcc.gnu.org/ml/gcc-patches/2004-02/msg00916.html
To simplify regression hunting, I'd like to apply these patches in two
independent commits. The first the required clean-ups, and the second
the remaining bug fixes and mechanical changes.
The first part, below, has been tested against the gcc-3_4-branch on
i686-pc-linux-gnu with a full "make bootstrap", all languages except
treelang, and regression tested with a top-level "make -k check" with
no new failures.
Ok for 3.4? Pre-approval for part 2?
2004-02-15 Roger Sayle <roger@eyesopen.com>
Backport from mainline:
2004-01-20 Roger Sayle <roger@eyesopen.com>
* fold-const.c (fold_convert): Rename to fold_convert_const.
(fold_convert_const): Change arguments to take a tree_code,
a type and the operand/expression to be converted. Return
NULL_TREE if no simplification is possible.
(fold): Adjust call to fold_convert to match new fold_convert_const.
Avoid modifying the tree based to fold in-place.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.322.2.2
diff -c -3 -p -r1.322.2.2 fold-const.c
*** fold-const.c 26 Jan 2004 13:01:08 -0000 1.322.2.2
--- fold-const.c 15 Feb 2004 15:32:50 -0000
*************** static tree int_const_binop (enum tree_c
*** 69,75 ****
static tree const_binop (enum tree_code, tree, tree, int);
static hashval_t size_htab_hash (const void *);
static int size_htab_eq (const void *, const void *);
! static tree fold_convert (tree, tree);
static enum tree_code invert_tree_comparison (enum tree_code);
static enum tree_code swap_tree_comparison (enum tree_code);
static int comparison_to_compcode (enum tree_code);
--- 69,75 ----
static tree const_binop (enum tree_code, tree, tree, int);
static hashval_t size_htab_hash (const void *);
static int size_htab_eq (const void *, const void *);
! static tree fold_convert_const (enum tree_code, tree, tree);
static enum tree_code invert_tree_comparison (enum tree_code);
static enum tree_code swap_tree_comparison (enum tree_code);
static int comparison_to_compcode (enum tree_code);
*************** size_diffop (tree arg0, tree arg1)
*** 1657,1670 ****
}
! /* Given T, a tree representing type conversion of ARG1, a constant,
! return a constant tree representing the result of conversion. */
static tree
! fold_convert (tree t, tree arg1)
{
- tree type = TREE_TYPE (t);
int overflow = 0;
if (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type))
{
--- 1657,1673 ----
}
! /* Attempt to fold type conversion operation CODE of expression ARG1 to
! type TYPE. If no simplification can be done return NULL_TREE. */
static tree
! fold_convert_const (enum tree_code code, tree type, tree arg1)
{
int overflow = 0;
+ tree t;
+
+ if (TREE_TYPE (arg1) == type)
+ return arg1;
if (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type))
{
*************** fold_convert (tree t, tree arg1)
*** 1673,1679 ****
/* If we would build a constant wider than GCC supports,
leave the conversion unfolded. */
if (TYPE_PRECISION (type) > 2 * HOST_BITS_PER_WIDE_INT)
! return t;
/* If we are trying to make a sizetype for a small integer, use
size_int to pick up cached types to reduce duplicate nodes. */
--- 1676,1682 ----
/* If we would build a constant wider than GCC supports,
leave the conversion unfolded. */
if (TYPE_PRECISION (type) > 2 * HOST_BITS_PER_WIDE_INT)
! return NULL_TREE;
/* If we are trying to make a sizetype for a small integer, use
size_int to pick up cached types to reduce duplicate nodes. */
*************** fold_convert (tree t, tree arg1)
*** 1701,1706 ****
--- 1704,1710 ----
|| TREE_OVERFLOW (arg1));
TREE_CONSTANT_OVERFLOW (t)
= TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg1);
+ return t;
}
else if (TREE_CODE (arg1) == REAL_CST)
{
*************** fold_convert (tree t, tree arg1)
*** 1766,1773 ****
= 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)
{
--- 1770,1777 ----
= TREE_OVERFLOW (arg1) | force_fit_type (t, overflow);
TREE_CONSTANT_OVERFLOW (t)
= TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg1);
+ return t;
}
}
else if (TREE_CODE (type) == REAL_TYPE)
{
*************** fold_convert (tree t, tree arg1)
*** 1795,1802 ****
return t;
}
}
! TREE_CONSTANT (t) = 1;
! return t;
}
/* Return an expr equal to X but certainly not valid as an lvalue. */
--- 1799,1805 ----
return t;
}
}
! return NULL_TREE;
}
/* Return an expr equal to X but certainly not valid as an lvalue. */
*************** fold (tree expr)
*** 5583,5599 ****
convert (TREE_TYPE (t), and1)));
}
! if (!wins)
! {
! if (TREE_CONSTANT (t) != TREE_CONSTANT (arg0))
! {
! if (t == orig_t)
! t = copy_node (t);
! 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)
--- 5586,5593 ----
convert (TREE_TYPE (t), and1)));
}
! tem = fold_convert_const (code, TREE_TYPE (t), arg0);
! return tem ? tem : t;
case VIEW_CONVERT_EXPR:
if (TREE_CODE (TREE_OPERAND (t, 0)) == VIEW_CONVERT_EXPR)
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833