Skip to content

Commit 2ed47e7

Browse files
Remove extra bitcast instruction in case of no use
1 parent f8018bf commit 2ed47e7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

llvm/lib/Transforms/Scalar/TLSVariableHoist.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,21 @@ bool TLSVariableHoistPass::tryReplaceTLSCandidate(Function &Fn,
236236

237237
// Generate a bitcast (no type change)
238238
auto *CastInst = genBitCastInst(Fn, GV);
239+
bool InstUsed = false;
239240

240241
// to replace the uses of TLS Candidate
241242
for (auto &User : Cand.Users) {
242243
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(User.Inst)) {
243244
if (II->getIntrinsicID() == Intrinsic::threadlocal_address)
244245
continue;
245246
}
247+
InstUsed = true;
246248
User.Inst->setOperand(User.OpndIdx, CastInst);
247249
}
248250

251+
if (!InstUsed)
252+
CastInst->eraseFromParent();
253+
249254
return true;
250255
}
251256

0 commit comments

Comments
 (0)