]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR rtl-optimization/49720 (Infinite recursion compiling gold binary_test.cc testcase)
authorChung-Lin Tang <cltang@codesourcery.com>
Fri, 28 Oct 2011 06:35:31 +0000 (06:35 +0000)
committerChung-Lin Tang <cltang@gcc.gnu.org>
Fri, 28 Oct 2011 06:35:31 +0000 (06:35 +0000)
2011-10-28  Chung-Lin Tang  <cltang@codesourcery.com>

PR rtl-optimization/49720
* simplify-rtx.c (simplify_relational_operation_1): Detect
infinite recursion condition in "(eq/ne (plus x cst1) cst2)
simplifies to (eq/ne x (cst2 - cst1))" case.

testsuite/
* g++.dg/torture/pr49720.C: New test.

From-SVN: r180604

gcc/ChangeLog
gcc/simplify-rtx.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/torture/pr49720.C [new file with mode: 0644]

index 420e188b91edc373e52a29dc1946005405373a91..61320f852ab756dc66cb489ecb199eabd6819095 100644 (file)
@@ -1,3 +1,10 @@
+2011-10-28  Chung-Lin Tang  <cltang@codesourcery.com>
+
+       PR rtl-optimization/49720
+       * simplify-rtx.c (simplify_relational_operation_1): Detect
+       infinite recursion condition in "(eq/ne (plus x cst1) cst2)
+       simplifies to (eq/ne x (cst2 - cst1))" case.
+
 2011-10-27  David S. Miller  <davem@davemloft.net>
 
        * config/sparc/sparc.md (snedi_special): Only match when not VIS3.
index 130161698596a46d41b2d5b4a9b5c56a00b10d92..ab888a96db84af0c5dead26100336a9a28a36142 100644 (file)
@@ -4352,10 +4352,20 @@ simplify_relational_operation_1 (enum rtx_code code, enum machine_mode mode,
     {
       rtx x = XEXP (op0, 0);
       rtx c = XEXP (op0, 1);
+      enum rtx_code invcode = op0code == PLUS ? MINUS : PLUS;
+      rtx tem = simplify_gen_binary (invcode, cmp_mode, op1, c);
+
+      /* Detect an infinite recursive condition, where we oscillate at this
+        simplification case between:
+           A + B == C  <--->  C - B == A,
+        where A, B, and C are all constants with non-simplifiable expressions,
+        usually SYMBOL_REFs.  */
+      if (GET_CODE (tem) == invcode
+         && CONSTANT_P (x)
+         && rtx_equal_p (c, XEXP (tem, 1)))
+       return NULL_RTX;
 
-      c = simplify_gen_binary (op0code == PLUS ? MINUS : PLUS,
-                              cmp_mode, op1, c);
-      return simplify_gen_relational (code, mode, cmp_mode, x, c);
+      return simplify_gen_relational (code, mode, cmp_mode, x, tem);
     }
 
   /* (ne:SI (zero_extract:SI FOO (const_int 1) BAR) (const_int 0))) is
index 9ef38fc4c0b6a47dfd5406155d79f9ab37d9aa84..c63184cbd1b1d91138195fa649b6e6969fc3af6a 100644 (file)
@@ -1,3 +1,8 @@
+2011-10-28  Chung-Lin Tang  <cltang@codesourcery.com>
+
+       PR rtl-optimization/49720
+       * g++.dg/torture/pr49720.C: New test.
+
 2011-10-27  David S. Miller  <davem@davemloft.net>
 
        * gcc.target/sparc/setcc-3.c: New test.
diff --git a/gcc/testsuite/g++.dg/torture/pr49720.C b/gcc/testsuite/g++.dg/torture/pr49720.C
new file mode 100644 (file)
index 0000000..c5da7ba
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+
+extern char t_start[], t_end[], t_size[];
+bool foo (void)
+{
+  long size = reinterpret_cast<long>(t_size);
+  return (size == t_end - t_start);
+}