[llvm] 739c86d - [llvm] Use more explicit cast methods (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 29 02:23:50 PDT 2023
Author: Nikita Popov
Date: 2023-09-29T11:21:13+02:00
New Revision: 739c86df807748182e576e11697db6002738aafd
URL: https://github.com/llvm/llvm-project/commit/739c86df807748182e576e11697db6002738aafd
DIFF: https://github.com/llvm/llvm-project/commit/739c86df807748182e576e11697db6002738aafd.diff
LOG: [llvm] Use more explicit cast methods (NFC)
Instead of ConstantExpr::getCast() with a fixed opcode, use the
corresponding getXYZ methods instead. For the one place creating
a pointer bitcast drop it entirely, as this is redundant with
opaque pointers.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
llvm/unittests/Analysis/SparsePropagation.cpp
llvm/unittests/Linker/LinkModulesTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 75c34d884e44aab..501a8cb6bea519b 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -588,7 +588,7 @@ Constant *FoldReinterpretLoadFromConst(Constant *C, Type *LoadTy,
if (DL.isNonIntegralPointerType(LoadTy->getScalarType()))
// Be careful not to replace a load of an addrspace value with an inttoptr here
return nullptr;
- Res = ConstantExpr::getCast(Instruction::IntToPtr, Res, LoadTy);
+ Res = ConstantExpr::getIntToPtr(Res, LoadTy);
}
return Res;
}
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index faee623d7c62fba..e31b08df7dbbe80 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -6305,7 +6305,7 @@ bool CodeGenPrepare::optimizePhiType(
// correct type.
ValueToValueMap ValMap;
for (ConstantData *C : Constants)
- ValMap[C] = ConstantExpr::getCast(Instruction::BitCast, C, ConvertTy);
+ ValMap[C] = ConstantExpr::getBitCast(C, ConvertTy);
for (Instruction *D : Defs) {
if (isa<BitCastInst>(D)) {
ValMap[D] = D->getOperand(0);
diff --git a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
index a0d81cdf2086722..adf38659de3d3d3 100644
--- a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
@@ -244,8 +244,7 @@ Constant* createIRTypedAddress(FunctionType &FT, ExecutorAddr Addr) {
Constant *AddrIntVal =
ConstantInt::get(Type::getInt64Ty(FT.getContext()), Addr.getValue());
Constant *AddrPtrVal =
- ConstantExpr::getCast(Instruction::IntToPtr, AddrIntVal,
- PointerType::get(&FT, 0));
+ ConstantExpr::getIntToPtr(AddrIntVal, PointerType::get(&FT, 0));
return AddrPtrVal;
}
diff --git a/llvm/unittests/Analysis/SparsePropagation.cpp b/llvm/unittests/Analysis/SparsePropagation.cpp
index e77eadf06717022..bbdf20035b0abc7 100644
--- a/llvm/unittests/Analysis/SparsePropagation.cpp
+++ b/llvm/unittests/Analysis/SparsePropagation.cpp
@@ -488,7 +488,7 @@ TEST_F(SparsePropagationTest, ComputeInstructionState) {
///
/// declare internal void @g()
///
-/// define internal void @f() personality i8* bitcast (void ()* @p to i8*) {
+/// define internal void @f() personality ptr @p {
/// entry:
/// invoke void @g()
/// to label %exit unwind label %catch.pad
@@ -513,9 +513,7 @@ TEST_F(SparsePropagationTest, ExceptionalTerminatorInsts) {
GlobalValue::InternalLinkage, "g", &M);
Function *F = Function::Create(FunctionType::get(Builder.getVoidTy(), false),
GlobalValue::InternalLinkage, "f", &M);
- Constant *C =
- ConstantExpr::getCast(Instruction::BitCast, P, Builder.getInt8PtrTy());
- F->setPersonalityFn(C);
+ F->setPersonalityFn(P);
BasicBlock *Entry = BasicBlock::Create(Context, "entry", F);
BasicBlock *Pad = BasicBlock::Create(Context, "catch.pad", F);
BasicBlock *Body = BasicBlock::Create(Context, "catch.body", F);
diff --git a/llvm/unittests/Linker/LinkModulesTest.cpp b/llvm/unittests/Linker/LinkModulesTest.cpp
index 3964afc17714138..b301e5a9c70290e 100644
--- a/llvm/unittests/Linker/LinkModulesTest.cpp
+++ b/llvm/unittests/Linker/LinkModulesTest.cpp
@@ -51,8 +51,7 @@ class LinkModuleTest : public testing::Test {
Init.push_back(SwitchCase2BA);
ConstantInt *One = ConstantInt::get(Type::getInt32Ty(Ctx), 1);
- Constant *OnePtr = ConstantExpr::getCast(Instruction::IntToPtr, One,
- Type::getInt8PtrTy(Ctx));
+ Constant *OnePtr = ConstantExpr::getIntToPtr(One, Type::getInt8PtrTy(Ctx));
Init.push_back(OnePtr);
GV->setInitializer(ConstantArray::get(AT, Init));
More information about the llvm-commits
mailing list