Skip to content

Stop using registers for computation #3

@aceinetx

Description

@aceinetx

Right now this code:

int num(){
        return 2+2*2;
}

int main(){
        return num() + (num()-1);
}

Compiles to this (no constant folding, qproc backend)

num:
movi r0 2
movi r1 2
movi r2 2
mul r1 r2
add r0 r1
pop ip
main:
call num
call num
movi r0 1
sub r0 r0
add r0 r0
pop ip

This is just wrong and doesn't work as expected, I think we should use push/pop to compute values, something like this

num:
push 2
push 2
push 2
pop r1
pop r0
mul r0 r1
push r0
pop r1
pop r0
add r0 r1
; mov r0 r0 optimized out
pop ip
main:
call num
push r0
call num
push r0
push 1
pop r1
pop r0
sub r0 r1
push r0
pop r1
pop r0
add r0 r1
; mov r0 r0 optimized out
pop ip

This is larger, we can probably make some optimizations to it later, but it eliminates the need for register allocation, and works as expected

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions