Bug 43209 - [4.5 Regression] ICE in try_improve_iv_set, at tree-ssa-loop-ivopts.c:5238
Summary: [4.5 Regression] ICE in try_improve_iv_set, at tree-ssa-loop-ivopts.c:5238
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.5.0
: P1 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords: ice-on-valid-code, patch
: 43238 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-02-28 13:41 UTC by Zdenek Sojka
Modified: 2010-03-04 12:14 UTC (History)
5 users (show)

See Also:
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Build:
Known to work: 4.4.3
Known to fail: 4.5.0
Last reconfirmed: 2010-02-28 22:01:43


Attachments
reduced testcase (75 bytes, text/plain)
2010-02-28 13:42 UTC, Zdenek Sojka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2010-02-28 13:41:15 UTC
Command line:
gcc -O1 testcase.c
(fails at all -O[123] levels)

Tested revisions:
r156999 - crash
r156745 - crash
r156293 - OK
4.4 r156256 - OK (with checking)

Output (with checking):
$ mnt/svn/gcc-trunk/binary-156999-lto/bin/gcc -O1 testcase.c
testcase.c: In function 'foo':
testcase.c:1:6: internal compiler error: in try_improve_iv_set, at tree-ssa-loop-ivopts.c:5238
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

Output (without checking):
$ gcc-4.5.0-alpha20100225 -O1 testcase.c
testcase.c: In function 'foo':
testcase.c:1:6: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugs.gentoo.org/> for instructions.
Comment 1 Zdenek Sojka 2010-02-28 13:42:21 UTC
Created attachment 19986 [details]
reduced testcase

Command line:
gcc -O1 pr43209.c
(or -O2, -O3)
Comment 2 Zdenek Sojka 2010-02-28 13:49:17 UTC
4.4 r157120 works fine too

testcase doesn't fail at -O2, -O3 (in trunk)
Comment 3 H.J. Lu 2010-02-28 17:02:14 UTC
It is caused by revision 156701:

http://gcc.gnu.org/ml/gcc-cvs/2010-02/msg00283.html
Comment 4 Alexander Monakov 2010-02-28 22:01:43 UTC
Confirmed.
The first invocation of get_computation_aff fails with ustep == (long) j, cstep == (unsigned long) j: constant_multiple_of (ustep, cstep, &rat) returns false (j is int, STRIP_NOPS ({u,c}step) preserves conversions).
Comment 5 Changpeng Fang 2010-03-01 18:02:51 UTC
I have a fix for this problem. We should not decrease the cost if the cost is
infinite.

diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 74dadf7..9accda9 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -4124,7 +4124,11 @@ determine_use_iv_cost_condition (struct ivopts_data *data,
   if (integer_zerop (*bound_cst)
       && (operand_equal_p (*control_var, cand->var_after, 0)
          || operand_equal_p (*control_var, cand->var_before, 0)))
-    elim_cost.cost -= 1;
+    {
+      /* Should not decrease the cost if it is infinite */
+      if (!infinite_cost_p (elim_cost))
+        elim_cost.cost -= 1;
+    }
Comment 6 sebpop@gmail.com 2010-03-01 18:10:59 UTC
Subject: Re:  [4.5 Regression] ICE in 
	try_improve_iv_set, at tree-ssa-loop-ivopts.c:5238

On Mon, Mar 1, 2010 at 12:02, changpeng dot fang at amd dot com
> I have a fix for this problem. We should not decrease the cost if the cost is
> infinite.
>

Looks good.  Thanks for fixing this.  Please test with the minor
modification below, and submit a patch to gcc-patches@

> diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
> index 74dadf7..9accda9 100644
> --- a/gcc/tree-ssa-loop-ivopts.c
> +++ b/gcc/tree-ssa-loop-ivopts.c
> @@ -4124,7 +4124,11 @@ determine_use_iv_cost_condition (struct ivopts_data
> *data,
>   if (integer_zerop (*bound_cst)
>       && (operand_equal_p (*control_var, cand->var_after, 0)
>          || operand_equal_p (*control_var, cand->var_before, 0)))
> -    elim_cost.cost -= 1;
> +    {
> +      /* Should not decrease the cost if it is infinite */
> +      if (!infinite_cost_p (elim_cost))

You should fuse this condition into the previous condition expression
to avoid the inner if.

> +        elim_cost.cost -= 1;
> +    }
Comment 7 sebpop@gmail.com 2010-03-01 18:21:12 UTC
Subject: Re:  [4.5 Regression] ICE in 
	try_improve_iv_set, at tree-ssa-loop-ivopts.c:5238

> You should fuse this condition into the previous condition expression
> to avoid the inner if.

Like this:

diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 74dadf7..3b766ed 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -4121,7 +4121,8 @@ determine_use_iv_cost_condition (struct ivopts_data *data,
      TODO: The constant that we're substracting from the cost should
      be target-dependent.  This information should be added to the
      target costs for each backend.  */
-  if (integer_zerop (*bound_cst)
+  if (!infinite_cost_p (elim_cost)
+      && integer_zerop (*bound_cst)
       && (operand_equal_p (*control_var, cand->var_after, 0)
 	  || operand_equal_p (*control_var, cand->var_before, 0)))
     elim_cost.cost -= 1;
Comment 8 Andrew Pinski 2010-03-02 20:58:33 UTC
*** Bug 43238 has been marked as a duplicate of this bug. ***
Comment 9 Sebastian Pop 2010-03-04 12:13:03 UTC
Subject: Bug 43209

Author: spop
Date: Thu Mar  4 12:12:50 2010
New Revision: 157217

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157217
Log:
Fix PR43209: Do not decrease the cost of an IV candidate when the cost is infinite.

2010-03-03  Changpeng Fang  <changpeng.fang@amd.com>

      PR middle-end/43209
      * tree-ssa-loop-ivopts.c (determine_use_iv_cost_condition): Do not decrease
      the cost of an IV candidate when the cost is infinite.

      * gcc.dg/tree-ssa/ivopts-4.c: New.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ivopts-4.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-loop-ivopts.c

Comment 10 Sebastian Pop 2010-03-04 12:14:28 UTC
Fixed.
Comment 11 hjl@gcc.gnu.org 2010-03-13 16:59:35 UTC
Subject: Bug 43209

Author: hjl
Date: Sat Mar 13 16:58:19 2010
New Revision: 157426

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157426
Log:
Backport testcases from mainline.

2010-03-13  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline:
	2010-03-11  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/43257
	* g++.dg/torture/pr43257.C: New test.

	2010-03-11  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/43255
	* gcc.c-torture/compile/pr43255.c: New testcase.

	2010-03-11  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>

	* gcc.dg/pr43280.c: New testcase.

	2010-03-10  Jan Hubicka   <jh@suse.cz>

	* gcc.c-torture/compile/pr43288.c: New test.

	2010-03-10  Andrey Belevantsev  <abel@ispras.ru>

	PR middle-end/42859
	* g++.dg/eh/pr42859.C: New test.

	2010-03-09  Jakub Jelinek  <jakub@redhat.com>

	PR debug/43299
	* gcc.dg/pr43299.c: New test.

	2010-03-08  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/43269
	* gcc.c-torture/execute/pr43269.c: New testcase.

	2010-03-04  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/43164
	PR tree-optimization/43191
	* gcc.c-torture/compile/pr43164.c: New test.
	* gcc.c-torture/compile/pr43191.c: Likewise.

	2010-03-04  Changpeng Fang  <changpeng.fang@amd.com>

	PR middle-end/43209
	* gcc.dg/tree-ssa/ivopts-4.c: New.

	2010-03-03  Jakub Jelinek  <jakub@redhat.com>

	PR debug/43229
	* gfortran.dg/pr43229.f90: New test.

	PR debug/43237
	* gcc.dg/debug/dwarf2/pr43237.c: New test.

	2010-03-02  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/43180
	* gfortran.dg/internal_pack_10.f90: New test.

	2010-02-26  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/43188
	* gcc.c-torture/compile/pr43188.c: New testcase.

	2010-02-25  Jakub Jelinek  <jakub@redhat.com>

	PR debug/43166
	* gfortran.dg/debug/pr43166.f: New test.

	PR debug/43165
	* gcc.dg/torture/pr43165.c: New test.

	2010-02-23  Jakub Jelinek  <jakub@redhat.com>

	PR target/43107
	* gcc.target/i386/pr43107.c: New test.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/eh/pr42859.C
      - copied unchanged from r157425, trunk/gcc/testsuite/g++.dg/eh/pr42859.C
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/torture/pr43257.C
      - copied unchanged from r157425, trunk/gcc/testsuite/g++.dg/torture/pr43257.C
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr43164.c
      - copied unchanged from r157425, trunk/gcc/testsuite/gcc.c-torture/compile/pr43164.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr43188.c
      - copied unchanged from r157425, trunk/gcc/testsuite/gcc.c-torture/compile/pr43188.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr43191.c
      - copied unchanged from r157425, trunk/gcc/testsuite/gcc.c-torture/compile/pr43191.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr43255.c
      - copied unchanged from r157425, trunk/gcc/testsuite/gcc.c-torture/compile/pr43255.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr43288.c
      - copied unchanged from r157425, trunk/gcc/testsuite/gcc.c-torture/compile/pr43288.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/execute/pr43269.c
      - copied unchanged from r157425, trunk/gcc/testsuite/gcc.c-torture/execute/pr43269.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/debug/dwarf2/pr43237.c
      - copied unchanged from r157425, trunk/gcc/testsuite/gcc.dg/debug/dwarf2/pr43237.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/pr43280.c
      - copied unchanged from r157425, trunk/gcc/testsuite/gcc.dg/pr43280.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/pr43299.c
      - copied unchanged from r157425, trunk/gcc/testsuite/gcc.dg/pr43299.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/torture/pr43165.c
      - copied unchanged from r157425, trunk/gcc/testsuite/gcc.dg/torture/pr43165.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/tree-ssa/ivopts-4.c
      - copied unchanged from r157425, trunk/gcc/testsuite/gcc.dg/tree-ssa/ivopts-4.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.target/i386/pr43107.c
      - copied unchanged from r157425, trunk/gcc/testsuite/gcc.target/i386/pr43107.c
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/debug/pr43166.f
      - copied unchanged from r157425, trunk/gcc/testsuite/gfortran.dg/debug/pr43166.f
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/internal_pack_10.f90
      - copied unchanged from r157425, trunk/gcc/testsuite/gfortran.dg/internal_pack_10.f90
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/pr43229.f90
      - copied unchanged from r157425, trunk/gcc/testsuite/gfortran.dg/pr43229.f90
Modified:
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog