Sub-word comparisons

Andrew Haley aph at redhat.com
Fri Nov 4 11:46:52 UTC 2016


On 03/11/16 19:58, Tom Rodriguez wrote:
> 
> I believe they can fall out of other transformations like the
> stripping of conversions, like Compare(ZeroExtend(x), ZeroExtend(y))
> -> Compare(x, y). 

Exactly so.

> I suspect the way this is supposed to work is that the if your
> backend doesn’t really support sub word types then it should never
> produce them.  So even if x is an i8 at the Node level the LIR
> operation should produce a word in the platform kind.

I get that, but how?  I'm trying to figure out a good way to generate
LIR to produce a word in the platform kind.

I was thinking about this in AArch64LIRGenerator.emitCompare but it's
ugly:

     if (size != 32 && size != 64) {
         Variable left1 = newVariable(LIRKind.value(target().arch.getWordKind()));
         Variable right1 = newVariable(LIRKind.value(target().arch.getWordKind()));
         append(new AArch64SignExtendOp(left1, load(a), size, 64));
         append(new AArch64SignExtendOp(right1, load(b), size, 64));
         a = left1;
         b = right1;
     }

(I need to be a bit more clever about sign-extending constants, but
more detail would obfuscate the point.)

Ah, I just looked at SPARC, and it does the exact same thing:

        int compareBytes = cmpKind.getSizeInBytes();
        // SPARC compares 32 or 64 bits
        if (compareBytes < left.getPlatformKind().getSizeInBytes()) {
            left = arithmeticLIRGen.emitSignExtend(left, compareBytes * 8, XWORD.getSizeInBytes() * 8);
        }
        if (compareBytes < right.getPlatformKind().getSizeInBytes()) {
            right = arithmeticLIRGen.emitSignExtend(right, compareBytes * 8, XWORD.getSizeInBytes() * 8);
        }

OK, I give up.  That must be the only way to do it.

Andrew.


More information about the graal-dev mailing list