This is an archive of the discontinued LLVM Phabricator instance.

[LICM] Don't hoist threadlocals within presplit coroutines
ClosedPublic

Authored by ChuanqiXu on May 30 2023, 8:51 PM.

Details

Summary

Close https://github.com/llvm/llvm-project/issues/63022

This is the following of https://reviews.llvm.org/D135550, which is discussed in https://discourse.llvm.org/t/rfc-unify-memory-effect-attributes/65579. In my imagination, we could fix the issue fundamentally after we introduces new memory kind thread id. But I am not very sure if we can fix the issue fundamentally in time.

Besides that, I think the correctness is the most important. So it should not be bad to land this given it is innocent.

Diff Detail

Event Timeline

ChuanqiXu created this revision.May 30 2023, 8:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2023, 8:51 PM
ChuanqiXu requested review of this revision.May 30 2023, 8:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2023, 8:51 PM
nikic added inline comments.Jun 1 2023, 12:27 PM
llvm/lib/Transforms/Scalar/LICM.cpp
1228 ↗(On Diff #526884)

Why is this specific to threadlocal_address? Don't you have the same problem with all readnone/readonly functions, which might be based on thread-local state internally?

ChuanqiXu updated this revision to Diff 527702.Jun 1 2023, 7:12 PM

Address comments.

ChuanqiXu marked an inline comment as done.Jun 1 2023, 7:13 PM
ChuanqiXu added inline comments.
llvm/lib/Transforms/Scalar/LICM.cpp
1228 ↗(On Diff #526884)

Oh, sorry. This was an oversight.

nikic added inline comments.Jun 5 2023, 12:04 AM
llvm/lib/Transforms/Scalar/LICM.cpp
1228 ↗(On Diff #527702)

Can you please move this to the existing Behavior check below?

ChuanqiXu updated this revision to Diff 528683.Jun 5 2023, 10:17 PM
ChuanqiXu marked an inline comment as done.

Address comments.

ChuanqiXu marked an inline comment as done.Jun 5 2023, 10:18 PM
ChuanqiXu added inline comments.
llvm/lib/Transforms/Scalar/LICM.cpp
1228 ↗(On Diff #527702)

Done. Sorry for not noticing it.

fplk added a subscriber: fplk.Jun 6 2023, 11:29 AM
fplk added inline comments.
llvm/lib/Transforms/Scalar/LICM.cpp
1240 ↗(On Diff #528683)

I'm wondering if the new check could be unified with this check to simplify code; they both seem to check for onlyReadsMemory. I didn't double-check yet, but from the naming it seems that onlyReadsMemory and doesNotAccessMemory are mutually exclusive so we can safely move the check to below.

nikic accepted this revision.Jun 6 2023, 12:59 PM

LGTM

llvm/lib/Transforms/Scalar/LICM.cpp
1231 ↗(On Diff #528683)

We -> we

1240 ↗(On Diff #528683)

doesNotAccessMemory() also implies onlyReadsMemory(). So I think it's okay to do the separate check that covers both branches.

llvm/test/Transforms/LICM/sink-with-coroutine.ll
55

Please precommit the new test together with a run of update_test_checks.py on the file.

This revision is now accepted and ready to land.Jun 6 2023, 12:59 PM
This revision was automatically updated to reflect the committed changes.
ChuanqiXu marked an inline comment as done.

Thanks for reviewing!