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 <rguent...@suse.de> Eric Botcazou <ebotca...@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;