-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[BasicAA][TLI] Treat local-linkage globals or known environments as not aliasing errno #170290
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
46df14b
fee1d59
06294b9
33dea37
2775070
39819a3
05a7a9f
f8a42c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1870,8 +1870,21 @@ AliasResult BasicAAResult::aliasErrno(const MemoryLocation &Loc, | |
| Loc.Size.getValue().getKnownMinValue() * 8 > TLI.getIntSize()) | ||
| return AliasResult::NoAlias; | ||
|
|
||
| if (isIdentifiedFunctionLocal(getUnderlyingObject(Loc.Ptr))) | ||
| const Value *Object = getUnderlyingObject(Loc.Ptr); | ||
| if (isIdentifiedFunctionLocal(Object)) | ||
| return AliasResult::NoAlias; | ||
|
|
||
| if (auto *GV = dyn_cast<GlobalVariable>(Object)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need additional logic for GlobalAlias? Or has it been handled by other places?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't believe so - if a GlobalAlias turns out to be a GlobalVariable, getUnderlyingObject() should tell us that. |
||
| // Errno cannot alias internal/private globals. | ||
| if (GV->hasLocalLinkage()) | ||
| return AliasResult::NoAlias; | ||
|
|
||
| // Neither can it alias globals where environments define it as a function | ||
| // call, nor can a non-thread-local global alias a thread-local errno. | ||
| if (!TLI.mayBeErrnoGlobal(GV)) | ||
| return AliasResult::NoAlias; | ||
| } | ||
|
|
||
| return AliasResult::MayAlias; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 | ||
| ; RUN: opt -S -mtriple=arm64-apple-macos -passes=instcombine < %s | FileCheck %s | ||
|
|
||
| @errno = external global i32 | ||
|
|
||
| ; non-tls errno global variable does not alias errno when known to be a thread-local variable, | ||
| ; can do constant store-to-load forwarding. | ||
| define i32 @does_not_alias_errno_global_known_tls(float %f) { | ||
| ; CHECK-LABEL: define i32 @does_not_alias_errno_global_known_tls( | ||
| ; CHECK-SAME: float [[F:%.*]]) { | ||
| ; CHECK-NEXT: [[ENTRY:.*:]] | ||
| ; CHECK-NEXT: store i32 42, ptr @errno, align 4 | ||
| ; CHECK-NEXT: [[CALL:%.*]] = call float @sinf(float [[F]]) | ||
| ; CHECK-NEXT: ret i32 42 | ||
| ; | ||
| entry: | ||
| store i32 42, ptr @errno, align 4 | ||
| %call = call float @sinf(float %f) | ||
| %v = load i32, ptr @errno, align 4 | ||
| ret i32 %v | ||
| } | ||
|
|
||
| declare float @sinf(float) memory(errnomem: write) |
Uh oh!
There was an error while loading. Please reload this page.