Skip to content

Commit 739c86d

Browse files
committed
[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.
1 parent 86dea5a commit 739c86d

File tree

5 files changed

+6
-10
lines changed

5 files changed

+6
-10
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ Constant *FoldReinterpretLoadFromConst(Constant *C, Type *LoadTy,
588588
if (DL.isNonIntegralPointerType(LoadTy->getScalarType()))
589589
// Be careful not to replace a load of an addrspace value with an inttoptr here
590590
return nullptr;
591-
Res = ConstantExpr::getCast(Instruction::IntToPtr, Res, LoadTy);
591+
Res = ConstantExpr::getIntToPtr(Res, LoadTy);
592592
}
593593
return Res;
594594
}

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6305,7 +6305,7 @@ bool CodeGenPrepare::optimizePhiType(
63056305
// correct type.
63066306
ValueToValueMap ValMap;
63076307
for (ConstantData *C : Constants)
6308-
ValMap[C] = ConstantExpr::getCast(Instruction::BitCast, C, ConvertTy);
6308+
ValMap[C] = ConstantExpr::getBitCast(C, ConvertTy);
63096309
for (Instruction *D : Defs) {
63106310
if (isa<BitCastInst>(D)) {
63116311
ValMap[D] = D->getOperand(0);

llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ Constant* createIRTypedAddress(FunctionType &FT, ExecutorAddr Addr) {
244244
Constant *AddrIntVal =
245245
ConstantInt::get(Type::getInt64Ty(FT.getContext()), Addr.getValue());
246246
Constant *AddrPtrVal =
247-
ConstantExpr::getCast(Instruction::IntToPtr, AddrIntVal,
248-
PointerType::get(&FT, 0));
247+
ConstantExpr::getIntToPtr(AddrIntVal, PointerType::get(&FT, 0));
249248
return AddrPtrVal;
250249
}
251250

llvm/unittests/Analysis/SparsePropagation.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ TEST_F(SparsePropagationTest, ComputeInstructionState) {
488488
///
489489
/// declare internal void @g()
490490
///
491-
/// define internal void @f() personality i8* bitcast (void ()* @p to i8*) {
491+
/// define internal void @f() personality ptr @p {
492492
/// entry:
493493
/// invoke void @g()
494494
/// to label %exit unwind label %catch.pad
@@ -513,9 +513,7 @@ TEST_F(SparsePropagationTest, ExceptionalTerminatorInsts) {
513513
GlobalValue::InternalLinkage, "g", &M);
514514
Function *F = Function::Create(FunctionType::get(Builder.getVoidTy(), false),
515515
GlobalValue::InternalLinkage, "f", &M);
516-
Constant *C =
517-
ConstantExpr::getCast(Instruction::BitCast, P, Builder.getInt8PtrTy());
518-
F->setPersonalityFn(C);
516+
F->setPersonalityFn(P);
519517
BasicBlock *Entry = BasicBlock::Create(Context, "entry", F);
520518
BasicBlock *Pad = BasicBlock::Create(Context, "catch.pad", F);
521519
BasicBlock *Body = BasicBlock::Create(Context, "catch.body", F);

llvm/unittests/Linker/LinkModulesTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ class LinkModuleTest : public testing::Test {
5151
Init.push_back(SwitchCase2BA);
5252

5353
ConstantInt *One = ConstantInt::get(Type::getInt32Ty(Ctx), 1);
54-
Constant *OnePtr = ConstantExpr::getCast(Instruction::IntToPtr, One,
55-
Type::getInt8PtrTy(Ctx));
54+
Constant *OnePtr = ConstantExpr::getIntToPtr(One, Type::getInt8PtrTy(Ctx));
5655
Init.push_back(OnePtr);
5756

5857
GV->setInitializer(ConstantArray::get(AT, Init));

0 commit comments

Comments
 (0)