Skip to content

Commit 145aff6

Browse files
committed
Clean up pointer casts etc after opaque pointers transition. NFC (#102631)
1 parent 1ff06c5 commit 145aff6

File tree

7 files changed

+21
-34
lines changed

7 files changed

+21
-34
lines changed

llvm/examples/BrainF/BrainFDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void addMainFunction(Module *mod) {
7272
FunctionType *main_func_fty = FunctionType::get(
7373
Type::getInt32Ty(mod->getContext()),
7474
{Type::getInt32Ty(mod->getContext()),
75-
Type::getInt8Ty(mod->getContext())->getPointerTo()->getPointerTo()},
75+
PointerType::getUnqual(mod->getContext())},
7676
false);
7777
Function *main_func =
7878
Function::Create(main_func_fty, Function::ExternalLinkage, "main", mod);

llvm/examples/ExceptionDemo/ExceptionDemo.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,8 +1244,7 @@ static llvm::Function *createCatchWrappedInvokeFunction(
12441244
llvm::Value *unwindExceptionClass =
12451245
builder.CreateLoad(builder.CreateStructGEP(
12461246
ourUnwindExceptionType,
1247-
builder.CreatePointerCast(unwindException,
1248-
ourUnwindExceptionType->getPointerTo()),
1247+
unwindException,
12491248
0));
12501249

12511250
// Branch to the externalExceptionBlock if the exception is foreign or
@@ -1277,10 +1276,8 @@ static llvm::Function *createCatchWrappedInvokeFunction(
12771276
// (OurException instance).
12781277
//
12791278
// Note: ourBaseFromUnwindOffset is usually negative
1280-
llvm::Value *typeInfoThrown = builder.CreatePointerCast(
1281-
builder.CreateConstGEP1_64(unwindException,
1282-
ourBaseFromUnwindOffset),
1283-
ourExceptionType->getPointerTo());
1279+
llvm::Value *typeInfoThrown = builder.CreateConstGEP1_64(unwindException,
1280+
ourBaseFromUnwindOffset));
12841281

12851282
// Retrieve thrown exception type info type
12861283
//

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,8 +2453,8 @@ bool AsmPrinter::doFinalization(Module &M) {
24532453
auto SymbolName = "swift_async_extendedFramePointerFlags";
24542454
auto Global = M.getGlobalVariable(SymbolName);
24552455
if (!Global) {
2456-
auto Int8PtrTy = PointerType::getUnqual(M.getContext());
2457-
Global = new GlobalVariable(M, Int8PtrTy, false,
2456+
auto PtrTy = PointerType::getUnqual(M.getContext());
2457+
Global = new GlobalVariable(M, PtrTy, false,
24582458
GlobalValue::ExternalWeakLinkage, nullptr,
24592459
SymbolName);
24602460
OutStreamer->emitSymbolAttribute(getSymbol(Global), MCSA_WeakReference);

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4567,7 +4567,7 @@ Instruction *InstCombinerImpl::foldNot(BinaryOperator &I) {
45674567
Type *SextTy = cast<BitCastOperator>(NotOp)->getSrcTy();
45684568
Value *NotX = Builder.CreateNot(X);
45694569
Value *Sext = Builder.CreateSExt(NotX, SextTy);
4570-
return CastInst::CreateBitOrPointerCast(Sext, Ty);
4570+
return new BitCastInst(Sext, Ty);
45714571
}
45724572

45734573
if (auto *NotOpI = dyn_cast<Instruction>(NotOp))

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2386,7 +2386,7 @@ static Instruction *foldSelectCmpBitcasts(SelectInst &Sel,
23862386
} else {
23872387
return nullptr;
23882388
}
2389-
return CastInst::CreateBitOrPointerCast(NewSel, Sel.getType());
2389+
return new BitCastInst(NewSel, Sel.getType());
23902390
}
23912391

23922392
/// Try to eliminate select instructions that test the returned flag of cmpxchg

llvm/lib/Transforms/Scalar/NaryReassociate.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,7 @@ NaryReassociatePass::tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
421421
return nullptr;
422422

423423
IRBuilder<> Builder(GEP);
424-
// Candidate does not necessarily have the same pointer type as GEP. Use
425-
// bitcast or pointer cast to make sure they have the same type, so that the
426-
// later RAUW doesn't complain.
427-
Candidate = Builder.CreateBitOrPointerCast(Candidate, GEP->getType());
424+
// Candidate should have the same pointer type as GEP.
428425
assert(Candidate->getType() == GEP->getType());
429426

430427
// NewGEP = (char *)Candidate + RHS * sizeof(IndexedType)

llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ TEST_F(ScalarEvolutionExpanderTest, ExpandPtrTypeSCEV) {
7373
// expansion when the value in ValueOffsetPair is a ptr and the offset
7474
// is not divisible by the elem type size of value.
7575
auto *I8Ty = Type::getInt8Ty(Context);
76-
auto *I8PtrTy = PointerType::get(Context, 0);
76+
auto *PtrTy = PointerType::get(Context, 0);
7777
auto *I32Ty = Type::getInt32Ty(Context);
78-
auto *I32PtrTy = PointerType::get(Context, 0);
7978
FunctionType *FTy =
8079
FunctionType::get(Type::getVoidTy(Context), std::vector<Type *>(), false);
8180
Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M);
@@ -87,13 +86,11 @@ TEST_F(ScalarEvolutionExpanderTest, ExpandPtrTypeSCEV) {
8786

8887
// loop: ; preds = %loop, %entry
8988
// %alloca = alloca i32
90-
// %gep0 = getelementptr i32, i32* %alloca, i32 1
91-
// %bitcast1 = bitcast i32* %gep0 to i8*
92-
// %gep1 = getelementptr i8, i8* %bitcast1, i32 1
93-
// %gep2 = getelementptr i8, i8* undef, i32 1
94-
// %cmp = icmp ult i8* undef, %bitcast1
95-
// %select = select i1 %cmp, i8* %gep1, i8* %gep2
96-
// %bitcast2 = bitcast i8* %select to i32*
89+
// %gep0 = getelementptr i32, ptr %alloca, i32 1
90+
// %gep1 = getelementptr i8, ptr %gep0, i32 1
91+
// %gep2 = getelementptr i8, ptr undef, i32 1
92+
// %cmp = icmp ult ptr undef, %gep0
93+
// %select = select i1 %cmp, ptr %gep1, ptr %gep2
9794
// br i1 undef, label %loop, label %exit
9895

9996
const DataLayout &DL = F->getDataLayout();
@@ -102,24 +99,20 @@ TEST_F(ScalarEvolutionExpanderTest, ExpandPtrTypeSCEV) {
10299
AllocaInst *Alloca = new AllocaInst(I32Ty, DL.getAllocaAddrSpace(), "alloca",
103100
Br->getIterator());
104101
ConstantInt *Ci32 = ConstantInt::get(Context, APInt(32, 1));
102+
UndefValue *UndefPtr = UndefValue::get(PtrTy);
105103
GetElementPtrInst *Gep0 =
106104
GetElementPtrInst::Create(I32Ty, Alloca, Ci32, "gep0", Br->getIterator());
107-
CastInst *CastA = CastInst::CreateBitOrPointerCast(Gep0, I8PtrTy, "bitcast1",
108-
Br->getIterator());
109105
GetElementPtrInst *Gep1 =
110-
GetElementPtrInst::Create(I8Ty, CastA, Ci32, "gep1", Br->getIterator());
106+
GetElementPtrInst::Create(I8Ty, Gep0, Ci32, "gep1", Br->getIterator());
111107
GetElementPtrInst *Gep2 = GetElementPtrInst::Create(
112-
I8Ty, UndefValue::get(I8PtrTy), Ci32, "gep2", Br->getIterator());
108+
I8Ty, UndefPtr, Ci32, "gep2", Br->getIterator());
113109
CmpInst *Cmp = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_ULT,
114-
UndefValue::get(I8PtrTy), CastA, "cmp",
115-
Br->getIterator());
116-
SelectInst *Sel =
110+
UndefPtr, Gep0, "cmp", Br->getIterator());
111+
SelectInst *Select =
117112
SelectInst::Create(Cmp, Gep1, Gep2, "select", Br->getIterator());
118-
CastInst *CastB = CastInst::CreateBitOrPointerCast(Sel, I32PtrTy, "bitcast2",
119-
Br->getIterator());
120113

121114
ScalarEvolution SE = buildSE(*F);
122-
const SCEV *S = SE.getSCEV(CastB);
115+
const SCEV *S = SE.getSCEV(Select);
123116
EXPECT_TRUE(isa<SCEVUnknown>(S));
124117
}
125118

0 commit comments

Comments
 (0)