Fix remaining -O1 tests: t/pmc/nci: 39, 41, 44-45 #1037

Closed
rurban opened this Issue Feb 27, 2014 · 3 comments

Comments

Projects
None yet
1 participant
Member

rurban commented Feb 27, 2014

rakudo should be able to use at least -O1 safely.

-O2 would be even better, but they do their own optimizations.

@rurban rurban self-assigned this Feb 27, 2014

Member

rurban commented Feb 27, 2014

m -s parrot_old && ./parrot_old -d61 -O1 -o t/pmc/nci_39-O1.pbc t/pmc/nci_39.pir

opt1 0x123b3f0 set sleep_cnt, 0
  => 0x123d210 null sleep_cnt
opt1 0x123b660 add sleep_cnt, 1
  => 0x123b3f0 inc sleep_cnt
loop LOOP -> FINISHED converted to post-test, added label LOOP_post1
block 1 label LOOP deleted

It is doing a branch_cond_loop_swap, converts conditional loops to post-test

./pbc_disassemble -b pure pbc vs -O1 pbc =>

    set_args_pc PMC_CONST(1), P3, P5
    invokecc_p P2
    get_results_pc PMC_CONST(0)
-   set_i_ic I0,0
-L3:    add_i_ic I0,1
+   null_i I0
+   inc_i I0
    get_global_p_sc P4,"cb_done"
    if_p_ic P4,L1
-   lt_ic_i_ic 10000,I0,L2
-   branch_ic L3
+L3:    lt_ic_i_ic 10000,I0,L2
+   inc_i I0
+   get_global_p_sc P4,"cb_done"
+   unless_p_ic P4,L3
 L1:    print_sc "the callback has run"
    end 
 L2:    print_sc "the callback didnt r"

rurban pushed a commit that referenced this issue Feb 27, 2014

[test] TODO remaining failing -O1 nci tests [GH #1037]
mark the 4 failing -O1 nci tests as TODO
Member

rurban commented Feb 27, 2014

branch_cond_loop_swap essentially converts in t/pmc/nci_39.pir

    .local int sleep_cnt
    sleep_cnt = 0
LOOP:
    sleep_cnt += 1
    .local pmc callback_has_run
    callback_has_run = get_global "cb_done"
    if callback_has_run goto FINISHED
    if sleep_cnt > 10000 goto ERROR
    goto LOOP
FINISHED:
    print "the callback has run\n"
    end
ERROR:
    print "the callback didnt run\n"
    end

to

    .local int sleep_cnt
    sleep_cnt = 1
    .local pmc callback_has_run
    callback_has_run = get_global "cb_done"
    if callback_has_run goto FINISHED
LOOP_post:
    if sleep_cnt > 10000 goto ERROR
    inc sleep_cnt
    callback_has_run = get_global "cb_done"
    unless callback_has_run goto LOOP_post
FINISHED:
    print "the callback has run\n"
    end
ERROR:
    print "the callback didnt run\n"
    end

This optimization looks good to me. I fail to see the problem, which seems to be nci specific.

rurban pushed a commit that referenced this issue Feb 27, 2014

[immc] Fixed -O1. Special-case get_global for branch_cond_loop_swap [GH
#1037]

See #1037 for the nci problem.
I couldn't see any logical problem with the attempted optimization

add I0,1 vs inc I0 tested ok.
just a get_global_p with if_p_ic P4,out converted to unless_p_ic P4,loop
was problematic, so we skip optimizing such loops.
get_global has no type attached, so we need to STREQ

added a IMCC_debug DEBUG_OPT1 notice for this case.

@rurban rurban closed this Feb 27, 2014

Member

rurban commented Feb 27, 2014

-O1 benchmarks / time make test vs make testO1

this includes the longer compile times:
time perl t/harness t/benchmark/\*.t; time perl t/harness -O1 t/benchmark/\*.t;

0m33.498s - 0m32.306s

without compile-time:

for t in t/benchmark/*.pir; do 
  ./parrot -O2 -o $t.O2.pbc $t; 
  ./parrot -O1 -o $t.O1.pbc $t; 
  ./parrot -o $t.O0.pbc $t;
done
$ time for t in t/benchmark/*.O0.pbc; do ./parrot $t >/dev/null; done
real    0m17.428s
$ time for t in t/benchmark/*.O1.pbc; do ./parrot $t >/dev/null; done
real    0m16.269s
$ time for t in t/benchmark/*.O2.pbc; do ./parrot $t >/dev/null; done
real    0m16.235s

perl t/harness --gc-debug --runcore-tests
1m17.267s

perl t/harness --gc-debug -O1 --runcore-tests
1m18.012s

perl t/harness -f --runcore-tests
1m16.640s

perl t/harness -f -O1 --runcore-tests
1m17.022s

perl t/harness -f -O2 --runcore-tests # with lot of SEGVs
1m16.902s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment