This is an archive of the discontinued LLVM Phabricator instance.

[LangRef] Add noreadafterunwind attribute
AbandonedPublic

Authored by nikic on Jan 3 2022, 4:08 AM.

Details

Summary

This introduces a noreadafterunwind attribute, which is intended to allow additional optimizations in DSE and MemCpyOpt. The simplest example is:

declare void @may_unwind()
define void @test(i32* noalias noreadafterunwind sret(i32) %out) {
    store i32 0, i32* %out
    call void @may_unwind()
    store i32 1, i32* %out
    ret void
}

Without the noreadafterunwind attribute, we can not eliminate the first store, because the call might unwind, and the caller may observe the state after the first store.

The attribute is currently defined in a way that does not make a read after unwind immediate UB and just makes it return poison instead. I'm open to making it immediate UB though, I don't think there's a lot of practical difference either way.

Frontends will likely want to annotate sret parameters with noreadafterunwind.

See https://lists.llvm.org/pipermail/llvm-dev/2021-December/154164.html for preliminary discussion on this.

Diff Detail

Event Timeline

nikic requested review of this revision.Jan 3 2022, 4:08 AM
nikic created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2022, 4:08 AM
nikic updated this revision to Diff 397807.Jan 6 2022, 12:35 AM
nikic retitled this revision from [LangRef] Add noreadonunwind attribute to [LangRef] Add noreadafterunwind attribute.
nikic edited the summary of this revision. (Show Details)

Rename to noreadafterunwind to clarify the this only limits reads after the unwind, not that the call itself can't read if it will later unwind.

nikic abandoned this revision.Jan 11 2022, 1:51 AM

Abandoning this in favor of D116998.