Skip to content

is a0 not been treated as return value???? #72

@yuyang-ok

Description

@yuyang-ok

I am doing some test with wasmtime.
there is a very wired problem.
p10i is the a0 register.

test compile precise-output
set unwind_info=false
target riscv64
function %xxxxxxxxxx(i64 vmctx, i64) -> i64, f32, i64, f64, i32, f32, i64, i32 wasmtime_system_v {
    gv0 = vmctx
    gv1 = load.i64 notrap aligned readonly gv0+8
    gv2 = load.i64 notrap aligned gv1
    gv3 = vmctx
    sig0 = (i64 vmctx, i64) -> i64, f32, i64, f64, i32, f32, i64, i32 wasmtime_system_v
    fn0 = u0:0 sig0
    stack_limit = gv2

block0(v0: i64, v1: i64):
    v10 = global_value.i64 gv3
    v11 = load.i64 notrap aligned v10+72
    v12 = load.i64 notrap aligned v10+80
    v13, v14, v15, v16, v17, v18, v19, v20 = call_indirect sig0, v11(v12, v0)
    jump block1(v13, v14, v15, v16, v17, v18, v19, v20)

block1(v2: i64, v3: f32, v4: i64, v5: f64, v6: i32, v7: f32, v8: i64, v9: i32):
    return v2, v3, v4, v5, v6, v7, v8, v9
}

;   add sp,-16
;   sd ra,8(sp)
;   sd fp,0(sp)
;   unwind PushFrameRegs { offset_upward_to_caller_sp: 16 }
;   mv fp,sp
;   ld t6,8(a0)
;   ld t6,0(t6)
;   trap_ifc stk_ovf##(sp ult t6)
;   unwind DefineNewFrame { offset_upward_to_caller_sp: 16, offset_downward_to_clobbers: 16 }
;   unwind SaveReg { clobber_offset: 8, reg: p18i }
;   sd s2,-8(sp)
;   add sp,-16
; block0:
;   mv s2,a2
;   ld t3,72(a0)
;   ld t4,80(a0)
;   mv a1,a0
;   add sp,-48
;   virtual_sp_offset_adj +48
;   mv a0,t4
;   load_addr a2,0(sp)
;   callind t3
;   flw ft8,0(sp)
;   ld a2,8(sp)
;   fld ft0,16(sp)
;   lw a6,24(sp)
;   flw ft4,28(sp)
;   ld t0,32(sp)
;   lw t2,40(sp)
;   add sp,+48
;   virtual_sp_offset_adj -48
;   j label1
; block1:
;   mv a0,s2
;   fsw ft8,0(a0)
;   sd a2,8(a0)
;   fsd ft0,16(a0)
;   sw a6,24(a0)
;   fsw ft4,28(a0)
;   sd t0,32(a0)
;   sw t2,40(a0)
;   add sp,+16
;   ld s2,-8(sp)
;   ld ra,8(sp)
;   ld fp,0(sp)
;   add sp,+16
;   ret

the problem with this code is that register a0 , a0 contain the first result for the function. should not used for instruction like sd a2,8(a0), a0 is been overwrite to some address for store operation.

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