Skip to content

Commit b26b1ce

Browse files
committed
[clang][CodeGenModule] Remove no-op ptr-to-ptr bitcasts (NFC)
Opaque ptr cleanup effort (NFC).
1 parent 2dace04 commit b26b1ce

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,10 +3201,9 @@ llvm::Constant *CodeGenModule::EmitAnnotationArgs(const AnnotateAttr *Attr) {
32013201
".args");
32023202
GV->setSection(AnnotationSection);
32033203
GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
3204-
auto *Bitcasted = llvm::ConstantExpr::getBitCast(GV, GlobalsInt8PtrTy);
32053204

3206-
Lookup = Bitcasted;
3207-
return Bitcasted;
3205+
Lookup = GV;
3206+
return GV;
32083207
}
32093208

32103209
llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
@@ -3227,11 +3226,7 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
32273226

32283227
// Create the ConstantStruct for the global annotation.
32293228
llvm::Constant *Fields[] = {
3230-
llvm::ConstantExpr::getBitCast(GVInGlobalsAS, GlobalsInt8PtrTy),
3231-
llvm::ConstantExpr::getBitCast(AnnoGV, ConstGlobalsPtrTy),
3232-
llvm::ConstantExpr::getBitCast(UnitGV, ConstGlobalsPtrTy),
3233-
LineNoCst,
3234-
Args,
3229+
GVInGlobalsAS, AnnoGV, UnitGV, LineNoCst, Args,
32353230
};
32363231
return llvm::ConstantStruct::getAnon(Fields);
32373232
}
@@ -4697,9 +4692,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
46974692
GV->takeName(Entry);
46984693

46994694
if (!Entry->use_empty()) {
4700-
llvm::Constant *NewPtrForOldDecl =
4701-
llvm::ConstantExpr::getBitCast(GV, Entry->getType());
4702-
Entry->replaceAllUsesWith(NewPtrForOldDecl);
4695+
Entry->replaceAllUsesWith(GV);
47034696
}
47044697

47054698
Entry->eraseFromParent();
@@ -4878,9 +4871,7 @@ llvm::GlobalVariable *CodeGenModule::CreateOrReplaceCXXRuntimeVariable(
48784871
GV->takeName(OldGV);
48794872

48804873
if (!OldGV->use_empty()) {
4881-
llvm::Constant *NewPtrForOldDecl =
4882-
llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
4883-
OldGV->replaceAllUsesWith(NewPtrForOldDecl);
4874+
OldGV->replaceAllUsesWith(GV);
48844875
}
48854876

48864877
OldGV->eraseFromParent();
@@ -5766,8 +5757,7 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) {
57665757
// Remove it and replace uses of it with the alias.
57675758
GA->takeName(Entry);
57685759

5769-
Entry->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GA,
5770-
Entry->getType()));
5760+
Entry->replaceAllUsesWith(GA);
57715761
Entry->eraseFromParent();
57725762
} else {
57735763
GA->setName(MangledName);
@@ -5845,8 +5835,7 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
58455835
// Remove it and replace uses of it with the ifunc.
58465836
GIF->takeName(Entry);
58475837

5848-
Entry->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GIF,
5849-
Entry->getType()));
5838+
Entry->replaceAllUsesWith(GIF);
58505839
Entry->eraseFromParent();
58515840
} else
58525841
GIF->setName(MangledName);
@@ -6042,9 +6031,6 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
60426031
llvm::Constant *Str =
60436032
llvm::ConstantExpr::getGetElementPtr(GV->getValueType(), GV, Zeros);
60446033

6045-
if (isUTF16)
6046-
// Cast the UTF16 string to the correct type.
6047-
Str = llvm::ConstantExpr::getBitCast(Str, Int8PtrTy);
60486034
Fields.add(Str);
60496035

60506036
// String length.
@@ -6414,8 +6400,7 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
64146400
// replace it with the new global now.
64156401
llvm::Constant *&Entry = MaterializedGlobalTemporaryMap[E];
64166402
if (Entry) {
6417-
Entry->replaceAllUsesWith(
6418-
llvm::ConstantExpr::getBitCast(CV, Entry->getType()));
6403+
Entry->replaceAllUsesWith(CV);
64196404
llvm::cast<llvm::GlobalVariable>(Entry)->eraseFromParent();
64206405
}
64216406
Entry = CV;

0 commit comments

Comments
 (0)