Lowering multiplyExact
Tom Rodriguez
tom.rodriguez at oracle.com
Thu Dec 1 17:51:52 UTC 2016
> On Dec 1, 2016, at 5:55 AM, Andrew Haley <aph at redhat.com> wrote:
>
> Graal assumes that multiplies set the overflow flag, and relies on
> this for multiplyExact. AArch64 doesn't set the overlfow flag for
> multiply, and as far as I can see neither does SPARC, so we have to do
> some backward somersaults to get it to work.
Couldn’t you just customize NodeLIRBuilderTool.emitOverflowCheckBranch to emit the proper test? I think the overflow in the name is really about whether the operation overflowed not which particular flags are set, even though the happen to correspond on intel. If it varies depending on the operation then the actual IntegerExactArithmeticSplitNode can be passed in.
tom
>
> Right now we do this:
>
> 0x0000007fa8baec54: smull x8, w1, w2
> 0x0000007fa8baec58: add w0, w8, #0x0
> 0x0000007fa8baec5c: cmp x8, w8, sxtw
> 0x0000007fa8baec60: orr x8, xzr, #0x80000000
> 0x0000007fa8baec64: csel w8, w8, wzr, ne
> 0x0000007fa8baec68: cmp w8, #0x1
> 0x0000007fa8baec6c: b.vs 0x0000007fa8baec8c
>
> which is
>
> x8 = i2l(w1) * i2l(w2)
> result = l2i(x8)
> flags = compare(x8, result)
> x8 = 0x80000000
> w8 = flags.ne ? w8 : 0
> flags = compare(w8, 1)
> ...
> if (flags.vs) goto overflow
>
> But it could be simply
>
> x8 = i2l(w1) * i2l(w2)
> result = l2i(x8)
> flags = compare(x8, result)
> ...
> if (flags.ne) goto overflow
>
> if we had a lowering for multiplyExact that didn't assume that
> multiplies set the overflow flag.
>
> It's really not an important thing, but it's kinda irksome. :-)
>
> Andrew.
More information about the graal-dev
mailing list