Skip to content

Commit 8762360

Browse files
authored
[llvm] Remove no-op ptr-to-ptr bitcasts (NFC) (#72133)
Opaque ptr cleanup effort (NFC).
1 parent af8428c commit 8762360

File tree

5 files changed

+3
-23
lines changed

5 files changed

+3
-23
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4494,7 +4494,7 @@ Constant *OpenMPIRBuilder::createOutlinedFunctionID(Function *OutlinedFn,
44944494
StringRef EntryFnIDName) {
44954495
if (Config.isTargetDevice()) {
44964496
assert(OutlinedFn && "The outlined function must exist if embedded");
4497-
return ConstantExpr::getBitCast(OutlinedFn, Builder.getInt8PtrTy());
4497+
return OutlinedFn;
44984498
}
44994499

45004500
return new GlobalVariable(

llvm/lib/IR/Module.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,6 @@ FunctionCallee Module::getOrInsertFunction(StringRef Name, FunctionType *Ty,
156156
return {Ty, New}; // Return the new prototype.
157157
}
158158

159-
// If the function exists but has the wrong type, return a bitcast to the
160-
// right type.
161-
auto *PTy = PointerType::get(Ty, F->getAddressSpace());
162-
if (F->getType() != PTy)
163-
return {Ty, ConstantExpr::getBitCast(F, PTy)};
164-
165159
// Otherwise, we just found the existing function or a prototype.
166160
return {Ty, F};
167161
}
@@ -212,13 +206,6 @@ Constant *Module::getOrInsertGlobal(
212206
GV = CreateGlobalCallback();
213207
assert(GV && "The CreateGlobalCallback is expected to create a global");
214208

215-
// If the variable exists but has the wrong type, return a bitcast to the
216-
// right type.
217-
Type *GVTy = GV->getType();
218-
PointerType *PTy = PointerType::get(Ty, GVTy->getPointerAddressSpace());
219-
if (GVTy != PTy)
220-
return ConstantExpr::getBitCast(GV, PTy);
221-
222209
// Otherwise, we just found the existing function or a prototype.
223210
return GV;
224211
}

llvm/lib/LTO/LTO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
12601260
ConstantAggregateZero::get(Ty), "");
12611261
GV->setAlignment(I.second.Alignment);
12621262
if (OldGV) {
1263-
OldGV->replaceAllUsesWith(ConstantExpr::getBitCast(GV, OldGV->getType()));
1263+
OldGV->replaceAllUsesWith(GV);
12641264
GV->takeName(OldGV);
12651265
OldGV->eraseFromParent();
12661266
} else {

llvm/lib/Transforms/CFGuard/CFGuard.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,6 @@ void CFGuard::insertCFGuardDispatch(CallBase *CB) {
195195
Value *CalledOperand = CB->getCalledOperand();
196196
Type *CalledOperandType = CalledOperand->getType();
197197

198-
// Cast the guard dispatch global to the type of the called operand.
199-
PointerType *PTy = PointerType::get(CalledOperandType, 0);
200-
if (GuardFnGlobal->getType() != PTy)
201-
GuardFnGlobal = ConstantExpr::getBitCast(GuardFnGlobal, PTy);
202-
203198
// Load the global as a pointer to a function of the same type.
204199
LoadInst *GuardDispatchLoad = B.CreateLoad(CalledOperandType, GuardFnGlobal);
205200

llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ static void insertCall(Function &CurFn, StringRef Func,
6565
InsertionPt);
6666
RetAddr->setDebugLoc(DL);
6767

68-
Value *Args[] = {
69-
ConstantExpr::getBitCast(&CurFn, PointerType::getUnqual(C)), RetAddr};
70-
68+
Value *Args[] = {&CurFn, RetAddr};
7169
CallInst *Call =
7270
CallInst::Create(Fn, ArrayRef<Value *>(Args), "", InsertionPt);
7371
Call->setDebugLoc(DL);

0 commit comments

Comments
 (0)