Skip to content

[MemDep] Treat partial-overlap lifetime.start as a clobber (#211167) - #13544

Open
usama54321 wants to merge 2 commits into
swiftlang:stable/21.xfrom
usama54321:eng/u_hameed/gvn-pre-load-hoist-cherrypick
Open

[MemDep] Treat partial-overlap lifetime.start as a clobber (#211167)#13544
usama54321 wants to merge 2 commits into
swiftlang:stable/21.xfrom
usama54321:eng/u_hameed/gvn-pre-load-hoist-cherrypick

Conversation

@usama54321

Copy link
Copy Markdown

When getSimplePointerDependencyFrom scans backward and reaches a @llvm.lifetime.start, it only treated the marker as a barrier when the query location MustAliased the lifetime's argument, and otherwise fell through to continue. For a load through a GEP into part of an alloca the alias result is PartialAlias, so the scan walked past lifetime.start as if it weren't there, and GVN Load PRE would hoist the load above it.

Inspect the full alias result instead of just isMustAlias: MustAlias still returns Def and NoAlias still continues, but any partial/may overlap now returns a Clobber so lifetime.start acts as a barrier and the access cannot be moved above it.

Fixes llvm#194940

When getSimplePointerDependencyFrom scans backward and reaches a
@llvm.lifetime.start, it only treated the marker as a barrier when the
query location MustAliased the lifetime's argument, and otherwise fell
through to `continue`. For a load through a GEP into part of an alloca
the alias result is PartialAlias, so the scan walked past lifetime.start
as if it weren't there, and GVN Load PRE would hoist the load above it.

Inspect the full alias result instead of just isMustAlias: MustAlias
still returns Def and NoAlias still continues, but any partial/may
overlap now returns a Clobber so lifetime.start acts as a barrier and
the access cannot be moved above it.

Fixes llvm#194940
@usama54321
usama54321 requested a review from a team as a code owner July 28, 2026 21:48
@usama54321

Copy link
Copy Markdown
Author

@swift-ci test llvm

@usama54321
usama54321 requested review from hnrklssn and rapidsna July 30, 2026 21:13
@usama54321

Copy link
Copy Markdown
Author

@hnrklssn Just giving you headsup that I am cherrypicking the change on 21.x.

The second commit fixes a ubsan test where a check was getting optimized away before

@usama54321

Copy link
Copy Markdown
Author

@swift-ci test llvm

Follow-up to 5f88e49 (llvm#211167), which stops GVN from
folding a load of a partially-overlapping alloca access to undef. In
test15 that undef fed the local-bounds check, which then got deleted.

Since all indices for the fam are out of bounds, clang emits the
local-bounds trap at -O0, but -O2 was silently dropping it. The
regenerated checks now keep __ubsan_handle_local_out_of_bounds_abort on
that path. The rest of the diff is attribute group renumbering.
@usama54321
usama54321 force-pushed the eng/u_hameed/gvn-pre-load-hoist-cherrypick branch from 7d38464 to 6186477 Compare July 30, 2026 21:26
@usama54321

Copy link
Copy Markdown
Author

@swift-ci test llvm

@usama54321

Copy link
Copy Markdown
Author

@swift-ci test

@hnrklssn

Copy link
Copy Markdown
Member

Wouldn't this cherry-pick need to include the changes from #13528?

@usama54321

Copy link
Copy Markdown
Author

Hmm the test did not fail on the initial run. I just took a look and seems like a bunch of bounds safety work is missing/cherrypick of your change created a merge conflict. I will wait for the results for now

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.

2 participants