This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR 23049


:ADDPATCH middle-end (fold):

The problem here is that we get in fold the following expression:
0 == 0 ? 0 : 1
We go into an infinite calling fold over and over again.

There are a couple of ways fixing this:
1.  Call fold on arg0 when we have a COND_EXPR.
2.  Make sure that fold does not go into an infinite loop.
3.  fold the EQ_EXPR before getting into fold.

The problem with 3, is that in DOM, we replace, a with 0 where
the original expression was "a == 0 ? 0 : 1" so DOM is just
replacing an expression with its value and should not be the
one who is folding the expression.

The problem with 2, is the code would just get too complex
and less readable.

So I went with number 1 which was also the easiest of them
all.

OK? Bootstrapped and tested on x86_64-pc-linux-gnu with no regressions.

Thanks,
Andrew Pinski

ChangeLog:
	* fold-const.c (fold_ternary) <case COND_EXPR>: Fold arg0 before doing
	anything else.

Testcase:

/* { dg-options "-O3 -ftree-vectorize" } */
/* { dg-do compile } */
unsigned long CRCTab[256];
void InitCRC(void) {
int I, J;
unsigned long C;
for (I=0; I<256; I++)
{
for (C=I,J=0;J<8;J++)
C=(C & 1) ? (C>>1)^0xEDB88320L : (C>>1);
CRCTab[I]=C;
}
}
void AC3_encode_init(void)
{
unsigned int c, n, k;
for(n=0; n<256; n++)
{
c = n << 8;
for (k = 0; k < 8; k++)
{
if (c & (1 << 15))
c = ((c << 1) & 0xffff) ^ (((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16)) & 0xffff);
}
CRCTab[n] = c;
}
}



Attachment: t46.diff.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]