This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[4.3] Fix wrong code for loop at -O
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 14 Apr 2008 13:34:56 +0200
- Subject: [4.3] Fix wrong code for loop at -O
This is a wrong code regression present on the 4.3 branch. It is actually
caught if checking is enabled, for example in the stage 1 compiler:
loop_address2.adb: In function 'Loop_Address2':
loop_address2.adb:4: error: expected an SSA_NAME object
loop_address2.adb:4: error: in statement
# A.17 = VDEF <A.17> { A.17 }
A.17 = D.212_12;
+===========================GNAT BUG DETECTED==============================+
| 4.3.1 20080308 (prerelease) [gcc-4_3-branch revision 133036]
(i586-suse-linux-gnu) GCC error:|
| verify_ssa failed
This is IVOPTS turning
<bb 3>:
# ivtmp.8_1 = PHI <ivtmp.8_13(6), 3(2)>
# i_19 = PHI <i_7(6), 0(2)>
b.1_4 = (const system__address) &b;
C2b_9 = i_19 * 4;
C9b_10 = VIEW_CONVERT_EXPR<system__address>(C2b_9);
D.197_11 = C9b_10 + b.1_4;
p_6 = (integer * {ref-all}) D.197_11;
if (p_6 == 0B)
goto <bb 4>;
else
goto <bb 5>;
into
<bb 2>:
D.215_12 = 0;
A.17 = D.215_12;
A.18_5 = &A.17;
D.218_22 = (system__address *) A.18_5;
ivtmp.14_23 = (unsigned int) D.218_22;
<bb 3>:
# ivtmp.14_14 = PHI <ivtmp.14_8(6), ivtmp.14_23(2)>
b.1_4 = (const system__address) &b;
D.219_24 = (long int) ivtmp.14_14;
C9b_10 ={v} MEM[index: D.219_24];
D.197_11 = C9b_10 + b.1_4;
p_6 = (integer * {ref-all}) D.197_11;
if (p_6 == 0B)
goto <bb 4>;
else
goto <bb 5>;
The problem is that may_be_nonaddressable_p deems VIEW_CONVERT_EXPR<0>
addressable. This is already fixed on the mainline because of
case VIEW_CONVERT_EXPR:
/* This kind of view-conversions may wrap non-addressable objects
and make them look addressable. After some processing the
non-addressability may be uncovered again, causing ADDR_EXPRs
of inappropriate objects to be built. */
if (is_gimple_reg (TREE_OPERAND (expr, 0))
|| is_gimple_min_invariant (TREE_OPERAND (expr, 0)))
return true;
so I've just backported the minimal change to make this work on the branch.
Tested on i586-suse-linux, applied on the branch as obvious and the testcase
on the mainline as well.
2008-04-14 Eric Botcazou <ebotcazou@adacore.com>
* tree-ssa-loop-ivopts.c (may_be_nonaddressable_p) <VIEW_CONVERT_EXPR>:
Return true if the operand is an INTEGER_CST.
2008-04-14 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/loop_address2.adb: New test.
--
Eric Botcazou
Index: tree-ssa-loop-ivopts.c
===================================================================
--- tree-ssa-loop-ivopts.c (revision 133036)
+++ tree-ssa-loop-ivopts.c (working copy)
@@ -1451,6 +1451,8 @@ may_be_nonaddressable_p (tree expr)
if (AGGREGATE_TYPE_P (TREE_TYPE (expr))
&& !AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 0))))
return true;
+ if (TREE_CODE (TREE_OPERAND (expr, 0)) == INTEGER_CST)
+ return true;
/* ... fall through ... */
-- { dg-do compile }
-- { dg-options "-O" }
with System, Ada.Unchecked_Conversion;
with System.Storage_Elements; use System.Storage_Elements;
procedure Loop_Address2 is
type Ptr is access all Integer;
function To_Ptr is new Ada.Unchecked_Conversion (System.Address, Ptr);
function F (BM : System.Address; I : Integer) return System.Address is
begin
return BM + Storage_Offset (4*I);
end;
B : Integer;
P : Ptr;
begin
for I in 0 .. 2 loop
P := To_Ptr (F (B'Address, I));
P.all := 0;
end loop;
end ;