[llvm] [IR] Replace of PointerType::getUnqual(Type) with opaque version (NFC) (PR #123909)
Mats Jun Larsen via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 22 23:15:22 PST 2025
https://github.com/junlarsen updated https://github.com/llvm/llvm-project/pull/123909
>From 6df9dc82cf2d1925c358cfd5a8b898c6dcffdab9 Mon Sep 17 00:00:00 2001
From: Mats Larsen <mats at jun.codes>
Date: Wed, 22 Jan 2025 17:58:37 +0900
Subject: [PATCH 1/2] [IR] Replace of PointerType::getUnqual(Type) with opaque
version (NFC)
Follow up to https://github.com/llvm/llvm-project/issues/123569
---
llvm/examples/BrainF/BrainF.cpp | 9 ++++-----
llvm/include/llvm/FuzzMutate/OpDescriptor.h | 6 ++++--
llvm/lib/Analysis/ScalarEvolution.cpp | 2 +-
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 5 +++--
llvm/lib/CodeGen/ShadowStackGCLowering.cpp | 2 +-
llvm/lib/CodeGen/SjLjEHPrepare.cpp | 4 ++--
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 10 +++-------
llvm/lib/Frontend/Offloading/OffloadWrapper.cpp | 4 ++--
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 6 +++---
llvm/lib/IR/Constants.cpp | 3 ++-
llvm/lib/IR/ConstantsContext.h | 2 +-
llvm/lib/IR/InlineAsm.cpp | 5 +++--
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp | 4 ++--
llvm/lib/Target/Sparc/SparcISelLowering.cpp | 4 ++--
.../WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp | 2 +-
llvm/lib/Transforms/Coroutines/CoroSplit.cpp | 2 +-
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp | 2 +-
.../Transforms/Instrumentation/DataFlowSanitizer.cpp | 4 ++--
llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp | 7 +++----
llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp | 2 +-
llvm/tools/bugpoint/Miscompilation.cpp | 6 +++---
21 files changed, 45 insertions(+), 46 deletions(-)
diff --git a/llvm/examples/BrainF/BrainF.cpp b/llvm/examples/BrainF/BrainF.cpp
index e62cc7bd591a3f..cdd1ad872ab866 100644
--- a/llvm/examples/BrainF/BrainF.cpp
+++ b/llvm/examples/BrainF/BrainF.cpp
@@ -149,8 +149,7 @@ void BrainF::header(LLVMContext& C) {
//declare i32 @puts(i8 *)
FunctionCallee puts_func = module->getOrInsertFunction(
- "puts", IntegerType::getInt32Ty(C),
- PointerType::getUnqual(IntegerType::getInt8Ty(C)));
+ "puts", IntegerType::getInt32Ty(C), PointerType::getUnqual(C));
//brainf.aberror:
aberrorbb = BasicBlock::Create(C, label, brainf_func);
@@ -296,8 +295,8 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
builder->SetInsertPoint(bb_1);
// Make part of PHI instruction now, wait until end of loop to finish
- PHINode *phi_0 = PHINode::Create(PointerType::getUnqual(Int8Ty), 2,
- headreg, testbb);
+ PHINode *phi_0 =
+ PHINode::Create(PointerType::getUnqual(C), 2, headreg, testbb);
phi_0->addIncoming(curhead, bb_0);
curhead = phi_0;
@@ -451,7 +450,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
//%head.%d = phi i8 *[%head.%d, %main.%d]
PHINode *phi_1 =
- builder->CreatePHI(PointerType::getUnqual(Int8Ty), 1, headreg);
+ builder->CreatePHI(PointerType::getUnqual(C), 1, headreg);
phi_1->addIncoming(head_0, testbb);
curhead = phi_1;
}
diff --git a/llvm/include/llvm/FuzzMutate/OpDescriptor.h b/llvm/include/llvm/FuzzMutate/OpDescriptor.h
index 4a3c2f767d00c8..771b711dd1b48d 100644
--- a/llvm/include/llvm/FuzzMutate/OpDescriptor.h
+++ b/llvm/include/llvm/FuzzMutate/OpDescriptor.h
@@ -155,7 +155,8 @@ static inline SourcePred anyPtrType() {
std::vector<Constant *> Result;
// TODO: Should these point at something?
for (Type *T : Ts)
- Result.push_back(PoisonValue::get(PointerType::getUnqual(T)));
+ Result.push_back(
+ PoisonValue::get(PointerType::getUnqual(T->getContext())));
return Result;
};
return {Pred, Make};
@@ -175,7 +176,8 @@ static inline SourcePred sizedPtrType() {
// as the pointer type will always be the same.
for (Type *T : Ts)
if (T->isSized())
- Result.push_back(PoisonValue::get(PointerType::getUnqual(T)));
+ Result.push_back(
+ PoisonValue::get(PointerType::getUnqual(T->getContext())));
return Result;
};
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 7673c354817579..c1abfd099f7482 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -13601,7 +13601,7 @@ const SCEV *ScalarEvolution::getElementSize(Instruction *Inst) {
else
return nullptr;
- Type *ETy = getEffectiveSCEVType(PointerType::getUnqual(Ty));
+ Type *ETy = getEffectiveSCEVType(PointerType::getUnqual(Inst->getContext()));
return getSizeOfExpr(ETy, Ty);
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 9f1aadcb279a99..646dce409a52ca 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -9006,8 +9006,9 @@ static SDValue getMemCmpLoad(const Value *PtrVal, MVT LoadVT,
if (LoadVT.isVector())
LoadTy = FixedVectorType::get(LoadTy, LoadVT.getVectorNumElements());
- LoadInput = ConstantExpr::getBitCast(const_cast<Constant *>(LoadInput),
- PointerType::getUnqual(LoadTy));
+ LoadInput =
+ ConstantExpr::getBitCast(const_cast<Constant *>(LoadInput),
+ PointerType::getUnqual(LoadTy->getContext()));
if (const Constant *LoadCst =
ConstantFoldLoadFromConstPtr(const_cast<Constant *>(LoadInput),
diff --git a/llvm/lib/CodeGen/ShadowStackGCLowering.cpp b/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
index d93db494e0908e..60c8372577a93b 100644
--- a/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
+++ b/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
@@ -233,7 +233,7 @@ bool ShadowStackGCLoweringImpl::doInitialization(Module &M) {
// Specifies length of variable length array.
EltTys.push_back(Type::getInt32Ty(M.getContext()));
FrameMapTy = StructType::create(EltTys, "gc_map");
- PointerType *FrameMapPtrTy = PointerType::getUnqual(FrameMapTy);
+ PointerType *FrameMapPtrTy = PointerType::getUnqual(M.getContext());
// struct StackEntry {
// ShadowStackEntry *Next; // Caller's stack entry.
diff --git a/llvm/lib/CodeGen/SjLjEHPrepare.cpp b/llvm/lib/CodeGen/SjLjEHPrepare.cpp
index 9630ba4307cd21..b55be23e4579d5 100644
--- a/llvm/lib/CodeGen/SjLjEHPrepare.cpp
+++ b/llvm/lib/CodeGen/SjLjEHPrepare.cpp
@@ -500,10 +500,10 @@ bool SjLjEHPrepareImpl::runOnFunction(Function &F) {
Module &M = *F.getParent();
RegisterFn = M.getOrInsertFunction(
"_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()),
- PointerType::getUnqual(FunctionContextTy));
+ PointerType::getUnqual(FunctionContextTy->getContext()));
UnregisterFn = M.getOrInsertFunction(
"_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()),
- PointerType::getUnqual(FunctionContextTy));
+ PointerType::getUnqual(FunctionContextTy->getContext()));
PointerType *AllocaPtrTy = M.getDataLayout().getAllocaPtrType(M.getContext());
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 76d5c1428ed649..14c52e809650c1 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -193,8 +193,7 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
{PlatformInstanceDecl, DSOHandle});
auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
- auto *AtExitCallbackTy = FunctionType::get(VoidTy, {}, false);
- auto *AtExitCallbackPtrTy = PointerType::getUnqual(AtExitCallbackTy);
+ auto *AtExitCallbackPtrTy = PointerType::getUnqual(*Ctx);
auto *AtExit = addHelperAndWrapper(
*M, "atexit", FunctionType::get(IntTy, {AtExitCallbackPtrTy}, false),
GlobalValue::HiddenVisibility, "__lljit.atexit_helper",
@@ -468,12 +467,9 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
*M, GenericIRPlatformSupportTy, true, GlobalValue::ExternalLinkage,
nullptr, "__lljit.platform_support_instance");
- auto *Int8Ty = Type::getInt8Ty(*Ctx);
auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
- auto *VoidTy = Type::getVoidTy(*Ctx);
- auto *BytePtrTy = PointerType::getUnqual(Int8Ty);
- auto *CxaAtExitCallbackTy = FunctionType::get(VoidTy, {BytePtrTy}, false);
- auto *CxaAtExitCallbackPtrTy = PointerType::getUnqual(CxaAtExitCallbackTy);
+ auto *BytePtrTy = PointerType::getUnqual(*Ctx);
+ auto *CxaAtExitCallbackPtrTy = PointerType::getUnqual(*Ctx);
auto *CxaAtExit = addHelperAndWrapper(
*M, "__cxa_atexit",
diff --git a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
index d616b4058b7bb0..f3d8bc713b8dfa 100644
--- a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
+++ b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
@@ -50,7 +50,7 @@ StructType *getDeviceImageTy(Module &M) {
}
PointerType *getDeviceImagePtrTy(Module &M) {
- return PointerType::getUnqual(getDeviceImageTy(M));
+ return PointerType::getUnqual(M.getContext());
}
// struct __tgt_bin_desc {
@@ -70,7 +70,7 @@ StructType *getBinDescTy(Module &M) {
}
PointerType *getBinDescPtrTy(Module &M) {
- return PointerType::getUnqual(getBinDescTy(M));
+ return PointerType::getUnqual(M.getContext());
}
/// Creates binary descriptor for the given device images. Binary descriptor
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 7dbf65fbf055bd..7ef9f2fc4f49d7 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -9177,16 +9177,16 @@ void OpenMPIRBuilder::initializeTypes(Module &M) {
#define OMP_TYPE(VarName, InitValue) VarName = InitValue;
#define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
VarName##Ty = ArrayType::get(ElemTy, ArraySize); \
- VarName##PtrTy = PointerType::getUnqual(VarName##Ty);
+ VarName##PtrTy = PointerType::getUnqual(Ctx);
#define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
VarName = FunctionType::get(ReturnType, {__VA_ARGS__}, IsVarArg); \
- VarName##Ptr = PointerType::getUnqual(VarName);
+ VarName##Ptr = PointerType::getUnqual(Ctx);
#define OMP_STRUCT_TYPE(VarName, StructName, Packed, ...) \
T = StructType::getTypeByName(Ctx, StructName); \
if (!T) \
T = StructType::create(Ctx, {__VA_ARGS__}, StructName, Packed); \
VarName = T; \
- VarName##Ptr = PointerType::getUnqual(T);
+ VarName##Ptr = PointerType::getUnqual(Ctx);
#include "llvm/Frontend/OpenMP/OMPKinds.def"
}
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index db5effbd9a43e7..33f4dc78c6d3f9 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -2482,7 +2482,8 @@ Constant *ConstantExpr::getSizeOf(Type* Ty) {
// Note that a non-inbounds gep is used, as null isn't within any object.
Constant *GEPIdx = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
Constant *GEP = getGetElementPtr(
- Ty, Constant::getNullValue(PointerType::getUnqual(Ty)), GEPIdx);
+ Ty, Constant::getNullValue(PointerType::getUnqual(Ty->getContext())),
+ GEPIdx);
return getPtrToInt(GEP,
Type::getInt64Ty(Ty->getContext()));
}
diff --git a/llvm/lib/IR/ConstantsContext.h b/llvm/lib/IR/ConstantsContext.h
index 08bf3f9dff5e66..e5c9622e09927a 100644
--- a/llvm/lib/IR/ConstantsContext.h
+++ b/llvm/lib/IR/ConstantsContext.h
@@ -380,7 +380,7 @@ struct InlineAsmKeyType {
using TypeClass = ConstantInfo<InlineAsm>::TypeClass;
InlineAsm *create(TypeClass *Ty) const {
- assert(PointerType::getUnqual(FTy) == Ty);
+ assert(PointerType::getUnqual(FTy->getContext()) == Ty);
return new InlineAsm(FTy, std::string(AsmString), std::string(Constraints),
HasSideEffects, IsAlignStack, AsmDialect, CanThrow);
}
diff --git a/llvm/lib/IR/InlineAsm.cpp b/llvm/lib/IR/InlineAsm.cpp
index aeaa6a3741b949..922081468a7750 100644
--- a/llvm/lib/IR/InlineAsm.cpp
+++ b/llvm/lib/IR/InlineAsm.cpp
@@ -30,7 +30,7 @@ using namespace llvm;
InlineAsm::InlineAsm(FunctionType *FTy, const std::string &asmString,
const std::string &constraints, bool hasSideEffects,
bool isAlignStack, AsmDialect asmDialect, bool canThrow)
- : Value(PointerType::getUnqual(FTy), Value::InlineAsmVal),
+ : Value(PointerType::getUnqual(FTy->getContext()), Value::InlineAsmVal),
AsmString(asmString), Constraints(constraints), FTy(FTy),
HasSideEffects(hasSideEffects), IsAlignStack(isAlignStack),
Dialect(asmDialect), CanThrow(canThrow) {
@@ -47,7 +47,8 @@ InlineAsm *InlineAsm::get(FunctionType *FTy, StringRef AsmString,
InlineAsmKeyType Key(AsmString, Constraints, FTy, hasSideEffects,
isAlignStack, asmDialect, canThrow);
LLVMContextImpl *pImpl = FTy->getContext().pImpl;
- return pImpl->InlineAsms.getOrCreate(PointerType::getUnqual(FTy), Key);
+ return pImpl->InlineAsms.getOrCreate(
+ PointerType::getUnqual(FTy->getContext()), Key);
}
void InlineAsm::destroyConstant() {
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index cd093317275ee9..8a7737e9819e6e 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -1954,7 +1954,7 @@ instCombineLD1GatherIndex(InstCombiner &IC, IntrinsicInst &II) {
Align Alignment =
BasePtr->getPointerAlignment(II.getDataLayout());
- Type *VecPtrTy = PointerType::getUnqual(Ty);
+ Type *VecPtrTy = PointerType::getUnqual(II.getContext());
Value *Ptr = IC.Builder.CreateGEP(cast<VectorType>(Ty)->getElementType(),
BasePtr, IndexBase);
Ptr = IC.Builder.CreateBitCast(Ptr, VecPtrTy);
@@ -1986,7 +1986,7 @@ instCombineST1ScatterIndex(InstCombiner &IC, IntrinsicInst &II) {
Value *Ptr = IC.Builder.CreateGEP(cast<VectorType>(Ty)->getElementType(),
BasePtr, IndexBase);
- Type *VecPtrTy = PointerType::getUnqual(Ty);
+ Type *VecPtrTy = PointerType::getUnqual(Val->getContext());
Ptr = IC.Builder.CreateBitCast(Ptr, VecPtrTy);
(void)IC.Builder.CreateMaskedStore(Val, Ptr, Alignment, Mask);
diff --git a/llvm/lib/Target/Sparc/SparcISelLowering.cpp b/llvm/lib/Target/Sparc/SparcISelLowering.cpp
index d0cd38cf723636..c2c3a59ed05000 100644
--- a/llvm/lib/Target/Sparc/SparcISelLowering.cpp
+++ b/llvm/lib/Target/Sparc/SparcISelLowering.cpp
@@ -2323,7 +2323,7 @@ SDValue SparcTargetLowering::LowerF128_LibCallArg(SDValue Chain,
Align(8));
Entry.Node = FIPtr;
- Entry.Ty = PointerType::getUnqual(ArgTy);
+ Entry.Ty = PointerType::getUnqual(ArgTy->getContext());
}
Args.push_back(Entry);
return Chain;
@@ -2351,7 +2351,7 @@ SparcTargetLowering::LowerF128Op(SDValue Op, SelectionDAG &DAG,
int RetFI = MFI.CreateStackObject(16, Align(8), false);
RetPtr = DAG.getFrameIndex(RetFI, PtrVT);
Entry.Node = RetPtr;
- Entry.Ty = PointerType::getUnqual(RetTy);
+ Entry.Ty = PointerType::getUnqual(RetTy->getContext());
if (!Subtarget->is64Bit()) {
Entry.IsSRet = true;
Entry.IndirectType = RetTy;
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
index 5aef016720cf4c..839a206033a0c6 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -580,7 +580,7 @@ Function *WebAssemblyLowerEmscriptenEHSjLj::getInvokeWrapper(CallBase *CI) {
return It->second;
// Put the pointer to the callee as first argument
- ArgTys.push_back(PointerType::getUnqual(CalleeFTy));
+ ArgTys.push_back(PointerType::getUnqual(CI->getContext()));
// Add argument types
ArgTys.append(CalleeFTy->param_begin(), CalleeFTy->param_end());
diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
index 3808147fc26009..23ac55e8ce0cde 100644
--- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -1419,7 +1419,7 @@ struct SwitchCoroutineSplitter {
SmallVector<Type *> NewParams;
NewParams.reserve(OldParams.size() + 1);
NewParams.append(OldParams.begin(), OldParams.end());
- NewParams.push_back(PointerType::getUnqual(Shape.FrameTy));
+ NewParams.push_back(PointerType::getUnqual(Shape.FrameTy->getContext()));
auto *NewFnTy = FunctionType::get(OrigFnTy->getReturnType(), NewParams,
OrigFnTy->isVarArg());
diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
index 2f171c3c981d40..3a2568c4555fed 100644
--- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -1529,7 +1529,7 @@ void DevirtModule::applyICallBranchFunnel(VTableSlotInfo &SlotInfo,
FunctionType *NewFT =
FunctionType::get(CB.getFunctionType()->getReturnType(), NewArgs,
CB.getFunctionType()->isVarArg());
- PointerType *NewFTPtr = PointerType::getUnqual(NewFT);
+ PointerType *NewFTPtr = PointerType::getUnqual(CB.getContext());
IRBuilder<> IRB(&CB);
std::vector<Value *> Args;
diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
index fd69b3f244ec81..fcabcdfb0ba9b3 100644
--- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -1150,9 +1150,9 @@ bool DataFlowSanitizer::initializeModule(Module &M) {
Ctx = &M.getContext();
Int8Ptr = PointerType::getUnqual(*Ctx);
OriginTy = IntegerType::get(*Ctx, OriginWidthBits);
- OriginPtrTy = PointerType::getUnqual(OriginTy);
+ OriginPtrTy = PointerType::getUnqual(*Ctx);
PrimitiveShadowTy = IntegerType::get(*Ctx, ShadowWidthBits);
- PrimitiveShadowPtrTy = PointerType::getUnqual(PrimitiveShadowTy);
+ PrimitiveShadowPtrTy = PointerType::getUnqual(*Ctx);
IntptrTy = DL.getIntPtrType(*Ctx);
ZeroPrimitiveShadow = ConstantInt::getSigned(PrimitiveShadowTy, 0);
ZeroOrigin = ConstantInt::getSigned(OriginTy, 0);
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
index 1d213e2aeae5a5..fc34dabe5f5184 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
@@ -380,12 +380,11 @@ void ObjCARCContract::tryToContractReleaseIntoStoreStrong(
<< " Load: " << *Load << "\n");
LLVMContext &C = Release->getContext();
- Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
- Type *I8XX = PointerType::getUnqual(I8X);
+ Type *I8X = PointerType::getUnqual(C);
Value *Args[] = { Load->getPointerOperand(), New };
- if (Args[0]->getType() != I8XX)
- Args[0] = new BitCastInst(Args[0], I8XX, "", Store->getIterator());
+ if (Args[0]->getType() != I8X)
+ Args[0] = new BitCastInst(Args[0], I8X, "", Store->getIterator());
if (Args[1]->getType() != I8X)
Args[1] = new BitCastInst(Args[1], I8X, "", Store->getIterator());
Function *Decl = EP.get(ARCRuntimeEntryPointKind::StoreStrong);
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
index 5bfbe95fafa05e..1671398f2342d1 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
@@ -1763,7 +1763,7 @@ void ObjCARCOpt::MoveCalls(Value *Arg, RRInfo &RetainsToMove,
SmallVectorImpl<Instruction *> &DeadInsts,
Module *M) {
Type *ArgTy = Arg->getType();
- Type *ParamTy = PointerType::getUnqual(Type::getInt8Ty(ArgTy->getContext()));
+ Type *ParamTy = PointerType::getUnqual(ArgTy->getContext());
LLVM_DEBUG(dbgs() << "== ObjCARCOpt::MoveCalls ==\n");
diff --git a/llvm/tools/bugpoint/Miscompilation.cpp b/llvm/tools/bugpoint/Miscompilation.cpp
index b165b8220c20bd..ff4ad54da54c2f 100644
--- a/llvm/tools/bugpoint/Miscompilation.cpp
+++ b/llvm/tools/bugpoint/Miscompilation.cpp
@@ -895,9 +895,9 @@ CleanupAndPrepareModules(BugDriver &BD, std::unique_ptr<Module> Test,
"resolver", LookupBB);
// Cast the result from the resolver to correctly-typed function.
- CastInst *CastedResolver = new BitCastInst(
- Resolver, PointerType::getUnqual(F->getFunctionType()),
- "resolverCast", LookupBB);
+ CastInst *CastedResolver =
+ new BitCastInst(Resolver, PointerType::getUnqual(F->getContext()),
+ "resolverCast", LookupBB);
// Save the value in our cache.
new StoreInst(CastedResolver, Cache, LookupBB);
>From be160bbf2a8e9800e6dfc2939aaec77cf436ec23 Mon Sep 17 00:00:00 2001
From: Mats Larsen <mats at jun.codes>
Date: Thu, 23 Jan 2025 16:13:57 +0900
Subject: [PATCH 2/2] [IR] Remove unnecessary bitcasts from pointer to pointer
---
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp | 5 -----
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp | 10 ++++------
llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp | 9 +--------
llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp | 5 +----
llvm/tools/bugpoint/Miscompilation.cpp | 9 ++-------
5 files changed, 8 insertions(+), 30 deletions(-)
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index 8a7737e9819e6e..77537df1ae053e 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -1954,10 +1954,8 @@ instCombineLD1GatherIndex(InstCombiner &IC, IntrinsicInst &II) {
Align Alignment =
BasePtr->getPointerAlignment(II.getDataLayout());
- Type *VecPtrTy = PointerType::getUnqual(II.getContext());
Value *Ptr = IC.Builder.CreateGEP(cast<VectorType>(Ty)->getElementType(),
BasePtr, IndexBase);
- Ptr = IC.Builder.CreateBitCast(Ptr, VecPtrTy);
CallInst *MaskedLoad =
IC.Builder.CreateMaskedLoad(Ty, Ptr, Alignment, Mask, PassThru);
MaskedLoad->takeName(&II);
@@ -1986,9 +1984,6 @@ instCombineST1ScatterIndex(InstCombiner &IC, IntrinsicInst &II) {
Value *Ptr = IC.Builder.CreateGEP(cast<VectorType>(Ty)->getElementType(),
BasePtr, IndexBase);
- Type *VecPtrTy = PointerType::getUnqual(Val->getContext());
- Ptr = IC.Builder.CreateBitCast(Ptr, VecPtrTy);
-
(void)IC.Builder.CreateMaskedStore(Val, Ptr, Alignment, Mask);
return IC.eraseInstFromFunction(II);
diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
index 3a2568c4555fed..e889926930082f 100644
--- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -1529,8 +1529,6 @@ void DevirtModule::applyICallBranchFunnel(VTableSlotInfo &SlotInfo,
FunctionType *NewFT =
FunctionType::get(CB.getFunctionType()->getReturnType(), NewArgs,
CB.getFunctionType()->isVarArg());
- PointerType *NewFTPtr = PointerType::getUnqual(CB.getContext());
-
IRBuilder<> IRB(&CB);
std::vector<Value *> Args;
Args.push_back(VCallSite.VTable);
@@ -1538,11 +1536,11 @@ void DevirtModule::applyICallBranchFunnel(VTableSlotInfo &SlotInfo,
CallBase *NewCS = nullptr;
if (isa<CallInst>(CB))
- NewCS = IRB.CreateCall(NewFT, IRB.CreateBitCast(JT, NewFTPtr), Args);
+ NewCS = IRB.CreateCall(NewFT, JT, Args);
else
- NewCS = IRB.CreateInvoke(NewFT, IRB.CreateBitCast(JT, NewFTPtr),
- cast<InvokeInst>(CB).getNormalDest(),
- cast<InvokeInst>(CB).getUnwindDest(), Args);
+ NewCS =
+ IRB.CreateInvoke(NewFT, JT, cast<InvokeInst>(CB).getNormalDest(),
+ cast<InvokeInst>(CB).getUnwindDest(), Args);
NewCS->setCallingConv(CB.getCallingConv());
AttributeList Attrs = CB.getAttributes();
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
index fc34dabe5f5184..b020591c203dbd 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
@@ -379,14 +379,7 @@ void ObjCARCContract::tryToContractReleaseIntoStoreStrong(
<< " Retain: " << *Retain << "\n"
<< " Load: " << *Load << "\n");
- LLVMContext &C = Release->getContext();
- Type *I8X = PointerType::getUnqual(C);
-
- Value *Args[] = { Load->getPointerOperand(), New };
- if (Args[0]->getType() != I8X)
- Args[0] = new BitCastInst(Args[0], I8X, "", Store->getIterator());
- if (Args[1]->getType() != I8X)
- Args[1] = new BitCastInst(Args[1], I8X, "", Store->getIterator());
+ Value *Args[] = {Load->getPointerOperand(), New};
Function *Decl = EP.get(ARCRuntimeEntryPointKind::StoreStrong);
CallInst *StoreStrong = objcarc::createCallInstWithColors(
Decl, Args, "", Store->getIterator(), BlockColors);
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
index 1671398f2342d1..7e3913554e689c 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
@@ -1769,14 +1769,11 @@ void ObjCARCOpt::MoveCalls(Value *Arg, RRInfo &RetainsToMove,
// Insert the new retain and release calls.
for (Instruction *InsertPt : ReleasesToMove.ReverseInsertPts) {
- Value *MyArg = ArgTy == ParamTy ? Arg
- : new BitCastInst(Arg, ParamTy, "",
- InsertPt->getIterator());
Function *Decl = EP.get(ARCRuntimeEntryPointKind::Retain);
SmallVector<OperandBundleDef, 1> BundleList;
addOpBundleForFunclet(InsertPt->getParent(), BundleList);
CallInst *Call =
- CallInst::Create(Decl, MyArg, BundleList, "", InsertPt->getIterator());
+ CallInst::Create(Decl, Arg, BundleList, "", InsertPt->getIterator());
Call->setDoesNotThrow();
Call->setTailCall();
diff --git a/llvm/tools/bugpoint/Miscompilation.cpp b/llvm/tools/bugpoint/Miscompilation.cpp
index ff4ad54da54c2f..4cf7de3659b8a4 100644
--- a/llvm/tools/bugpoint/Miscompilation.cpp
+++ b/llvm/tools/bugpoint/Miscompilation.cpp
@@ -894,18 +894,13 @@ CleanupAndPrepareModules(BugDriver &BD, std::unique_ptr<Module> Test,
CallInst *Resolver = CallInst::Create(resolverFunc, ResolverArgs,
"resolver", LookupBB);
- // Cast the result from the resolver to correctly-typed function.
- CastInst *CastedResolver =
- new BitCastInst(Resolver, PointerType::getUnqual(F->getContext()),
- "resolverCast", LookupBB);
-
// Save the value in our cache.
- new StoreInst(CastedResolver, Cache, LookupBB);
+ new StoreInst(Resolver, Cache, LookupBB);
BranchInst::Create(DoCallBB, LookupBB);
PHINode *FuncPtr =
PHINode::Create(NullPtr->getType(), 2, "fp", DoCallBB);
- FuncPtr->addIncoming(CastedResolver, LookupBB);
+ FuncPtr->addIncoming(Resolver, LookupBB);
FuncPtr->addIncoming(CachedVal, EntryBB);
// Save the argument list.
More information about the llvm-commits
mailing list