Skip to content

Commit 9071a15

Browse files
authored
[llvm][Attributor] Strip AddressSpaceCast from 'constructPointer' (#74742)
* Remove pointer AddressSpaceCast in function `constructPointer` * Remove 1st parameter (`ResTy`) of function `constructPointer` 1st input argument to function `constructPointer` in all 4 call-sites is `ptr addrspace(0)`. Function `constructPointer` performs a pointer AddressSpaceCast to `ResTy`, making the returned pointer have type `ptr addrspace(0)` in all 4 call-sites. Unless there's a clear reason to discard the addrspace info of input parameter `Ptr`, I think we should keep and forward that info to the returned pointer of `constructPointer`. Opaque ptr cleanup effort.
1 parent 06d6af7 commit 9071a15

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,19 @@ static const Value *getPointerOperand(const Instruction *I,
290290
return nullptr;
291291
}
292292

293-
/// Helper function to create a pointer of type \p ResTy, based on \p Ptr, and
294-
/// advanced by \p Offset bytes. To aid later analysis the method tries to build
293+
/// Helper function to create a pointer based on \p Ptr, and advanced by \p
294+
/// Offset bytes. To aid later analysis the method tries to build
295295
/// getelement pointer instructions that traverse the natural type of \p Ptr if
296296
/// possible. If that fails, the remaining offset is adjusted byte-wise, hence
297297
/// through a cast to i8*.
298298
///
299299
/// TODO: This could probably live somewhere more prominantly if it doesn't
300300
/// already exist.
301-
static Value *constructPointer(Type *ResTy, Type *PtrElemTy, Value *Ptr,
302-
int64_t Offset, IRBuilder<NoFolder> &IRB,
303-
const DataLayout &DL) {
301+
static Value *constructPointer(Type *PtrElemTy, Value *Ptr, int64_t Offset,
302+
IRBuilder<NoFolder> &IRB, const DataLayout &DL) {
304303
assert(Offset >= 0 && "Negative offset not supported yet!");
305304
LLVM_DEBUG(dbgs() << "Construct pointer: " << *Ptr << " + " << Offset
306-
<< "-bytes as " << *ResTy << "\n");
305+
<< "-bytes\n");
307306

308307
if (Offset) {
309308
Type *Ty = PtrElemTy;
@@ -327,10 +326,6 @@ static Value *constructPointer(Type *ResTy, Type *PtrElemTy, Value *Ptr,
327326
}
328327
}
329328

330-
// Ensure the result has the requested type.
331-
Ptr = IRB.CreatePointerBitCastOrAddrSpaceCast(Ptr, ResTy,
332-
Ptr->getName() + ".cast");
333-
334329
LLVM_DEBUG(dbgs() << "Constructed pointer: " << *Ptr << "\n");
335330
return Ptr;
336331
}
@@ -7492,19 +7487,16 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
74927487
if (auto *PrivStructType = dyn_cast<StructType>(PrivType)) {
74937488
const StructLayout *PrivStructLayout = DL.getStructLayout(PrivStructType);
74947489
for (unsigned u = 0, e = PrivStructType->getNumElements(); u < e; u++) {
7495-
Type *PointeeTy = PrivStructType->getElementType(u)->getPointerTo();
7496-
Value *Ptr =
7497-
constructPointer(PointeeTy, PrivType, &Base,
7498-
PrivStructLayout->getElementOffset(u), IRB, DL);
7490+
Value *Ptr = constructPointer(
7491+
PrivType, &Base, PrivStructLayout->getElementOffset(u), IRB, DL);
74997492
new StoreInst(F.getArg(ArgNo + u), Ptr, &IP);
75007493
}
75017494
} else if (auto *PrivArrayType = dyn_cast<ArrayType>(PrivType)) {
75027495
Type *PointeeTy = PrivArrayType->getElementType();
7503-
Type *PointeePtrTy = PointeeTy->getPointerTo();
75047496
uint64_t PointeeTySize = DL.getTypeStoreSize(PointeeTy);
75057497
for (unsigned u = 0, e = PrivArrayType->getNumElements(); u < e; u++) {
7506-
Value *Ptr = constructPointer(PointeePtrTy, PrivType, &Base,
7507-
u * PointeeTySize, IRB, DL);
7498+
Value *Ptr =
7499+
constructPointer(PrivType, &Base, u * PointeeTySize, IRB, DL);
75087500
new StoreInst(F.getArg(ArgNo + u), Ptr, &IP);
75097501
}
75107502
} else {
@@ -7524,30 +7516,23 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
75247516
IRBuilder<NoFolder> IRB(IP);
75257517
const DataLayout &DL = IP->getModule()->getDataLayout();
75267518

7527-
Type *PrivPtrType = PrivType->getPointerTo();
7528-
if (Base->getType() != PrivPtrType)
7529-
Base = BitCastInst::CreatePointerBitCastOrAddrSpaceCast(
7530-
Base, PrivPtrType, "", ACS.getInstruction());
7531-
75327519
// Traverse the type, build GEPs and loads.
75337520
if (auto *PrivStructType = dyn_cast<StructType>(PrivType)) {
75347521
const StructLayout *PrivStructLayout = DL.getStructLayout(PrivStructType);
75357522
for (unsigned u = 0, e = PrivStructType->getNumElements(); u < e; u++) {
75367523
Type *PointeeTy = PrivStructType->getElementType(u);
7537-
Value *Ptr =
7538-
constructPointer(PointeeTy->getPointerTo(), PrivType, Base,
7539-
PrivStructLayout->getElementOffset(u), IRB, DL);
7524+
Value *Ptr = constructPointer(
7525+
PrivType, Base, PrivStructLayout->getElementOffset(u), IRB, DL);
75407526
LoadInst *L = new LoadInst(PointeeTy, Ptr, "", IP);
75417527
L->setAlignment(Alignment);
75427528
ReplacementValues.push_back(L);
75437529
}
75447530
} else if (auto *PrivArrayType = dyn_cast<ArrayType>(PrivType)) {
75457531
Type *PointeeTy = PrivArrayType->getElementType();
75467532
uint64_t PointeeTySize = DL.getTypeStoreSize(PointeeTy);
7547-
Type *PointeePtrTy = PointeeTy->getPointerTo();
75487533
for (unsigned u = 0, e = PrivArrayType->getNumElements(); u < e; u++) {
7549-
Value *Ptr = constructPointer(PointeePtrTy, PrivType, Base,
7550-
u * PointeeTySize, IRB, DL);
7534+
Value *Ptr =
7535+
constructPointer(PrivType, Base, u * PointeeTySize, IRB, DL);
75517536
LoadInst *L = new LoadInst(PointeeTy, Ptr, "", IP);
75527537
L->setAlignment(Alignment);
75537538
ReplacementValues.push_back(L);

0 commit comments

Comments
 (0)