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

stage2: Teach Liveness that some safety checks do not observably modify memory #13233

Merged
merged 1 commit into from
Dec 12, 2022

Conversation

topolarity
Copy link
Contributor

@topolarity topolarity commented Oct 20, 2022

Spun off from #13074

This is a crude pattern match for try-like .cond_br blocks emitted by Sema's safety checks. It looks for:

 %x = block(void, {
    cond_br(..., {
      br(%x, @Zir.Inst.Ref.void_value)
    }, {
      call(...)
    })
  })

This matches the signature of many of our safety checks which look like this:

  %14 = ... ; generate check condition
  %23!= block(void, {
    %24!= cond_br(%14!, {
      %13! %21!
      %25!= br(%23, @Zir.Inst.Ref.void_value)
    }, {
      %22!= call(%21!, [%12, %13!])
    })
  })

The reasoning here is that control flow either diverges (the call must be noreturn to be at the end of the block) or continues directly to the following instructions in the block without modifying memory. This was inspired by #11772 (comment)

Resolves #12215

@topolarity topolarity force-pushed the liveness-peephole branch 2 times, most recently from b50f20e to df64831 Compare October 20, 2022 07:18
This change adds to Liveness a simple pattern match for the
try-like `.condbr` blocks emitted by Sema's safety checks. This
allows us to determine that these do not modify memory, which
permits us to elide additional loads in the backend.

As @Vexu points out in the main issue, this is probably not a
complete solution on its own. We'll still want a way to reliably
narrow the load/copy when performing several consecutive accesses,
such as `foo.arr[x][y].z`

Resolves ziglang#12215
@andrewrk andrewrk merged commit 25d3713 into ziglang:master Dec 12, 2022
@topolarity topolarity deleted the liveness-peephole branch December 14, 2022 16:57
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

Successfully merging this pull request may close these issues.

stage2 array access performance (boundchecks related?)
2 participants