Skip to content

Revert "[IRBuilder] Handle constexpr-bitcast for IRBuilder::CreateThreadLocalAddress" #72434

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
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions llvm/lib/IR/IRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,19 +536,8 @@ static MaybeAlign getAlign(Value *Ptr) {
}

CallInst *IRBuilderBase::CreateThreadLocalAddress(Value *Ptr) {
#ifndef NDEBUG
// Handle specially for constexpr cast. This is possible when
// opaque pointers not enabled since constant could be sinked
// directly by the design of llvm. This could be eliminated
// after we eliminate the abuse of constexpr.
auto *V = Ptr;
if (auto *CE = dyn_cast<ConstantExpr>(V))
if (CE->isCast())
V = CE->getOperand(0);

assert(isa<GlobalValue>(V) && cast<GlobalValue>(V)->isThreadLocal() &&
assert(isa<GlobalValue>(Ptr) && cast<GlobalValue>(Ptr)->isThreadLocal() &&
"threadlocal_address only applies to thread local variables.");
#endif
CallInst *CI = CreateIntrinsic(llvm::Intrinsic::threadlocal_address,
{Ptr->getType()}, {Ptr});
if (MaybeAlign A = getAlign(Ptr)) {
Expand Down
15 changes: 0 additions & 15 deletions llvm/unittests/IR/IRBuilderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,21 +1042,6 @@ TEST_F(IRBuilderTest, CreateGlobalStringPtr) {
EXPECT_TRUE(String3->getType()->getPointerAddressSpace() == 2);
}

TEST_F(IRBuilderTest, CreateThreadLocalAddress) {
IRBuilder<> Builder(BB);

GlobalVariable *G = new GlobalVariable(*M, Builder.getInt64Ty(), /*isConstant*/true,
GlobalValue::ExternalLinkage, nullptr, "", nullptr,
GlobalValue::GeneralDynamicTLSModel);

Constant *CEBC = ConstantExpr::getBitCast(G, Builder.getInt8PtrTy());
// Tests that IRBuilder::CreateThreadLocalAddress wouldn't crash if its operand
// is BitCast ConstExpr. The case should be eliminated after we eliminate the
// abuse of constexpr.
CallInst *CI = Builder.CreateThreadLocalAddress(CEBC);
EXPECT_NE(CI, nullptr);
}

TEST_F(IRBuilderTest, DebugLoc) {
auto CalleeTy = FunctionType::get(Type::getVoidTy(Ctx),
/*isVarArg=*/false);
Expand Down