[MLton-devel] Re: your mail

Matthew Fluet fluet@cs.cornell.edu
Tue, 1 Jul 2003 13:35:13 -0400 (EDT)


> > The  version  of MLton we are using has some kind of bug because if I compile
> > the following:
> >
> >     val f = IntInf.fromInt
> >     val _ =
> >            print (IntInf.toString (IntInf.div (f ~3, f 2)) ^ "\n")
> >
> > Then I get the following error (at compile time):
> >     x86Translate.translateChunk::x86Translate.Chunk.toX86Chunk::x86Translate.Block.toX86Blocks::x86Translate.Statement.toX86Blocks::RI32(0): Int32  = OI32 (Cast (Cast (0wxFFFFFFFB, intInf), pt_4), ~8)::x86Translate.Operand.toX86Operand::toX86Operand: strange Offset: base: $0xFFFFFFFB
> > on both Red Hat 7.1 and 8.0.
>
> This is almost certainly a bug in the SSA simplifier that leaves an
> IntInf constant around, with some dead code that thinks its a pointer
> to a word vector.  Hopefully we don't need the bug fix right now, and
> the problem will go away in a program where the constants are not
> known.

The problem is with the way  Word_toIntInf/IntInf_toWord  are handled in
the SSA simplifier and in  SsaToRssa.  The SSA simplifier only evaluates
the conversions on constants when the respective intInf is small, but
SsaToRssa implements both of them as a cast, so the constant is propagated
around to the point where it is cast to a big intInf (which it isn't) and
is accessed as a vector.

I think the actual bug is in Const.SmallIntInf.fromWord:

      fun fromWord (w: word): IntInf.t option =
	 if w < 0wx80000000
	    then SOME (IntInf.fromInt (Word.toIntX (Word.~>> (w, 0w1))))
	 else NONE

In particular, this doesn't "line up" with
basis-library/integer/int-inf.fun's implementation of fromInt:
      (*
       * Given a Word.word, add the tag bit in so that it looks like
       * a fixnum bigInt.
       *)
      fun addTag (argw: Word.word): Word.word =
	 Word.orb (Word.<< (argw, 0w1), 0w1)
      (*
       * Given two Word.word's, check if they have the same `sign' bit.
       *)
      fun sameSign (lhs: Word.word, rhs: Word.word): bool =
	 Word.toIntX (Word.xorb (lhs, rhs)) >= 0
      (*
       * Convert a smallInt to a bigInt.
       *)
      fun bigFromInt (arg: smallInt): bigInt =
	 let
	    val argv = Word.fromInt arg
	    val ans = addTag argv
	 in
	    if sameSign (argv, ans)
	       then Prim.fromWord ans
	    else ,,,
         end
which will happily convert word's corresponding to negative signed
integers into a smallInt if they fit in 31 bits.  Note that
Const.SmallIntInf.fromWord only works on positive signed integers.
So, Henry's ~3 is a constant that run's down the true branch of
bigFromInt, but the SSA simplifier won't do anything with it.

It's a shame that we need to duplicate the logic for handing small/large
intInf's in both the basis-library and in the compiler.  Couldn't we
simplify Const.SmallIntInf.{to,from}Word by using
MLton.IntInf.{isSmall,rep}?



-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel