Constant folding problems between snoot and porky
Timothy Jones <[email protected]> Wed, 04 Jan 2006 14:37:52 +0000
| Newsgroups | gmane.comp.compilers.suif.bugs |
|---|---|
| Message-ID | <[email protected]> |
Hi everyone,
I've found a bug in either snoot or porky that is exposed when constant
folding occurs. I'm not sure which program the bug is in, but let me
explain further. I'm compiling this on an Alpha, so 'long' is 64 bits.
This is from 253.perlbmk, a SPEC2000 benchmark:
cast_iv(f)
double f;
{
if (f >= IV_MAX)
return (IV) IV_MAX;
if (f <= IV_MIN)
return (IV) IV_MIN;
return (IV) f;
}
It's the first 'if' statement that causes problems. Here it is after
preprocessing (I've substituted in the typedefs):
if (f >= ((long)((~(unsigned long)0) >> 1)))
which I calculate to be:
if (f >= (0x7fffffffffffffff))
or
if (f >= (9223372036854775807))
Running 'snoot -Talpha-dec-osf' gives this output:
2: IF (Jumpto=L:cast_iv.L1)
IF HEADER
3: bfalse e1, L:cast_iv.L1
4: e1: sle t:g30 (i.32) e2, cast_iv.f
5: e2: cvt t:g11 (f.64) e3
6: e3: cvt t:g4 (i.32) e4
7: e4: cvt t:g5 (i.64) e5
8: e5: lsr t:g9 (u.64) e6, e7
9: e6: not t:g9 (u.64) e8
10: e8: ldc t:g9 (u.64) 0
11: e7: ldc t:g8 (u.32) 1
and 'porky -defaults' on the resulting file gives this:
2: IF (Jumpto=L:cast_iv.L1)
IF HEADER
3: bfalse e1, L:cast_iv.L1
4: e1: sle t:g30 (i.32) e2, cast_iv.f
63: e2: ldc t:g11 (f.64) -1.000000000000000000e+00
As you can see, the constant has been incorrectly calculated as -1.
My problem is that I don't know where the error is. Does anybody know
why in line 6: of the output, snoot converts the value to an i.32 type?
Could this be the problem because the value is too large for the type?
Or is the problem with porky and it's constant folding algorithm that
should still manage this? Any help that can be given would be much
appreciated.
Thanks
Tim
_______________________________________________
To unsubscribe, send mail to [email protected]
or visit http://suif.stanford.edu/mailman/listinfo/suif-bugs