diff options
author | Kazu Hirata <kazu@cs.umass.edu> | 2005-04-15 18:42:38 +0000 |
---|---|---|
committer | Kazu Hirata <kazu@gcc.gnu.org> | 2005-04-15 18:42:38 +0000 |
commit | 9f1054af045a95c4116bcfce3d1486766429bc7a (patch) | |
tree | 6e55a9c5fe4cc1e5e873c3df45d21505ed4236ae /gcc | |
parent | 6ba40dd7ac0131712102aa4e31aa3e6a733f452f (diff) | |
download | gcc-9f1054af045a95c4116bcfce3d1486766429bc7a.zip gcc-9f1054af045a95c4116bcfce3d1486766429bc7a.tar.gz gcc-9f1054af045a95c4116bcfce3d1486766429bc7a.tar.bz2 |
re PR tree-optimization/21031 (Another missed forward propagation opportunity)
gcc/
PR tree-optimization/21031
* tree-ssa-forwprop.c (ssa_name_defined_by_comparison_p): New.
(forward_propagate_into_cond_1): Call it. Forward propagate
integer-integer casts into COND_EXPRs.
testsuite/
PR tree-optimization/21031
* gcc.dg/tree-ssa/pr21031.c: New.
From-SVN: r98199
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/pr21031.c | 20 | ||||
-rw-r--r-- | gcc/tree-ssa-forwprop.c | 23 |
4 files changed, 55 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f175789..2c6aa43 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2005-04-15 Kazu Hirata <kazu@cs.umass.edu> + + PR tree-optimization/21031 + * tree-ssa-forwprop.c (ssa_name_defined_by_comparison_p): New. + (forward_propagate_into_cond_1): Call it. Forward propagate + integer-integer casts into COND_EXPRs. + 2005-04-15 Dave Korn <dave.korn@artimi.com> * gcc.c (default_compilers): Clarify obscure error message when diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b2b8e97..41a3508 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-04-15 Kazu Hirata <kazu@cs.umass.edu> + + PR tree-optimization/21031 + * gcc.dg/tree-ssa/pr21031.c: New. + 2005-04-15 Uros Bizjak <uros@kss-loka.si> PR tree-optimization/21004 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr21031.c b/gcc/testsuite/gcc.dg/tree-ssa/pr21031.c new file mode 100644 index 0000000..df200d5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr21031.c @@ -0,0 +1,20 @@ +/* PR tree-optimization/21031 + + Make sure that a != 0 is propagated into the "if" statement. */ + +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1-details" } */ + +int +foo (int a) +{ + int b = a != 0; + unsigned char c = b; + if (c) + return 1; + else + return 0; +} + +/* { dg-final { scan-tree-dump-times "Replaced" 2 "forwprop1"} } */ +/* { dg-final { cleanup-tree-dump "forwprop1" } } */ diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index 75fe6e1..a47d69a 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -109,6 +109,23 @@ Boston, MA 02111-1307, USA. */ This will (of course) be extended as other needs arise. */ +/* Given an SSA_NAME VAR, return true if and only if VAR is defined by + a comparison. */ + +static bool +ssa_name_defined_by_comparison_p (tree var) +{ + tree def = SSA_NAME_DEF_STMT (var); + + if (TREE_CODE (def) == MODIFY_EXPR) + { + tree rhs = TREE_OPERAND (def, 1); + return COMPARISON_CLASS_P (rhs); + } + + return 0; +} + /* Forward propagate a single-use variable into COND once. Return a new condition if successful. Return NULL_TREE otherwise. */ @@ -303,6 +320,12 @@ forward_propagate_into_cond_1 (tree cond, tree *test_var_p) || (TREE_CODE (inner_type) == BOOLEAN_TYPE && INTEGRAL_TYPE_P (outer_type))) ; + else if (INTEGRAL_TYPE_P (outer_type) + && INTEGRAL_TYPE_P (inner_type) + && TREE_CODE (TREE_OPERAND (def_rhs, 0)) == SSA_NAME + && ssa_name_defined_by_comparison_p (TREE_OPERAND (def_rhs, + 0))) + ; else return NULL_TREE; |