-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[TLSVariableHoist] Do not introduce bitcast on llvm.threadlocal.address argument #112772
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
Conversation
The method `AddressingModeMatcher::matchOperationAddr` and `Verifier::visitIntrinsicCall` expect a `GlobalValue` as the operand of the `llvm.threadlocal.address.p0` intrinsic. The hoist TLS pass replaces them with a bitcast instruction, causing a crash.
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-llvm-transforms Author: None (abhishek-kaushik22) ChangesThe method Fixes #112771 Full diff: https://github.com/llvm/llvm-project/pull/112772.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp b/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp
index 58ea5b68d5488b..93cd736945aace 100644
--- a/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp
+++ b/llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp
@@ -238,8 +238,13 @@ bool TLSVariableHoistPass::tryReplaceTLSCandidate(Function &Fn,
auto *CastInst = genBitCastInst(Fn, GV);
// to replace the uses of TLS Candidate
- for (auto &User : Cand.Users)
+ for (auto &User : Cand.Users) {
+ if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(User.Inst)) {
+ if (II->getIntrinsicID() == Intrinsic::threadlocal_address)
+ continue;
+ }
User.Inst->setOperand(User.OpndIdx, CastInst);
+ }
return true;
}
|
@abhishek-kaushik22 |
@nikic can you please review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right approach to fix this: If llvm.threadlocal.address is used, then we need to hoist that call. Skipping it would defeat the point.
However ... I think this entire pass may just be useless how? Since we switched to using llvm.threadlocal.address, I believe that normal EarlyCSE/GVN and LICM will already perform the optimization this pass is intended to do. Maybe we can just delete this code entirely?
CodeGenPrepare.cpp
and Verifier.cpp
I've opened #114740 to delete the pass. |
The method
AddressingModeMatcher::matchOperationAddr
andVerifier::visitIntrinsicCall
expect aGlobalValue
as the operand of thellvm.threadlocal.address.p0
intrinsic. The hoist TLS pass replaces them with a bitcast instruction, causing a crash.Fixes #112771