Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gets try_spilled_reg_mem error when compile the code with optimize level 1 #410

Open
rogerchang23424 opened this issue Jul 8, 2024 · 0 comments

Comments

@rogerchang23424
Copy link

rogerchang23424 commented Jul 8, 2024

MIR code

File test.mir:

mod:     module
store_proto:    proto   u8, p:mctx, u32:addr, u64:value
trap_proto:     proto   p:mctx, u8:cause, u32:tval
f:     func    p, p:mctx
        local   i64:gen_reg_7, i64:gen_reg_8, i64:gen_reg_15, i64:gen_reg_9, i64:gen_reg_10, i64:gen_reg_11, i64:gen_reg_12, i64:gen_reg_13
        local   i64:zero_reg_1, i64:zero_reg_2, i64:zero_reg_3, i64:zero_reg_4, i64:zero_reg_5, i64:zero_reg_6, i64:gen_reg_1, i64:zero_reg_7
        local   i64:zero_reg_8, i64:zero_reg_9, i64:zero_reg_10, i64:zero_reg_11, i64:zero_reg_12, i64:gen_reg_24, i64:gen_reg_26, i64:mem_addr_13
        local   i64:fault_reg_14, i64:host_addr_15, i64:vpn_reg_16, i64:cmp_vpn_reg_17, i64:page_index_18, i64:align_offset_19, i64:gen_reg_17, i64:gen_reg_23
        local   i64:mem_addr_20, i64:fault_reg_21, i64:host_addr_22, i64:vpn_reg_23, i64:cmp_vpn_reg_24, i64:page_index_25, i64:align_offset_26, i64:gen_reg_16
        local   i64:mem_addr_27, i64:fault_reg_28, i64:host_addr_29, i64:vpn_reg_30, i64:cmp_vpn_reg_31, i64:page_index_32, i64:align_offset_33, i64:gen_reg_31
        local   i64:gen_reg_19, i64:mem_addr_34, i64:fault_reg_35, i64:host_addr_36, i64:vpn_reg_37, i64:cmp_vpn_reg_38, i64:page_index_39, i64:align_offset_40
        local   i64:gen_reg_14, i64:mem_addr_41, i64:fault_reg_42, i64:host_addr_43, i64:vpn_reg_44, i64:cmp_vpn_reg_45, i64:page_index_46, i64:align_offset_47
        local   i64:gen_reg_18, i64:mem_addr_48, i64:fault_reg_49, i64:host_addr_50, i64:vpn_reg_51, i64:cmp_vpn_reg_52, i64:page_index_53, i64:align_offset_54
        local   i64:gen_reg_4, i64:zero_reg_55, i64:mem_addr_56, i64:fault_reg_57, i64:host_addr_58, i64:vpn_reg_59, i64:cmp_vpn_reg_60, i64:page_index_61
        local   i64:align_offset_62, i64:gen_reg_22

# 1 arg, 82 locals, 0 globals
L1:
        mov     gen_reg_7, i32:32872(mctx)
L2:
        urshs   gen_reg_8, gen_reg_7, 7
        urshs   gen_reg_15, gen_reg_7, 25
        ors     gen_reg_8, gen_reg_8, gen_reg_15
        urshs   gen_reg_9, gen_reg_8, 7
        urshs   gen_reg_15, gen_reg_8, 25
        ors     gen_reg_9, gen_reg_9, gen_reg_15
        urshs   gen_reg_10, gen_reg_9, 7
        urshs   gen_reg_15, gen_reg_9, 25
        ors     gen_reg_10, gen_reg_10, gen_reg_15
        urshs   gen_reg_11, gen_reg_10, 7
        urshs   gen_reg_15, gen_reg_10, 25
        ors     gen_reg_11, gen_reg_11, gen_reg_15
        urshs   gen_reg_12, gen_reg_11, 7
        urshs   gen_reg_15, gen_reg_11, 25
        ors     gen_reg_12, gen_reg_12, gen_reg_15
        urshs   gen_reg_13, gen_reg_12, 7
        urshs   gen_reg_15, gen_reg_12, 25
        ors     gen_reg_13, gen_reg_13, gen_reg_15
        adds    zero_reg_1, 0, 0
        adds    zero_reg_2, 0, 0
        adds    zero_reg_3, 0, 0
        adds    zero_reg_4, 0, 0
        adds    zero_reg_5, 0, 0
        adds    zero_reg_6, 0, 0
        mov     gen_reg_1, 2147508576
        adds    gen_reg_1, gen_reg_1, 4294967220
        adds    zero_reg_7, 0, 0
        adds    zero_reg_8, 0, 0
        adds    zero_reg_9, 0, 0
        adds    zero_reg_10, 0, 0
        adds    zero_reg_11, 0, 0
        adds    zero_reg_12, 0, 0
        mov     gen_reg_24, 1431654400
        adds    gen_reg_24, gen_reg_24, 1364
        adds    gen_reg_26, 0, 6
        subs    gen_reg_26, gen_reg_24, gen_reg_26
        adds    mem_addr_13, gen_reg_1, 0
        uext32  mem_addr_13, mem_addr_13
        urshs   vpn_reg_16, mem_addr_13, 8
        ands    page_index_18, vpn_reg_16, 255
        mov     cmp_vpn_reg_17, u64:24664(mctx, page_index_18, 32)
        bnes    L4, cmp_vpn_reg_17, vpn_reg_16
        and     align_offset_19, mem_addr_13, 3
        bt      L4, align_offset_19
        mov     host_addr_15, u64:24648(mctx, page_index_18, 32)
        add     host_addr_15, host_addr_15, mem_addr_13
        mov     u32:(host_addr_15), gen_reg_26
        add     i32:40(mctx), i32:40(mctx), 1
        jmp     L3
L4:
        call    store_proto, 139627793115072, fault_reg_14, mctx, mem_addr_13, gen_reg_26
        beqs    L3, fault_reg_14, 64
        mov     i32:32848(mctx), gen_reg_1
        mov     i32:32876(mctx), gen_reg_8
        mov     i32:32880(mctx), gen_reg_9
        mov     i32:32884(mctx), gen_reg_10
        mov     i32:32888(mctx), gen_reg_11
        mov     i32:32892(mctx), gen_reg_12
        mov     i32:32896(mctx), gen_reg_13
        mov     i32:32904(mctx), gen_reg_15
        mov     i32:32940(mctx), gen_reg_24
        mov     i32:32948(mctx), gen_reg_26
L5:
        mov     i32:32840(mctx), 2147484048
        add     u64:8(mctx), u64:8(mctx), 37
        add     u64:24(mctx), u64:24(mctx), 37
        call    trap_proto, 139627792808448, mctx, fault_reg_14, mem_addr_13
        ret     0
L3:
        mov     gen_reg_17, 33554432
        mov     gen_reg_17, 33554432
        subs    gen_reg_23, gen_reg_17, gen_reg_17
        adds    mem_addr_20, gen_reg_1, 4
        uext32  mem_addr_20, mem_addr_20
        urshs   vpn_reg_23, mem_addr_20, 8
        ands    page_index_25, vpn_reg_23, 255
        mov     cmp_vpn_reg_24, u64:24664(mctx, page_index_25, 32)
        bnes    L7, cmp_vpn_reg_24, vpn_reg_23
        and     align_offset_26, mem_addr_20, 3
        bt      L7, align_offset_26
        mov     host_addr_22, u64:24648(mctx, page_index_25, 32)
        add     host_addr_22, host_addr_22, mem_addr_20
        mov     u32:(host_addr_22), gen_reg_23
        add     i32:40(mctx), i32:40(mctx), 1
        jmp     L6
L7:
        call    store_proto, 139627793115072, fault_reg_21, mctx, mem_addr_20, gen_reg_23
        beqs    L6, fault_reg_21, 64
        mov     i32:32848(mctx), gen_reg_1
        mov     i32:32876(mctx), gen_reg_8
        mov     i32:32880(mctx), gen_reg_9
        mov     i32:32884(mctx), gen_reg_10
        mov     i32:32888(mctx), gen_reg_11
        mov     i32:32892(mctx), gen_reg_12
        mov     i32:32896(mctx), gen_reg_13
        mov     i32:32904(mctx), gen_reg_15
        mov     i32:32912(mctx), gen_reg_17
        mov     i32:32936(mctx), gen_reg_23
        mov     i32:32940(mctx), gen_reg_24
        mov     i32:32948(mctx), gen_reg_26
L8:
        mov     i32:32840(mctx), 2147484064
        add     u64:8(mctx), u64:8(mctx), 41
        add     u64:24(mctx), u64:24(mctx), 41
        call    trap_proto, 139627792808448, mctx, fault_reg_21, mem_addr_20
        ret     0
L6:
        adds    gen_reg_16, 0, 4294967289
        adds    gen_reg_16, 0, 4294967289
        subs    gen_reg_16, gen_reg_16, gen_reg_16
        adds    mem_addr_27, gen_reg_1, 8
        uext32  mem_addr_27, mem_addr_27
        urshs   vpn_reg_30, mem_addr_27, 8
        ands    page_index_32, vpn_reg_30, 255
        mov     cmp_vpn_reg_31, u64:24664(mctx, page_index_32, 32)
        bnes    L10, cmp_vpn_reg_31, vpn_reg_30
        and     align_offset_33, mem_addr_27, 3
        bt      L10, align_offset_33
        mov     host_addr_29, u64:24648(mctx, page_index_32, 32)
        add     host_addr_29, host_addr_29, mem_addr_27
        mov     u32:(host_addr_29), gen_reg_16
        add     i32:40(mctx), i32:40(mctx), 1
        jmp     L9
L10:
        call    store_proto, 139627793115072, fault_reg_28, mctx, mem_addr_27, gen_reg_16
        beqs    L9, fault_reg_28, 64
        mov     i32:32848(mctx), gen_reg_1
        mov     i32:32876(mctx), gen_reg_8
        mov     i32:32880(mctx), gen_reg_9
        mov     i32:32884(mctx), gen_reg_10
        mov     i32:32888(mctx), gen_reg_11
        mov     i32:32892(mctx), gen_reg_12
        mov     i32:32896(mctx), gen_reg_13
        mov     i32:32904(mctx), gen_reg_15
        mov     i32:32908(mctx), gen_reg_16
        mov     i32:32912(mctx), gen_reg_17
        mov     i32:32936(mctx), gen_reg_23
        mov     i32:32940(mctx), gen_reg_24
        mov     i32:32948(mctx), gen_reg_26
L11:
        mov     i32:32840(mctx), 2147484080
        add     u64:8(mctx), u64:8(mctx), 45
        add     u64:24(mctx), u64:24(mctx), 45
        call    trap_proto, 139627792808448, mctx, fault_reg_28, mem_addr_27
        ret     0
L9:
        adds    gen_reg_31, 0, 4294967293
        mov     gen_reg_19, 1717985280
        adds    gen_reg_19, gen_reg_19, 1637
        subs    gen_reg_31, gen_reg_31, gen_reg_19
        adds    mem_addr_34, gen_reg_1, 12
        uext32  mem_addr_34, mem_addr_34
        urshs   vpn_reg_37, mem_addr_34, 8
        ands    page_index_39, vpn_reg_37, 255
        mov     cmp_vpn_reg_38, u64:24664(mctx, page_index_39, 32)
        bnes    L13, cmp_vpn_reg_38, vpn_reg_37
        and     align_offset_40, mem_addr_34, 3
        bt      L13, align_offset_40
        mov     host_addr_36, u64:24648(mctx, page_index_39, 32)
        add     host_addr_36, host_addr_36, mem_addr_34
        mov     u32:(host_addr_36), gen_reg_31
        add     i32:40(mctx), i32:40(mctx), 1
        jmp     L12
L13:
        call    store_proto, 139627793115072, fault_reg_35, mctx, mem_addr_34, gen_reg_31
        beqs    L12, fault_reg_35, 64
        mov     i32:32848(mctx), gen_reg_1
        mov     i32:32876(mctx), gen_reg_8
        mov     i32:32880(mctx), gen_reg_9
        mov     i32:32884(mctx), gen_reg_10
        mov     i32:32888(mctx), gen_reg_11
        mov     i32:32892(mctx), gen_reg_12
        mov     i32:32896(mctx), gen_reg_13
        mov     i32:32904(mctx), gen_reg_15
        mov     i32:32908(mctx), gen_reg_16
        mov     i32:32912(mctx), gen_reg_17
        mov     i32:32920(mctx), gen_reg_19
        mov     i32:32936(mctx), gen_reg_23
        mov     i32:32940(mctx), gen_reg_24
        mov     i32:32948(mctx), gen_reg_26
        mov     i32:32968(mctx), gen_reg_31
L14:
        mov     i32:32840(mctx), 2147484100
        add     u64:8(mctx), u64:8(mctx), 50
        add     u64:24(mctx), u64:24(mctx), 50
        call    trap_proto, 139627792808448, mctx, fault_reg_35, mem_addr_34
        ret     0
L12:
        mov     gen_reg_23, 524288
        mov     gen_reg_14, 524288
        subs    gen_reg_8, gen_reg_23, gen_reg_14
        adds    mem_addr_41, gen_reg_1, 16
        uext32  mem_addr_41, mem_addr_41
        urshs   vpn_reg_44, mem_addr_41, 8
        ands    page_index_46, vpn_reg_44, 255
        mov     cmp_vpn_reg_45, u64:24664(mctx, page_index_46, 32)
        bnes    L16, cmp_vpn_reg_45, vpn_reg_44
        and     align_offset_47, mem_addr_41, 3
        bt      L16, align_offset_47
        mov     host_addr_43, u64:24648(mctx, page_index_46, 32)
        add     host_addr_43, host_addr_43, mem_addr_41
        mov     u32:(host_addr_43), gen_reg_8
        add     i32:40(mctx), i32:40(mctx), 1
        jmp     L15
L16:
        call    store_proto, 139627793115072, fault_reg_42, mctx, mem_addr_41, gen_reg_8
        beqs    L15, fault_reg_42, 64
        mov     i32:32848(mctx), gen_reg_1
        mov     i32:32876(mctx), gen_reg_8
        mov     i32:32880(mctx), gen_reg_9
        mov     i32:32884(mctx), gen_reg_10
        mov     i32:32888(mctx), gen_reg_11
        mov     i32:32892(mctx), gen_reg_12
        mov     i32:32896(mctx), gen_reg_13
        mov     i32:32900(mctx), gen_reg_14
        mov     i32:32904(mctx), gen_reg_15
        mov     i32:32908(mctx), gen_reg_16
        mov     i32:32912(mctx), gen_reg_17
        mov     i32:32920(mctx), gen_reg_19
        mov     i32:32936(mctx), gen_reg_23
        mov     i32:32940(mctx), gen_reg_24
        mov     i32:32948(mctx), gen_reg_26
        mov     i32:32968(mctx), gen_reg_31
L17:
        mov     i32:32840(mctx), 2147484116
        add     u64:8(mctx), u64:8(mctx), 54
        add     u64:24(mctx), u64:24(mctx), 54
        call    trap_proto, 139627792808448, mctx, fault_reg_42, mem_addr_41
        ret     0
L15:
        mov     gen_reg_13, 4227858432
        adds    gen_reg_13, gen_reg_13, 4294967295
        mov     gen_reg_24, 2147483648
        subs    gen_reg_18, gen_reg_13, gen_reg_24
        adds    mem_addr_48, gen_reg_1, 20
        uext32  mem_addr_48, mem_addr_48
        urshs   vpn_reg_51, mem_addr_48, 8
        ands    page_index_53, vpn_reg_51, 255
        mov     cmp_vpn_reg_52, u64:24664(mctx, page_index_53, 32)
        bnes    L19, cmp_vpn_reg_52, vpn_reg_51
        and     align_offset_54, mem_addr_48, 3
        bt      L19, align_offset_54
        mov     host_addr_50, u64:24648(mctx, page_index_53, 32)
        add     host_addr_50, host_addr_50, mem_addr_48
        mov     u32:(host_addr_50), gen_reg_18
        add     i32:40(mctx), i32:40(mctx), 1
        jmp     L18
L19:
        call    store_proto, 139627793115072, fault_reg_49, mctx, mem_addr_48, gen_reg_18
        beqs    L18, fault_reg_49, 64
        mov     i32:32848(mctx), gen_reg_1
        mov     i32:32876(mctx), gen_reg_8
        mov     i32:32880(mctx), gen_reg_9
        mov     i32:32884(mctx), gen_reg_10
        mov     i32:32888(mctx), gen_reg_11
        mov     i32:32892(mctx), gen_reg_12
        mov     i32:32896(mctx), gen_reg_13
        mov     i32:32900(mctx), gen_reg_14
        mov     i32:32904(mctx), gen_reg_15
        mov     i32:32908(mctx), gen_reg_16
        mov     i32:32912(mctx), gen_reg_17
        mov     i32:32916(mctx), gen_reg_18
        mov     i32:32920(mctx), gen_reg_19
        mov     i32:32936(mctx), gen_reg_23
        mov     i32:32940(mctx), gen_reg_24
        mov     i32:32948(mctx), gen_reg_26
        mov     i32:32968(mctx), gen_reg_31
L20:
        mov     i32:32840(mctx), 2147484136
        add     u64:8(mctx), u64:8(mctx), 59
        add     u64:24(mctx), u64:24(mctx), 59
        call    trap_proto, 139627792808448, mctx, fault_reg_49, mem_addr_48
        ret     0
L18:
        adds    gen_reg_12, 0, 32
        adds    gen_reg_4, 0, 0
        subs    zero_reg_55, gen_reg_12, gen_reg_4
        adds    mem_addr_56, gen_reg_1, 24
        uext32  mem_addr_56, mem_addr_56
        urshs   vpn_reg_59, mem_addr_56, 8
        ands    page_index_61, vpn_reg_59, 255
        mov     cmp_vpn_reg_60, u64:24664(mctx, page_index_61, 32)
        bnes    L22, cmp_vpn_reg_60, vpn_reg_59
        and     align_offset_62, mem_addr_56, 3
        bt      L22, align_offset_62
        mov     host_addr_58, u64:24648(mctx, page_index_61, 32)
        add     host_addr_58, host_addr_58, mem_addr_56
        mov     u32:(host_addr_58), 0
        add     i32:40(mctx), i32:40(mctx), 1
        jmp     L21
L22:
        call    store_proto, 139627793115072, fault_reg_57, mctx, mem_addr_56, 0
        beqs    L21, fault_reg_57, 64
        mov     i32:32848(mctx), gen_reg_1
        mov     i32:32860(mctx), gen_reg_4
        mov     i32:32876(mctx), gen_reg_8
        mov     i32:32880(mctx), gen_reg_9
        mov     i32:32884(mctx), gen_reg_10
        mov     i32:32888(mctx), gen_reg_11
        mov     i32:32892(mctx), gen_reg_12
        mov     i32:32896(mctx), gen_reg_13
        mov     i32:32900(mctx), gen_reg_14
        mov     i32:32904(mctx), gen_reg_15
        mov     i32:32908(mctx), gen_reg_16
        mov     i32:32912(mctx), gen_reg_17
        mov     i32:32916(mctx), gen_reg_18
        mov     i32:32920(mctx), gen_reg_19
        mov     i32:32936(mctx), gen_reg_23
        mov     i32:32940(mctx), gen_reg_24
        mov     i32:32948(mctx), gen_reg_26
        mov     i32:32968(mctx), gen_reg_31
L23:
        mov     i32:32840(mctx), 2147484152
        add     u64:8(mctx), u64:8(mctx), 63
        add     u64:24(mctx), u64:24(mctx), 63
        call    trap_proto, 139627792808448, mctx, fault_reg_57, mem_addr_56
        ret     0
L21:
        mov     gen_reg_22, 3758096384
        add     u64:8(mctx), u64:8(mctx), 64
        add     u64:24(mctx), u64:24(mctx), 64
        mov     i32:32848(mctx), gen_reg_1
        mov     i32:32860(mctx), gen_reg_4
        mov     i32:32876(mctx), gen_reg_8
        mov     i32:32880(mctx), gen_reg_9
        mov     i32:32884(mctx), gen_reg_10
        mov     i32:32888(mctx), gen_reg_11
        mov     i32:32892(mctx), gen_reg_12
        mov     i32:32896(mctx), gen_reg_13
        mov     i32:32900(mctx), gen_reg_14
        mov     i32:32904(mctx), gen_reg_15
        mov     i32:32908(mctx), gen_reg_16
        mov     i32:32912(mctx), gen_reg_17
        mov     i32:32916(mctx), gen_reg_18
        mov     i32:32920(mctx), gen_reg_19
        mov     i32:32932(mctx), gen_reg_22
        mov     i32:32936(mctx), gen_reg_23
        mov     i32:32940(mctx), gen_reg_24
        mov     i32:32948(mctx), gen_reg_26
        mov     i32:32968(mctx), gen_reg_31
        mov     i32:32840(mctx), 2147484160
        ret     0
        endfunc
        endmodule

File test_mir.cpp

#include "mir.h"
#include "mir-gen.h"

#include <cstdlib>
#include <string>
#include <vector>

int main() {
  std::vector<char> s;
  {
    FILE* fp = fopen("test.mir", "rb");
    fseek(fp, 0, SEEK_END);
    long file_size = ftell(fp);
    s.resize(file_size);
    fseek(fp, 0, SEEK_SET);
    size_t read_size = fread(s.data(), 1, file_size, fp);
    assert(read_size == file_size);
  }

  MIR_context_t ctx = MIR_init();

  MIR_scan_string(ctx, s.data());

  MIR_module_t mir_module = DLIST_HEAD (MIR_module_t, *MIR_get_module_list (ctx));

  MIR_load_module(ctx, mir_module);

  MIR_gen_init(ctx);
  MIR_gen_set_optimize_level(ctx, 1);
  MIR_link(ctx, MIR_set_gen_interface, NULL);
  MIR_gen_finish(ctx);

  MIR_finish(ctx);
}

Terminal Output:

Fatal failure in matching insn: subs    hr10, hr10, i64:48(hr4)

debug output:

rvbt: mir-gen.c:7933: try_spilled_reg_mem: Assertion `n < 2' failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant