Bug 57417 - [4.7 Regression] hang on volatile int array
Summary: [4.7 Regression] hang on volatile int array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.7.4
Assignee: Richard Biener
URL:
Keywords:
Depends on:
Blocks: 57381
  Show dependency treegraph
 
Reported: 2013-05-25 18:42 UTC by Zhendong Su
Modified: 2014-05-06 14:23 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.6.4, 4.7.4, 4.8.2, 4.9.0
Known to fail: 4.7.3, 4.8.1
Last reconfirmed: 2013-05-27 00:00:00


Attachments
prototype patch (1.25 KB, patch)
2013-05-27 10:22 UTC, Richard Biener
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2013-05-25 18:42:47 UTC
The following code causes gcc trunk (and the 4.7 & 4.8 branches) to hang at -O1 or above. This seems to be different from 57381, but perhaps related.

$ gcc-trunk -v
Target: x86_64-unknown-linux-gnu
gcc version 4.9.0 20130525 (experimental) [trunk revision 199323] (GCC)
$ gcc-trunk -m32 -O0 -c small.c
$ gcc-trunk -m32 -O1 -c small.c
^C
$ cat small.c
int a, b, c;

void foo ()
{
  volatile int d[1];
  b = 0;
  for (;; a--)
    c = (int)&d[b];
}
Comment 1 Richard Biener 2013-05-27 08:25:00 UTC
Yeah, similar.  Mine.
Comment 2 Richard Biener 2013-05-27 09:54:05 UTC
The existing support for comparing addresses in operand_equal_p cannot handle
this as the volatile array is local.

It seems to me that there is no good reason to ever treat addresses of
TREE_SIDE_EFFECTS trees as different if there is not TREE_SIDE_EFFECTS
on offset determining pieces (though that would rely on gimplification
for COMPONENT_REFs?).

I wonder if this is the right time to introduce gimple_op_equal_p (),
wrapping operand_equal_p but handling a few cases less conservative...
Comment 3 Richard Biener 2013-05-27 10:22:42 UTC
Created attachment 30202 [details]
prototype patch

Like the attached.
Comment 4 Eric Botcazou 2013-05-27 10:31:38 UTC
> It seems to me that there is no good reason to ever treat addresses of
> TREE_SIDE_EFFECTS trees as different if there is not TREE_SIDE_EFFECTS
> on offset determining pieces (though that would rely on gimplification
> for COMPONENT_REFs?).

Yes, I agree that the handling of addresses looks overly conservative.
Comment 5 rguenther@suse.de 2013-05-27 10:59:39 UTC
On Mon, 27 May 2013, ebotcazou at gcc dot gnu.org wrote:

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57417
> 
> --- Comment #4 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> > It seems to me that there is no good reason to ever treat addresses of
> > TREE_SIDE_EFFECTS trees as different if there is not TREE_SIDE_EFFECTS
> > on offset determining pieces (though that would rely on gimplification
> > for COMPONENT_REFs?).
> 
> Yes, I agree that the handling of addresses looks overly conservative.

I suppose TREE_SIDE_EFFECTS matter on the offset expression of
a get_inner_reference call on op0 of the ADDR_EXPR.  For Ada that
would involve looking at SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET 
(field), exp) for example - or do we somehow guarantee that the
offset expressions that do not appear in indexes like operand 1 of
ARRAY_REFs do not contain side-effects?
Comment 6 Richard Biener 2013-05-27 12:45:08 UTC
Author: rguenth
Date: Mon May 27 12:44:29 2013
New Revision: 199356

URL: http://gcc.gnu.org/viewcvs?rev=199356&root=gcc&view=rev
Log:
2013-05-27  Richard Biener  <rguenther@suse.de>

	Revert
	PR middle-end/57381
	* fold-const.c (operand_equal_p): Compare FIELD_DECLs with
	OEP_CONSTANT_ADDRESS_OF retained.

	PR tree-optimization/57417
	* tree-ssa-sccvn.c (vn_reference_fold_indirect): Fix test
	for unchanged base.
	(set_ssa_val_to): Compare addresses using
	get_addr_base_and_unit_offset.

	* gcc.dg/torture/pr57417.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr57417.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-sccvn.c
Comment 7 Eric Botcazou 2013-05-27 21:08:04 UTC
> I suppose TREE_SIDE_EFFECTS matter on the offset expression of
> a get_inner_reference call on op0 of the ADDR_EXPR.  For Ada that
> would involve looking at SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET 
> (field), exp) for example - or do we somehow guarantee that the
> offset expressions that do not appear in indexes like operand 1 of
> ARRAY_REFs do not contain side-effects?

No, we cannot guarantee that.  But AFAICS operand_equal_p rejects two ADDR_EXPRs of the same expression when !OEP_ONLY_CONST only because it has TREE_SIDE_EFFECTS and I don't see why, IOW my understanding is that it should be possible to add a OEP_ADDRESS_OF flag when !OEP_ONLY_CONST and use it to be less conservative.
Comment 8 Jakub Jelinek 2013-08-29 13:15:02 UTC
Author: jakub
Date: Thu Aug 29 13:14:59 2013
New Revision: 202074

URL: http://gcc.gnu.org/viewcvs?rev=202074&root=gcc&view=rev
Log:
	Backported from mainline
	2013-07-22  Georg-Johann Lay  <avr@gjlay.de>

	PR testsuite/52641
	* gcc.dg/torture/pr57381.c: Add dg-require-effective-target int32plus.

	2013-05-27  Richard Biener  <rguenther@suse.de>

	PR middle-end/57381
	PR tree-optimization/57417
	* tree-ssa-sccvn.c (vn_reference_fold_indirect): Fix test
	for unchanged base.
	(set_ssa_val_to): Compare addresses using
	get_addr_base_and_unit_offset.

	PR tree-optimization/57417
	* gcc.dg/torture/pr57417.c: New testcase.

	2013-05-23  Richard Biener  <rguenther@suse.de>

	PR middle-end/57381
	* gcc.dg/torture/pr57381.c: New testcase.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/torture/pr57381.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/torture/pr57417.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_8-branch/gcc/tree-ssa-sccvn.c
Comment 9 Jakub Jelinek 2013-08-29 13:18:37 UTC
Fixed for 4.8.2+.
Comment 10 Richard Biener 2014-05-06 14:23:13 UTC
Author: rguenth
Date: Tue May  6 14:22:41 2014
New Revision: 210110

URL: http://gcc.gnu.org/viewcvs?rev=210110&root=gcc&view=rev
Log:
2014-05-06  Richard Biener  <rguenther@suse.de>

	Backport from mainline
	2013-05-27  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/57417
	* tree-ssa-sccvn.c (set_ssa_val_to): Compare addresses using
	get_addr_base_and_unit_offset.

	* gcc.dg/torture/pr57417.c: New testcase.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.dg/torture/pr57417.c
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_7-branch/gcc/tree-ssa-sccvn.c
Comment 11 Richard Biener 2014-05-06 14:23:20 UTC
Fixed.