systems-nuts / unifico

Compiler and build harness for heterogeneous-ISA binaries with the same stack layout.
3 stars 1 forks source link

StackSlotColoring results in different order of stack slots #300

Open blackgeorge-boom opened 10 months ago

blackgeorge-boom commented 10 months ago
#include <stdio.h>

void results(char *name, char class, int n1, int n2, int n3, int niter, char *optype)
{

    printf("%c\n", class);

    if (n3 == 0) {
        long nn = n1;
        if (n2 != 0)
            nn *= n2;
        printf("%12ld\n", nn);
    }
    else
        printf("%4dx%4dx\n", n1, n2);

    printf("%12d\n", niter);
    printf("%24s\n", optype);

}

int main() {
    results("IS", 'S', 1, 64, 0, 3, "keys ranked");

    return 0;

}
make clean; make stackmaps-check -j10 OBJDUMP_FLAGS= OPT_LEVEL=-O1

WARNING: results: callsite 0, value locations 1/1 have different location offset or  different constant (-48 vs. -32)
WARNING: results: callsite 0, value locations 2/2 have different location offset or  different constant (-28 vs. -44)
WARNING: results: callsite 0, value locations 3/3 have different location offset or  different constant (-36 vs. -40)
...
blackgeorge-boom commented 10 months ago

Before and after stack slot coloring:

arm

32B   STRWui $w4, %stack.1, 0 :: (store 4 into %stack.1)
48B   STRWui $w3, %stack.2, 0 :: (store 4 into %stack.2)
64B   STRXui $x2, %stack.3, 0 :: (store 8 into %stack.3)
# becomes
32B   STRWui $w4, %stack.2, 0 :: (store 4 into %stack.2)
48B   STRWui $w3, %stack.0, 0 :: (store 4 into %stack.0)
64B   STRXui $x2, %stack.3, 0 :: (store 8 into %stack.3)

x86

32B   MOV32mr %stack.1, 1, $noreg, 0, $noreg, $r8d :: (store 4 into %stack.1)
48B   MOV32mr %stack.2, 1, $noreg, 0, $noreg, $ecx :: (store 4 into %stack.2)
64B   renamable $edx = KILL $edx, implicit-def $rdx
72B   MOV64mr %stack.3, 1, $noreg, 0, $noreg, killed renamable $rdx :: (store 8 into %stack.3)
# becomes
32B   MOV32mr %stack.2, 1, $noreg, 0, $noreg, $r8d :: (store 4 into %stack.2)
48B   MOV32mr %stack.3, 1, $noreg, 0, $noreg, $ecx :: (store 4 into %stack.3)
64B   renamable $edx = KILL $edx, implicit-def $rdx
72B   MOV64mr %stack.0, 1, $noreg, 0, $noreg, killed renamable $rdx :: (store 8 into %stack.0)