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

Emission of unnecessary jumps #2929

Open
xclerc opened this issue Aug 15, 2024 · 0 comments
Open

Emission of unnecessary jumps #2929

xclerc opened this issue Aug 15, 2024 · 0 comments

Comments

@xclerc
Copy link
Contributor

xclerc commented Aug 15, 2024

The following code:

let[@inline never] failure _ = failwith "..."

type t =
  | A
  | B
  | C

let of_int_exn = function
  | 0 -> A
  | 1 -> B
  | 2 -> C
  | n -> failure n

generates:

        cmpq    $5, %rax
        jbe     .L1
        jmp     camlA__failure_0_2_code@PLT
.L1:
        ret

which is rather good, but contains one unnecessary jump.

The reason why it is not optimized away is that the CFG
representation does not see two jumps, but only a conditional
jump and a (direct) tail call.

It seems possible to slightly alter the CFG representation
so that for instance the destinations of conditional jumps
are not mere labels but symbols.

However, doing so would have an impact on a number
of existing passes, for instance the jump-on-jump optimization
or the zero-alloc checker.

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

No branches or pull requests

1 participant