From: Chung-Lin Tang Date: Fri, 28 Oct 2011 06:35:31 +0000 (+0000) Subject: re PR rtl-optimization/49720 (Infinite recursion compiling gold binary_test.cc testcase) X-Git-Tag: releases/gcc-4.7.0~2749 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d303c992f61f5f94aaa314e914b1e27280940de2;p=thirdparty%2Fgcc.git re PR rtl-optimization/49720 (Infinite recursion compiling gold binary_test.cc testcase) 2011-10-28 Chung-Lin Tang 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 420e188b91ed..61320f852ab7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2011-10-28 Chung-Lin Tang + + 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 * config/sparc/sparc.md (snedi_special): Only match when not VIS3. diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 130161698596..ab888a96db84 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9ef38fc4c0b6..c63184cbd1b1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-10-28 Chung-Lin Tang + + PR rtl-optimization/49720 + * g++.dg/torture/pr49720.C: New test. + 2011-10-27 David S. Miller * 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 index 000000000000..c5da7ba670f1 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr49720.C @@ -0,0 +1,8 @@ +/* { dg-do compile } */ + +extern char t_start[], t_end[], t_size[]; +bool foo (void) +{ + long size = reinterpret_cast(t_size); + return (size == t_end - t_start); +}