The following testcase calls abort when it is compiled with
-O3 -ftree-loop-distribution.
/* Derived from gcc.c-torture/execute/20010910-1.c. */
extern void abort(void);
struct epic_private
{
unsigned int *rx_ring;
unsigned int rx_skbuff[5];
};
int
main (void)
{
struct epic_private ep;
unsigned int rx_ring[5];
int i;
ep.rx_skbuff[0] = 5;
ep.rx_ring = rx_ring;
for (i = 0; i < 5; i++)
{
ep.rx_ring[i] = i;
ep.rx_skbuff[i] = 0;
}
if (ep.rx_skbuff[0] != 0)
abort ();
return 0;
}
The loop distribution pass produces:
<bb 2>:
ep.rx_skbuff[0] = 5;
<bb 8>:
# i_22 = PHI <i_36(9), 0(2)>
D.1604_11 = (long unsigned int) i_22;
D.1605_30 = D.1604_11 * 4;
D.1606_31 = &rx_ring + D.1605_30;
i.0_32 = (unsigned int) i_22;
*D.1606_31 = i.0_32;
i_36 = i_22 + 1;
if (i_36 <= 4)
goto <bb 9>;
else
goto <bb 10>;
<bb 9>:
goto <bb 8>;
<bb 10>:
Invalid sum of outgoing probabilities 0.0%
D.1642_37 = &ep + 8;
__builtin_memset (D.1642_37, 0, 20);
<bb 5>:
Invalid sum of incoming frequencies 0, should be 1667
D.1609_10 = ep.rx_skbuff[0];
if (D.1609_10 != 0)
goto <bb 6>;
else
goto <bb 7>;
<bb 6>:
abort ();
<bb 7>:
return 0;
dom2 in turn produces:
ep.rx_skbuff[0] = 5;
rx_ring[0] = 0;
D.1606_47 = &rx_ring[1];
rx_ring[1] = 1;
D.1606_59 = &rx_ring[2];
rx_ring[2] = 2;
D.1606_71 = &rx_ring[3];
rx_ring[3] = 3;
D.1606_31 = &rx_ring[4];
rx_ring[4] = 4;
D.1642_37 = &ep + 8;
__builtin_memset (D.1642_37, 0, 20);
D.1609_10 = 5;
abort ();
Note that the end of the function is replaced with an unconditional
abort.
GCC puts an unconditional abort at the rtl level when compiling The
original gcc.c-torture/execute/20010910-1.c. Once I remove extra
source code, I can observe an unconditional abort at the tree level.
The compiler probably does not notice that the value of
ep.rx_skbuff[0] changes across __builtin_memset. This sounds like an
alias problem of some sort.
--
Summary: wrong code generated with -ftree-loop-disttribution
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kazu at gcc dot gnu dot org
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39132