Patchwork PATCH: fix infinite loop in CSE

login
register
mail settings
Submitter Sandra Loosemore
Date Dec. 19, 2011, 8:29 p.m.
Message ID <4EEF9EC3.8070807@codesourcery.com>
Download mbox | patch
Permalink /patch/132310/
State New
Headers show

Comments

Sandra Loosemore - Dec. 19, 2011, 8:29 p.m.
On 12/18/2011 05:21 AM, Eric Botcazou wrote:
>
> OK everywhere without the cap and with the same test on ARG2:
> If a testcase doesn't need fancy options, it must go in gcc.c-torture/compile.

OK.  I've checked in this version, which addresses both those issues.

-Sandra


2011-12-19  Sandra Loosemore  <sandra@codesourcery.com>
	    Tom de Vries <tom@codesourcery.com>

	PR rtl-opt/50380

	gcc/
	* cse.c (find_comparison_args): Detect fixed point and
	bail early.

	gcc/testsuite/
	* gcc.c-torture/compile/pr50380.c: New testcase.

Patch

Index: gcc/testsuite/gcc.c-torture/compile/pr50380.c
===================================================================
--- gcc/testsuite/gcc.c-torture/compile/pr50380.c	(revision 0)
+++ gcc/testsuite/gcc.c-torture/compile/pr50380.c	(revision 0)
@@ -0,0 +1,12 @@ 
+/* This test used to get stuck in an infinite loop in find_comparison_args
+   when compiling for MIPS at -O2.  */
+
+__attribute__ ((__noreturn__)) extern void fail (void);
+
+char x;
+
+void foo (const unsigned char y)
+{
+   ((void) (__builtin_expect((!! y == y), 1) ? 0 : (fail (), 0)));
+   x = ! y;
+}
Index: gcc/cse.c
===================================================================
--- gcc/cse.c	(revision 181994)
+++ gcc/cse.c	(working copy)
@@ -3055,6 +3055,12 @@  find_comparison_args (enum rtx_code code
 	  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)
+	    continue;
+
 	  if (GET_CODE (p->exp) == COMPARE
 	      /* Another possibility is that this machine has a compare insn
 		 that includes the comparison code.  In that case, ARG1 would