public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix CCP and addresses of multi-dimensional arrays
@ 2012-07-19 11:46 Richard Guenther
  2012-07-19 20:26 ` Eric Botcazou
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Guenther @ 2012-07-19 11:46 UTC (permalink / raw)
  To: gcc-patches; +Cc: ebotcazou


The Ada testcase below exposes that we do not properly handle
&a[CONSTANT][UNDEFINED] when initially computing its lattice
value and will ICE if the UNDEFINED value becomes CONSTANT later.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk
(Eric, if you want to do the testing on the branch and do the backport
that would be nice).

Richard.

2012-07-19  Richard Guenther  <rguenther@suse.de>
	Eric Botcazou  <ebotcazou@adacore.com>

	* tree-ssa-ccp.c (valid_lattice_transition): Clarify comment
	about transition from invariant to known bits.
	(likely_value): Addresses with UNDEFINED components are
	UNDEFINED.

	* gnat.dg/loop_optimization11.adb: New testcase.
	* gnat.dg/loop_optimization11_pkg.ads: Likewise.

Index: gcc/tree-ssa-ccp.c
===================================================================
*** gcc/tree-ssa-ccp.c	(revision 189646)
--- gcc/tree-ssa-ccp.c	(working copy)
*************** valid_lattice_transition (prop_value_t o
*** 405,411 ****
  
    /* Now both lattice values are CONSTANT.  */
  
!   /* Allow transitioning from &x to &x & ~3.  */
    if (TREE_CODE (old_val.value) != INTEGER_CST
        && TREE_CODE (new_val.value) == INTEGER_CST)
      return true;
--- 405,412 ----
  
    /* Now both lattice values are CONSTANT.  */
  
!   /* Allow transitioning from PHI <&x, not executable> == &x
!      to PHI <&x, &y> == common alignment.  */
    if (TREE_CODE (old_val.value) != INTEGER_CST
        && TREE_CODE (new_val.value) == INTEGER_CST)
      return true;
*************** likely_value (gimple stmt)
*** 648,653 ****
--- 649,659 ----
  	     the undefined operand may be promoted.  */
  	  return UNDEFINED;
  
+ 	case ADDR_EXPR:
+ 	  /* If any part of an address is UNDEFINED, like the index
+ 	     of an ARRAY_EXPR, then treat the result as UNDEFINED.  */
+ 	  return UNDEFINED;
+ 
  	default:
  	  ;
  	}
Index: gcc/testsuite/gnat.dg/loop_optimization11.adb
===================================================================
*** gcc/testsuite/gnat.dg/loop_optimization11.adb	(revision 0)
--- gcc/testsuite/gnat.dg/loop_optimization11.adb	(working copy)
***************
*** 0 ****
--- 1,19 ----
+ -- { dg-do compile }
+ -- { dg-options "-O" }
+ 
+ with Loop_Optimization11_Pkg; use Loop_Optimization11_Pkg;
+ 
+ procedure Loop_Optimization11 is
+    Arr : array (Prot, Mem) of Integer := (others => (others => 0));
+ begin
+    Put_Line (Img (0) & " ");
+    for I in Arr'Range (1) loop
+       for J in Arr'Range (2) loop
+          declare
+             Elem : Integer renames Arr (I, J);
+          begin
+             Put_Line (Img (Elem));
+          end;
+       end loop;
+    end loop;
+ end;
Index: gcc/testsuite/gnat.dg/loop_optimization11_pkg.ads
===================================================================
*** gcc/testsuite/gnat.dg/loop_optimization11_pkg.ads	(revision 0)
--- gcc/testsuite/gnat.dg/loop_optimization11_pkg.ads	(working copy)
***************
*** 0 ****
--- 1,11 ----
+ package Loop_Optimization11_Pkg is
+ 
+    function Img (X : Integer) return String;
+ 
+    procedure Put_Line (Data : String);
+ 
+    type Prot is (Execute, Execute_Read, Execute_Read_Write);
+ 
+    type Mem is (Mem_Image, Mem_Mapped, Mem_Private, Unknown);
+ 
+ end Loop_Optimization11_Pkg;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix CCP and addresses of multi-dimensional arrays
  2012-07-19 11:46 [PATCH] Fix CCP and addresses of multi-dimensional arrays Richard Guenther
@ 2012-07-19 20:26 ` Eric Botcazou
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Botcazou @ 2012-07-19 20:26 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches

> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk
> (Eric, if you want to do the testing on the branch and do the backport
> that would be nice).

Done.  Thanks for your help.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-07-19 20:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-19 11:46 [PATCH] Fix CCP and addresses of multi-dimensional arrays Richard Guenther
2012-07-19 20:26 ` Eric Botcazou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).