Skip to content

IRVerifier: Allow GlobalValue as llvm.threadlocal.address operand #88321

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

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

MatzeB
Copy link
Contributor

@MatzeB MatzeB commented Apr 10, 2024

Loosen llvm.threadlocal.address verifier checks to allow any GlobalValue with isThreadLocal() set to true.

@MatzeB
Copy link
Contributor Author

MatzeB commented Apr 10, 2024

This amends #87841 : I just noticed in the class hierarchy and reading the language spec that GlobalAlias and GlobalVariable can be thread local. So it is best to allow any GlobalValue in the check I added the other day.

FWIW the X86 backend seems to produce invalid code that isn't actually doing thread-local accesses GlobalAliases, but that is probably just a bug for this (unused?) feature.

@MatzeB MatzeB marked this pull request as ready for review April 10, 2024 21:28
@llvmbot
Copy link
Member

llvmbot commented Apr 10, 2024

@llvm/pr-subscribers-llvm-ir

Author: Matthias Braun (MatzeB)

Changes

Loosen llvm.threadlocal.address verifier checks to allow any GlobalValue with isThreadLocal() set to true.


Full diff: https://github.com/llvm/llvm-project/pull/88321.diff

2 Files Affected:

  • (modified) llvm/docs/LangRef.rst (+2-1)
  • (modified) llvm/lib/IR/Verifier.cpp (+4-4)
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index f6ada292b93b10..9592929d79feb4 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -28130,7 +28130,8 @@ Syntax:
 Arguments:
 """"""""""
 
-The first argument is a thread local :ref:`global variable <globalvars>`.
+The `llvm.threadlocal.address` intrinsic requires a global value argument (a
+:ref:`global variable <globalvars>` or alias) that is thread local.
 
 Semantics:
 """"""""""
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4092f0cb12ffe9..25cb99f0f9bd8b 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -6226,10 +6226,10 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
   }
   case Intrinsic::threadlocal_address: {
     const Value &Arg0 = *Call.getArgOperand(0);
-    Check(isa<GlobalVariable>(Arg0),
-          "llvm.threadlocal.address first argument must be a GlobalVariable");
-    Check(cast<GlobalVariable>(Arg0).isThreadLocal(),
-          "llvm.threadlocal.address operand isThreadLocal() must no be false");
+    Check(isa<GlobalValue>(Arg0),
+          "llvm.threadlocal.address first argument must be a GlobalValue");
+    Check(cast<GlobalValue>(Arg0).isThreadLocal(),
+          "llvm.threadlocal.address operand isThreadLocal() must be true");
     break;
   }
   };

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test to make sure the verifier does not fire?

@MatzeB MatzeB force-pushed the threadlocal_verify_amend branch from b52dc1c to 48fda5a Compare April 11, 2024 16:59
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MatzeB MatzeB merged commit c6cd460 into llvm:main Apr 12, 2024
bazuzi pushed a commit to bazuzi/llvm-project that referenced this pull request Apr 15, 2024
…vm#88321)

Loosen `llvm.threadlocal.address` verifier checks to allow any
`GlobalValue` with `isThreadLocal()` set to true.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants