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

Merge Basic Blocks if possible #170

Open
reiner-dolp opened this issue Dec 9, 2018 · 2 comments
Open

Merge Basic Blocks if possible #170

reiner-dolp opened this issue Dec 9, 2018 · 2 comments
Labels
backend optimization 💪 New optimization feature
Projects
Milestone

Comments

@reiner-dolp
Copy link
Contributor

Currently, through optimization, sometimes nodes are split into a suboptimal amount of basic blocks, which might reduce the efficiency of subsequent optimizations.


The following is an example:

---
optimizations: [ConstantFolding,UnreachableCodeElimination]
expect:
    identical-to:
        is: |
          class UCE_If {
            public static void main(String[] args) {
              System.out.println(1);
            }
          }
        
stdout:
    is: "1\n"
---
class UCE_If {
  public static void main(String[] args) {
    if (true) {
        System.out.println(1);
    } else {
        System.out.println(0);
    }
  }
}

The ASM for the hand optimized routine is:

# -- Begin  mj_main
	.p2align 4,,15
	.globl mj_main
	.type	mj_main, @function
mj_main:
/*.L0:*/                          /* Block BB[108:2] preds: none, freq: 1.000 */
	pushq %rbp                       /* amd64_push_reg T[273:74] */
	mov %rsp, %rbp                   /* be_Copy Lu[276:77] */
	movl $0x1, %edi                  /* amd64_mov_imm Lu[207:11] */
	call mjrt_system_out_println@PLT    /* amd64_call T[208:12] */
	leave                            /* amd64_leave T[269:70] */
	ret                              /* amd64_ret X[216:20] */
	.size	mj_main, .-mj_main
# -- End  mj_main

The compiler optimized routine has unnecessary basic blocks, resulting in fallthroughs to be visible in the ASM:

mj_main:
/*.L800:*/                        /* Block BB[176:2] preds: none, freq: 1.000 */
    pushq %rbp                       /* amd64_push_reg T[635:78] */
    mov %rsp, %rbp                   /* be_Copy Lu[638:81] */
    /* fallthrough to .L801 */       /* amd64_jmp X[578:24] */
/*.L801:*/                        /* Block BB[189:10] preds: .L800, freq: 1.000 */
    movl $0x1, %edi                  /* amd64_mov_imm Lu[567:13] */
    call mjrt_system_out_println@PLT    /* amd64_call T[568:14] */
    /* fallthrough to .L802 */       /* amd64_jmp X[577:23] */
/*.L802:*/                        /* Block BB[215:9] preds: .L801, freq: 1.000 */
    leave                            /* amd64_leave T[631:74] */
    ret                              /* amd64_ret X[576:22] */
    .size    mj_main, .-mj_main
# -- End  mj_main
@reiner-dolp
Copy link
Contributor Author

reiner-dolp commented Dec 9, 2018

We also emit empty blocks during firm graph construction:

// FIXME: we're constructing an empty block here because we are only

@hediet hediet added the optimization 💪 New optimization feature label Dec 16, 2018
@joshuabach joshuabach added this to the Finale milestone Jan 4, 2019
@problame problame added this to Todo Optimization in Endspurt Feb 4, 2019
@problame
Copy link
Contributor

problame commented Feb 5, 2019

This would actually be "useful" for the backend, as some of our more esoteric crashes stem from unnecessarily split basic blocks (e.g. the problems in #217 with Cmp and Cond being spread over 2 BBs even though they could be in one).
Technically, it shouldn't matter for the backend, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend optimization 💪 New optimization feature
Projects
Endspurt
  
Todo Optimization
Development

No branches or pull requests

4 participants