cpuex2019-1 / compiler

Other
0 stars 0 forks source link

覗き穴最適化をする #9

Open okuraofvegetable opened 4 years ago

okuraofvegetable commented 4 years ago
okuraofvegetable commented 4 years ago

グローバル配列、タプルの埋め込みによりグローバル配列へのアクセスは定数番地へのアクセスに変わる。アクセスのコード片をのぞき穴で最適化できる

okuraofvegetable commented 4 years ago

solver_secondの周辺でやばめの断片が大量に見える

    lw  $6, 32($2)
    lw  $6, 28($2)
    lw  $6, 24($2)
    lw  $6, 20($2)
    lw  $6, 16($2)
    lw  $6, 12($2)
    lw  $6, 8($2)
    lw  $6, 4($2)
    lw  $6, 0($2)
okuraofvegetable commented 4 years ago

redundantなloadと定数畳みこみ(Liした直後に同じレジスタにaddiするのを1回のLiにする)をやった ある程度効果はあったっぽい(48億->40億くらい)

okuraofvegetable commented 4 years ago

solver系関数(死ぬほど呼ばれる)内に上のような冗長なlwがまだあった。自分の想定しているパターンに引っかかっていないのでasmをプリントして構造を特定して取り除こうと思う。

okuraofvegetable commented 4 years ago

IfEq(x,y,e1,e2)のe1,e2,とかに最適化か届いていなかった。Asm.t用とAsm.exp用の関数をつくって相互再帰させてとりあえず冗長なloadはだいたい消した。

okuraofvegetable commented 4 years ago

この改善で39億(1st,最適化なしinline100)から33.7億に。13%程度削減できた

okuraofvegetable commented 4 years ago

inline100の26587行目くらいを見ると

    addi    $10, $0, 3624
    add $30, $0, $10
    sf  $f0, 0($30)

というパターンが見えた、これはStw(hoge,x,V(reg_zero))の形の時に無駄な計算をしている。これをStw(hoge,x,C(0))に置き換えるような最適化をする

okuraofvegetable commented 4 years ago

Let((y1,t1),Lwz(x1,i1),Let((y2,t2),Lwz(x2,i2),e1)) の時i2がV(y1)となる可能性を考慮していなかった、i2にy1が入っていないかチェックするようにしたら直った

okuraofvegetable commented 4 years ago
addi $9,$9,3004
lw $5, 4($9)

みたいなものを

lw $5, 3008($9)
addi $9,$9,3004

に置き換えた (後ろに移ったaddiは不要定義削除で消える可能性があるので嬉しい)