new folding rule

From-SVN: r158567
This commit is contained in:
Xinliang David Li 2010-04-20 17:00:37 +00:00
parent 54fb1ae03e
commit 94e85e0ae8
4 changed files with 63 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2010-04-20 Xinliang David Li <davidxl@gcc.gnu.org>
PR middle-end/41952
* fold-const.c (fold_comparison): New folding rule.
2010-04-20 Anatoly Sokolov <aesok@post.ru
* double-int.h (double_int_setbit): Declare.

View File

@ -8643,9 +8643,33 @@ fold_comparison (location_t loc, enum tree_code code, tree type,
offset1 = TREE_OPERAND (arg1, 1);
}
/* A local variable can never be pointed to by
the default SSA name of an incoming parameter. */
if ((TREE_CODE (arg0) == ADDR_EXPR
&& indirect_base0
&& TREE_CODE (base0) == VAR_DECL
&& auto_var_in_fn_p (base0, current_function_decl)
&& !indirect_base1
&& TREE_CODE (base1) == SSA_NAME
&& TREE_CODE (SSA_NAME_VAR (base1)) == PARM_DECL
&& SSA_NAME_IS_DEFAULT_DEF (base1))
|| (TREE_CODE (arg1) == ADDR_EXPR
&& indirect_base1
&& TREE_CODE (base1) == VAR_DECL
&& auto_var_in_fn_p (base1, current_function_decl)
&& !indirect_base0
&& TREE_CODE (base0) == SSA_NAME
&& TREE_CODE (SSA_NAME_VAR (base0)) == PARM_DECL
&& SSA_NAME_IS_DEFAULT_DEF (base0)))
{
if (code == NE_EXPR)
return constant_boolean_node (1, type);
else if (code == EQ_EXPR)
return constant_boolean_node (0, type);
}
/* If we have equivalent bases we might be able to simplify. */
if (indirect_base0 == indirect_base1
&& operand_equal_p (base0, base1, 0))
else if (indirect_base0 == indirect_base1
&& operand_equal_p (base0, base1, 0))
{
/* We can fold this expression to a constant if the non-constant
offset parts are equal. */

View File

@ -1,3 +1,7 @@
2010-04-20 Xinliang David Li <davidxl@google.com>
* g++.dg/tree-ssa/fold-compare.C: New.
2010-04-20 Richard Guenther <rguenther@suse.de>
PR tree-optimization/39417

View File

@ -0,0 +1,28 @@
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized" } */
struct ExtentsBase {
ExtentsBase() : startx_(), endx_() { }
ExtentsBase(const ExtentsBase &b) {
*this = b;
}
const ExtentsBase & operator=(const ExtentsBase &b) {
if (this != &b) {
startx_ = b.startx_;
}
return *this;
}
int startx_;
int endx_;
};
int f(const ExtentsBase &e1) {
ExtentsBase my_extents = e1;
return my_extents.startx_;
}
/* { dg-final { scan-tree-dump-not "&my_extents" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */