[llvm] c4c0ac1 - [IPO] Remove unnecessary bitcasts (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 6 07:49:54 PST 2023
Author: Nikita Popov
Date: 2023-11-06T16:49:45+01:00
New Revision: c4c0ac10f18bab1ef2b1c445a57ca806136be302
URL: https://github.com/llvm/llvm-project/commit/c4c0ac10f18bab1ef2b1c445a57ca806136be302
DIFF: https://github.com/llvm/llvm-project/commit/c4c0ac10f18bab1ef2b1c445a57ca806136be302.diff
LOG: [IPO] Remove unnecessary bitcasts (NFC)
Added:
Modified:
llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
llvm/lib/Transforms/IPO/FunctionImport.cpp
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
index 01834015f3fdd42..24c0923505c24c8 100644
--- a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -248,7 +248,7 @@ bool DeadArgumentEliminationPass::deleteDeadVarargs(Function &F) {
NF->addMetadata(KindID, *Node);
// Fix up any BlockAddresses that refer to the function.
- F.replaceAllUsesWith(ConstantExpr::getBitCast(NF, F.getType()));
+ F.replaceAllUsesWith(NF);
// Delete the bitcast that we just created, so that NF does not
// appear to be address-taken.
NF->removeDeadConstantUsers();
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index 3c07101d87e9d27..9c546b531dff498 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -1322,7 +1322,7 @@ static Function *replaceAliasWithAliasee(Module *SrcModule, GlobalAlias *GA) {
// ensure all uses of alias instead use the new clone (casted if necessary).
NewFn->setLinkage(GA->getLinkage());
NewFn->setVisibility(GA->getVisibility());
- GA->replaceAllUsesWith(ConstantExpr::getBitCast(NewFn, GA->getType()));
+ GA->replaceAllUsesWith(NewFn);
NewFn->takeName(GA);
return NewFn;
}
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index 429de758c7c3fde..b75ca7761a60b62 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -488,9 +488,6 @@ void FunctionSpecializer::promoteConstantStackValues(Function *F) {
Value *GV = new GlobalVariable(M, ConstVal->getType(), true,
GlobalValue::InternalLinkage, ConstVal,
"specialized.arg." + Twine(++NGlobals));
- if (ArgOpType != ConstVal->getType())
- GV = ConstantExpr::getBitCast(cast<Constant>(GV), ArgOpType);
-
Call->setArgOperand(Idx, GV);
}
}
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 2bf0fc2a4a84459..5fcb518cf37c130 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -381,8 +381,7 @@ struct ScopedSaveAliaseesAndUsed {
appendToCompilerUsed(M, CompilerUsed);
for (auto P : FunctionAliases)
- P.first->setAliasee(
- ConstantExpr::getBitCast(P.second, P.first->getType()));
+ P.first->setAliasee(P.second);
for (auto P : ResolverIFuncs) {
// This does not preserve pointer casts that may have been stripped by the
@@ -966,7 +965,6 @@ LowerTypeTestsModule::importTypeId(StringRef TypeId) {
Int8Arr0Ty);
if (auto *GV = dyn_cast<GlobalVariable>(C))
GV->setVisibility(GlobalValue::HiddenVisibility);
- C = ConstantExpr::getBitCast(C, Int8PtrTy);
return C;
};
@@ -1111,8 +1109,6 @@ void LowerTypeTestsModule::importFunction(
void LowerTypeTestsModule::lowerTypeTestCalls(
ArrayRef<Metadata *> TypeIds, Constant *CombinedGlobalAddr,
const DenseMap<GlobalTypeMember *, uint64_t> &GlobalLayout) {
- CombinedGlobalAddr = ConstantExpr::getBitCast(CombinedGlobalAddr, Int8PtrTy);
-
// For each type identifier in this disjoint set...
for (Metadata *TypeId : TypeIds) {
// Build the bitset.
@@ -1649,12 +1645,10 @@ void LowerTypeTestsModule::buildBitSetsFromFunctionsNative(
Function *F = cast<Function>(Functions[I]->getGlobal());
bool IsJumpTableCanonical = Functions[I]->isJumpTableCanonical();
- Constant *CombinedGlobalElemPtr = ConstantExpr::getBitCast(
- ConstantExpr::getInBoundsGetElementPtr(
- JumpTableType, JumpTable,
- ArrayRef<Constant *>{ConstantInt::get(IntPtrTy, 0),
- ConstantInt::get(IntPtrTy, I)}),
- F->getType());
+ Constant *CombinedGlobalElemPtr = ConstantExpr::getInBoundsGetElementPtr(
+ JumpTableType, JumpTable,
+ ArrayRef<Constant *>{ConstantInt::get(IntPtrTy, 0),
+ ConstantInt::get(IntPtrTy, I)});
const bool IsExported = Functions[I]->isExported();
if (!IsJumpTableCanonical) {
diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
index 98ef2065d6d9492..3988265304470c4 100644
--- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -198,7 +198,7 @@ void simplifyExternals(Module &M) {
AttributeList::FunctionIndex,
F.getAttributes().getFnAttrs()));
NewF->takeName(&F);
- F.replaceAllUsesWith(ConstantExpr::getBitCast(NewF, F.getType()));
+ F.replaceAllUsesWith(NewF);
F.eraseFromParent();
}
diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
index df5d14b56b32b5c..bc2fae0d11740e4 100644
--- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -1709,8 +1709,7 @@ void DevirtModule::applyUniqueRetValOpt(CallSiteInfo &CSInfo, StringRef FnName,
}
Constant *DevirtModule::getMemberAddr(const TypeMemberInfo *M) {
- Constant *C = ConstantExpr::getBitCast(M->Bits->GV, Int8PtrTy);
- return ConstantExpr::getGetElementPtr(Int8Ty, C,
+ return ConstantExpr::getGetElementPtr(Int8Ty, M->Bits->GV,
ConstantInt::get(Int64Ty, M->Offset));
}
More information about the llvm-commits
mailing list