Commit 362cb1bb by Roger Sayle Committed by Roger Sayle

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
parent 334f3a34
2005-03-13 Roger Sayle <roger@eyesopen.com>
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 <ebotcazou@libertysurf.fr> 2005-03-14 Eric Botcazou <ebotcazou@libertysurf.fr>
* config/sparc/sparc.c (struct_value_alias_set): New global variable. * config/sparc/sparc.c (struct_value_alias_set): New global variable.
......
...@@ -6148,7 +6148,8 @@ fold_sign_changed_comparison (enum tree_code code, tree type, ...@@ -6148,7 +6148,8 @@ fold_sign_changed_comparison (enum tree_code code, tree type,
tree arg0_inner, tmp; tree arg0_inner, tmp;
tree inner_type, outer_type; 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; return NULL_TREE;
outer_type = TREE_TYPE (arg0); outer_type = TREE_TYPE (arg0);
...@@ -6159,7 +6160,8 @@ fold_sign_changed_comparison (enum tree_code code, tree type, ...@@ -6159,7 +6160,8 @@ fold_sign_changed_comparison (enum tree_code code, tree type,
return NULL_TREE; return NULL_TREE;
if (TREE_CODE (arg1) != INTEGER_CST 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)) && TREE_TYPE (TREE_OPERAND (arg1, 0)) == inner_type))
return NULL_TREE; return NULL_TREE;
...@@ -6180,7 +6182,7 @@ fold_sign_changed_comparison (enum tree_code code, tree type, ...@@ -6180,7 +6182,7 @@ fold_sign_changed_comparison (enum tree_code code, tree type,
else else
arg1 = fold_convert (inner_type, arg1); 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 /* 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) ...@@ -9150,7 +9152,8 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
TREE_OPERAND (arg0, 0), TREE_OPERAND (arg0, 1))); TREE_OPERAND (arg0, 0), TREE_OPERAND (arg0, 1)));
else if (TREE_CODE (TREE_TYPE (arg0)) == INTEGER_TYPE 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, /* If we are widening one operand of an integer comparison,
see if the other operand is similarly being widened. Perhaps we see if the other operand is similarly being widened. Perhaps we
......
...@@ -4729,7 +4729,8 @@ get_unwidened (tree op, tree for_type) ...@@ -4729,7 +4729,8 @@ get_unwidened (tree op, tree for_type)
&& TYPE_UNSIGNED (type)); && TYPE_UNSIGNED (type));
tree win = op; tree win = op;
while (TREE_CODE (op) == NOP_EXPR) while (TREE_CODE (op) == NOP_EXPR
|| TREE_CODE (op) == CONVERT_EXPR)
{ {
int bitschange int bitschange
= TYPE_PRECISION (TREE_TYPE (op)) = TYPE_PRECISION (TREE_TYPE (op))
...@@ -4759,7 +4760,9 @@ get_unwidened (tree op, tree for_type) ...@@ -4759,7 +4760,9 @@ get_unwidened (tree op, tree for_type)
/* TYPE_UNSIGNED says whether this is a zero-extension. /* TYPE_UNSIGNED says whether this is a zero-extension.
Let's avoid computing it if it does not affect WIN Let's avoid computing it if it does not affect WIN
and if UNS will not be needed again. */ 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))) && TYPE_UNSIGNED (TREE_TYPE (op)))
{ {
uns = 1; uns = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment