From 362cb1bb1f100075cb261248d64c7ba0cb748cec Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Sun, 13 Mar 2005 22:34:03 +0000 Subject: re PR middle-end/19331 (Inefficient code generated for bitfield assignment) PR middle-end/19331 * tree.c (get_unwidened): Treat CONVERT_EXPR and NOP_EXPR identically. * fold-const.c (fold_sign_changed_comparison): Likewise. (fold_binary): Optimize comparisons against widened operands if the extension is represented by a CONVERT_EXPR, same as a NOP_EXPR. From-SVN: r96397 --- gcc/ChangeLog | 8 ++++++++ gcc/fold-const.c | 11 +++++++---- gcc/tree.c | 7 +++++-- 3 files changed, 20 insertions(+), 6 deletions(-) (limited to 'gcc') diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2a4a78e..78f5ba5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2005-03-13 Roger Sayle + + PR middle-end/19331 + * tree.c (get_unwidened): Treat CONVERT_EXPR and NOP_EXPR identically. + * fold-const.c (fold_sign_changed_comparison): Likewise. + (fold_binary): Optimize comparisons against widened operands if + the extension is represented by a CONVERT_EXPR, same as a NOP_EXPR. + 2005-03-14 Eric Botcazou * config/sparc/sparc.c (struct_value_alias_set): New global variable. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 3fdfb92..6a00abe 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6148,7 +6148,8 @@ fold_sign_changed_comparison (enum tree_code code, tree type, tree arg0_inner, tmp; tree inner_type, outer_type; - if (TREE_CODE (arg0) != NOP_EXPR) + if (TREE_CODE (arg0) != NOP_EXPR + && TREE_CODE (arg0) != CONVERT_EXPR) return NULL_TREE; outer_type = TREE_TYPE (arg0); @@ -6159,7 +6160,8 @@ fold_sign_changed_comparison (enum tree_code code, tree type, return NULL_TREE; if (TREE_CODE (arg1) != INTEGER_CST - && !(TREE_CODE (arg1) == NOP_EXPR + && !((TREE_CODE (arg1) == NOP_EXPR + || TREE_CODE (arg1) == CONVERT_EXPR) && TREE_TYPE (TREE_OPERAND (arg1, 0)) == inner_type)) return NULL_TREE; @@ -6180,7 +6182,7 @@ fold_sign_changed_comparison (enum tree_code code, tree type, else arg1 = fold_convert (inner_type, arg1); - return fold (build (code, type, arg0_inner, arg1)); + return fold (build2 (code, type, arg0_inner, arg1)); } /* Tries to replace &a[idx] CODE s * delta with &a[idx CODE delta], if s is @@ -9150,7 +9152,8 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) TREE_OPERAND (arg0, 0), TREE_OPERAND (arg0, 1))); else if (TREE_CODE (TREE_TYPE (arg0)) == INTEGER_TYPE - && TREE_CODE (arg0) == NOP_EXPR) + && (TREE_CODE (arg0) == NOP_EXPR + || TREE_CODE (arg0) == CONVERT_EXPR)) { /* If we are widening one operand of an integer comparison, see if the other operand is similarly being widened. Perhaps we diff --git a/gcc/tree.c b/gcc/tree.c index 815ef75..0a99598 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -4729,7 +4729,8 @@ get_unwidened (tree op, tree for_type) && TYPE_UNSIGNED (type)); tree win = op; - while (TREE_CODE (op) == NOP_EXPR) + while (TREE_CODE (op) == NOP_EXPR + || TREE_CODE (op) == CONVERT_EXPR) { int bitschange = TYPE_PRECISION (TREE_TYPE (op)) @@ -4759,7 +4760,9 @@ get_unwidened (tree op, tree for_type) /* TYPE_UNSIGNED says whether this is a zero-extension. Let's avoid computing it if it does not affect WIN and if UNS will not be needed again. */ - if ((uns || TREE_CODE (op) == NOP_EXPR) + if ((uns + || TREE_CODE (op) == NOP_EXPR + || TREE_CODE (op) == CONVERT_EXPR) && TYPE_UNSIGNED (TREE_TYPE (op))) { uns = 1; -- cgit v1.1