aboutsummaryrefslogtreecommitdiff
path: root/gcc/cse.c
diff options
context:
space:
mode:
authorAndrew Jenner <andrew@codesourcery.com>2012-07-26 20:51:24 +0000
committerSandra Loosemore <sandra@codesourcery.com>2012-07-26 20:51:24 +0000
commit3f1e89dfad969d073fb8c4ed04ec75acfa74e89f (patch)
tree23ce5234684b58ad1898974a03acd1eb8d8d4723 /gcc/cse.c
parent4a2ca54fd8f83781b0e38935777266509df31713 (diff)
2012-07-26 Andrew Jenner <andrew@codesourcery.com>
Sandra Loosemore <sandra@codesourcery.com> gcc/ * cse.c (find_comparison_args): Check for cycles of any length. gcc/testsuite/ * gcc.c-torture/compile/pr50380.c: Add code to cause cycle of length 2. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@189896 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cse.c')
-rw-r--r--gcc/cse.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/gcc/cse.c b/gcc/cse.c
index 9a54433c6de..a8726f3fc32 100644
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-pass.h"
#include "df.h"
#include "dbgcnt.h"
+#include "pointer-set.h"
/* The basic idea of common subexpression elimination is to go
through the code, keeping a record of expressions that would
@@ -2897,6 +2898,9 @@ find_comparison_args (enum rtx_code code, rtx *parg1, rtx *parg2,
enum machine_mode *pmode1, enum machine_mode *pmode2)
{
rtx arg1, arg2;
+ struct pointer_set_t *visited = NULL;
+ /* Set nonzero when we find something of interest. */
+ rtx x = NULL;
arg1 = *parg1, arg2 = *parg2;
@@ -2904,11 +2908,18 @@ find_comparison_args (enum rtx_code code, rtx *parg1, rtx *parg2,
while (arg2 == CONST0_RTX (GET_MODE (arg1)))
{
- /* Set nonzero when we find something of interest. */
- rtx x = 0;
int reverse_code = 0;
struct table_elt *p = 0;
+ /* Remember state from previous iteration. */
+ if (x)
+ {
+ if (!visited)
+ visited = pointer_set_create ();
+ pointer_set_insert (visited, x);
+ x = 0;
+ }
+
/* If arg1 is a COMPARE, extract the comparison arguments from it.
On machines with CC0, this is the only case that can occur, since
fold_rtx will return the COMPARE or item being compared with zero
@@ -2985,10 +2996,8 @@ find_comparison_args (enum rtx_code code, rtx *parg1, rtx *parg2,
if (! exp_equiv_p (p->exp, p->exp, 1, false))
continue;
- /* If it's the same comparison we're already looking at, skip it. */
- if (COMPARISON_P (p->exp)
- && XEXP (p->exp, 0) == arg1
- && XEXP (p->exp, 1) == arg2)
+ /* If it's a comparison we've used before, skip it. */
+ if (visited && pointer_set_contains (visited, p->exp))
continue;
if (GET_CODE (p->exp) == COMPARE
@@ -3069,6 +3078,8 @@ find_comparison_args (enum rtx_code code, rtx *parg1, rtx *parg2,
*pmode1 = GET_MODE (arg1), *pmode2 = GET_MODE (arg2);
*parg1 = fold_rtx (arg1, 0), *parg2 = fold_rtx (arg2, 0);
+ if (visited)
+ pointer_set_destroy (visited);
return code;
}