Skip to content

Commit a7ee80f

Browse files
committed
[llvm] Drop some more typed pointer bitcasts etc.
1 parent 2c85b24 commit a7ee80f

File tree

12 files changed

+32
-63
lines changed

12 files changed

+32
-63
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7841,9 +7841,7 @@ static bool splitMergedValStore(StoreInst &SI, const DataLayout &DL,
78417841
bool IsLE = SI.getModule()->getDataLayout().isLittleEndian();
78427842
auto CreateSplitStore = [&](Value *V, bool Upper) {
78437843
V = Builder.CreateZExtOrBitCast(V, SplitStoreType);
7844-
Value *Addr = Builder.CreateBitCast(
7845-
SI.getOperand(1),
7846-
SplitStoreType->getPointerTo(SI.getPointerAddressSpace()));
7844+
Value *Addr = SI.getPointerOperand();
78477845
Align Alignment = SI.getAlign();
78487846
const bool IsOffsetStore = (IsLE && Upper) || (!IsLE && !Upper);
78497847
if (IsOffsetStore) {

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ llvm::createMemLibcall(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
689689
LLT OpLLT = MRI.getType(Reg);
690690
Type *OpTy = nullptr;
691691
if (OpLLT.isPointer())
692-
OpTy = Type::getInt8PtrTy(Ctx, OpLLT.getAddressSpace());
692+
OpTy = PointerType::get(Ctx, OpLLT.getAddressSpace());
693693
else
694694
OpTy = IntegerType::get(Ctx, OpLLT.getSizeInBits());
695695
Args.push_back({Reg, OpTy, 0});

llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,9 +934,8 @@ void LoadStoreOpt::initializeStoreMergeTargetInfo(unsigned AddrSpace) {
934934
BitVector LegalSizes(MaxStoreSizeToForm * 2);
935935
const auto &LI = *MF->getSubtarget().getLegalizerInfo();
936936
const auto &DL = MF->getFunction().getParent()->getDataLayout();
937-
Type *IntPtrIRTy =
938-
DL.getIntPtrType(MF->getFunction().getContext(), AddrSpace);
939-
LLT PtrTy = getLLTForType(*IntPtrIRTy->getPointerTo(AddrSpace), DL);
937+
Type *IRPtrTy = PointerType::get(MF->getFunction().getContext(), AddrSpace);
938+
LLT PtrTy = getLLTForType(*IRPtrTy, DL);
940939
// We assume that we're not going to be generating any stores wider than
941940
// MaxStoreSizeToForm bits for now.
942941
for (unsigned Size = 2; Size <= MaxStoreSizeToForm; Size *= 2) {

llvm/lib/CodeGen/JMCInstrumenter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void attachDebugInfo(GlobalVariable &GV, DISubprogram &SP) {
120120

121121
FunctionType *getCheckFunctionType(LLVMContext &Ctx) {
122122
Type *VoidTy = Type::getVoidTy(Ctx);
123-
PointerType *VoidPtrTy = Type::getInt8PtrTy(Ctx);
123+
PointerType *VoidPtrTy = PointerType::getUnqual(Ctx);
124124
return FunctionType::get(VoidTy, VoidPtrTy, false);
125125
}
126126

llvm/lib/IR/Constants.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,7 @@ BlockAddress *BlockAddress::get(Function *F, BasicBlock *BB) {
17701770
}
17711771

17721772
BlockAddress::BlockAddress(Function *F, BasicBlock *BB)
1773-
: Constant(Type::getInt8PtrTy(F->getContext(), F->getAddressSpace()),
1773+
: Constant(PointerType::get(F->getContext(), F->getAddressSpace()),
17741774
Value::BlockAddressVal, &Op<0>(), 2) {
17751775
setOperand(0, F);
17761776
setOperand(1, BB);

llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,7 @@ bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop,
20542054
// includes the load that feeds the stores. Check for an alias by generating
20552055
// the base address and checking everything.
20562056
Value *StoreBasePtr = Expander.expandCodeFor(StoreEv->getStart(),
2057-
Builder.getInt8PtrTy(SI->getPointerAddressSpace()), ExpPt);
2057+
Builder.getPtrTy(SI->getPointerAddressSpace()), ExpPt);
20582058
Value *LoadBasePtr = nullptr;
20592059

20602060
bool Overlap = false;
@@ -2125,7 +2125,7 @@ bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop,
21252125
// For a memcpy, we have to make sure that the input array is not being
21262126
// mutated by the loop.
21272127
LoadBasePtr = Expander.expandCodeFor(LoadEv->getStart(),
2128-
Builder.getInt8PtrTy(LI->getPointerAddressSpace()), ExpPt);
2128+
Builder.getPtrTy(LI->getPointerAddressSpace()), ExpPt);
21292129

21302130
SmallPtrSet<Instruction*, 2> Ignore2;
21312131
Ignore2.insert(SI);

llvm/lib/Transforms/Scalar/ConstantHoisting.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,12 +761,8 @@ void ConstantHoistingPass::emitBaseConstants(Instruction *Base,
761761
if (Adj->Offset) {
762762
if (Adj->Ty) {
763763
// Constant being rebased is a ConstantExpr.
764-
PointerType *Int8PtrTy = Type::getInt8PtrTy(
765-
*Ctx, cast<PointerType>(Adj->Ty)->getAddressSpace());
766-
Base = new BitCastInst(Base, Int8PtrTy, "base_bitcast", Adj->MatInsertPt);
767764
Mat = GetElementPtrInst::Create(Type::getInt8Ty(*Ctx), Base, Adj->Offset,
768765
"mat_gep", Adj->MatInsertPt);
769-
Mat = new BitCastInst(Mat, Adj->Ty, "mat_bitcast", Adj->MatInsertPt);
770766
} else
771767
// Constant being rebased is a ConstantInt.
772768
Mat = BinaryOperator::Create(Instruction::Add, Base, Adj->Offset,

llvm/lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ static PointerBounds expandBounds(const RuntimeCheckingPtrGroup *CG,
16401640
Loop *TheLoop, Instruction *Loc,
16411641
SCEVExpander &Exp) {
16421642
LLVMContext &Ctx = Loc->getContext();
1643-
Type *PtrArithTy = Type::getInt8PtrTy(Ctx, CG->AddressSpace);
1643+
Type *PtrArithTy = PointerType::get(Ctx, CG->AddressSpace);
16441644

16451645
Value *Start = nullptr, *End = nullptr;
16461646
LLVM_DEBUG(dbgs() << "LAA: Adding RT check for range:\n");
@@ -1693,21 +1693,13 @@ Value *llvm::addRuntimeChecks(
16931693
const PointerBounds &A = Check.first, &B = Check.second;
16941694
// Check if two pointers (A and B) conflict where conflict is computed as:
16951695
// start(A) <= end(B) && start(B) <= end(A)
1696-
unsigned AS0 = A.Start->getType()->getPointerAddressSpace();
1697-
unsigned AS1 = B.Start->getType()->getPointerAddressSpace();
16981696

1699-
assert((AS0 == B.End->getType()->getPointerAddressSpace()) &&
1700-
(AS1 == A.End->getType()->getPointerAddressSpace()) &&
1697+
assert((A.Start->getType()->getPointerAddressSpace() ==
1698+
B.End->getType()->getPointerAddressSpace()) &&
1699+
(B.Start->getType()->getPointerAddressSpace() ==
1700+
A.End->getType()->getPointerAddressSpace()) &&
17011701
"Trying to bounds check pointers with different address spaces");
17021702

1703-
Type *PtrArithTy0 = Type::getInt8PtrTy(Ctx, AS0);
1704-
Type *PtrArithTy1 = Type::getInt8PtrTy(Ctx, AS1);
1705-
1706-
Value *Start0 = ChkBuilder.CreateBitCast(A.Start, PtrArithTy0, "bc");
1707-
Value *Start1 = ChkBuilder.CreateBitCast(B.Start, PtrArithTy1, "bc");
1708-
Value *End0 = ChkBuilder.CreateBitCast(A.End, PtrArithTy1, "bc");
1709-
Value *End1 = ChkBuilder.CreateBitCast(B.End, PtrArithTy0, "bc");
1710-
17111703
// [A|B].Start points to the first accessed byte under base [A|B].
17121704
// [A|B].End points to the last accessed byte, plus one.
17131705
// There is no conflict when the intervals are disjoint:
@@ -1716,8 +1708,8 @@ Value *llvm::addRuntimeChecks(
17161708
// bound0 = (B.Start < A.End)
17171709
// bound1 = (A.Start < B.End)
17181710
// IsConflict = bound0 & bound1
1719-
Value *Cmp0 = ChkBuilder.CreateICmpULT(Start0, End1, "bound0");
1720-
Value *Cmp1 = ChkBuilder.CreateICmpULT(Start1, End0, "bound1");
1711+
Value *Cmp0 = ChkBuilder.CreateICmpULT(A.Start, B.End, "bound0");
1712+
Value *Cmp1 = ChkBuilder.CreateICmpULT(B.Start, A.End, "bound1");
17211713
Value *IsConflict = ChkBuilder.CreateAnd(Cmp0, Cmp1, "found.conflict");
17221714
if (MemoryRuntimeCheck) {
17231715
IsConflict =

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,10 @@ Value *SCEVExpander::InsertNoopCastOfTo(Value *V, Type *Ty) {
170170
if (Op == Instruction::IntToPtr) {
171171
auto *PtrTy = cast<PointerType>(Ty);
172172
if (DL.isNonIntegralPointerType(PtrTy)) {
173-
auto *Int8PtrTy = Builder.getInt8PtrTy(PtrTy->getAddressSpace());
174173
assert(DL.getTypeAllocSize(Builder.getInt8Ty()) == 1 &&
175174
"alloc size of i8 must by 1 byte for the GEP to be correct");
176175
return Builder.CreateGEP(
177-
Builder.getInt8Ty(), Constant::getNullValue(Int8PtrTy), V, "scevgep");
176+
Builder.getInt8Ty(), Constant::getNullValue(PtrTy), V, "scevgep");
178177
}
179178
}
180179
// Short-circuit unnecessary bitcasts.
@@ -2138,8 +2137,7 @@ Value *SCEVExpander::generateOverflowCheck(const SCEVAddRecExpr *AR,
21382137
bool NeedNegCheck = !SE.isKnownPositive(Step);
21392138

21402139
if (PointerType *ARPtrTy = dyn_cast<PointerType>(ARTy)) {
2141-
StartValue = InsertNoopCastOfTo(
2142-
StartValue, Builder.getInt8PtrTy(ARPtrTy->getAddressSpace()));
2140+
StartValue = InsertNoopCastOfTo(StartValue, ARPtrTy);
21432141
Value *NegMulV = Builder.CreateNeg(MulV);
21442142
if (NeedPosCheck)
21452143
Add = Builder.CreateGEP(Builder.getInt8Ty(), StartValue, MulV);
@@ -2245,7 +2243,7 @@ Value *SCEVExpander::fixupLCSSAFormFor(Value *V) {
22452243
// instruction.
22462244
Type *ToTy;
22472245
if (DefI->getType()->isIntegerTy())
2248-
ToTy = DefI->getType()->getPointerTo();
2246+
ToTy = PointerType::get(DefI->getContext(), 0);
22492247
else
22502248
ToTy = Type::getInt32Ty(DefI->getContext());
22512249
Instruction *User =

llvm/test/Transforms/ConstantHoisting/AArch64/const-hoist-gep.ll

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,12 @@ define dso_local void @zot() {
2121
; CHECK-NEXT: bb:
2222
; CHECK-NEXT: [[CONST:%.*]] = bitcast ptr getelementptr inbounds ([[TMP0:%.*]], ptr @global, i32 0, i32 4, i32 0, i32 0) to ptr
2323
; CHECK-NEXT: store i32 undef, ptr [[CONST]], align 4
24-
; CHECK-NEXT: [[BASE_BITCAST:%.*]] = bitcast ptr [[CONST]] to ptr
25-
; CHECK-NEXT: [[MAT_GEP:%.*]] = getelementptr i8, ptr [[BASE_BITCAST]], i32 4
26-
; CHECK-NEXT: [[MAT_BITCAST:%.*]] = bitcast ptr [[MAT_GEP]] to ptr
27-
; CHECK-NEXT: store i32 undef, ptr [[MAT_BITCAST]], align 4
28-
; CHECK-NEXT: [[BASE_BITCAST1:%.*]] = bitcast ptr [[CONST]] to ptr
29-
; CHECK-NEXT: [[MAT_GEP2:%.*]] = getelementptr i8, ptr [[BASE_BITCAST1]], i32 160
30-
; CHECK-NEXT: [[MAT_BITCAST3:%.*]] = bitcast ptr [[MAT_GEP2]] to ptr
31-
; CHECK-NEXT: store i32 undef, ptr [[MAT_BITCAST3]], align 4
32-
; CHECK-NEXT: [[BASE_BITCAST4:%.*]] = bitcast ptr [[CONST]] to ptr
33-
; CHECK-NEXT: [[MAT_GEP5:%.*]] = getelementptr i8, ptr [[BASE_BITCAST4]], i32 164
34-
; CHECK-NEXT: [[MAT_BITCAST6:%.*]] = bitcast ptr [[MAT_GEP5]] to ptr
35-
; CHECK-NEXT: store i32 undef, ptr [[MAT_BITCAST6]], align 4
24+
; CHECK-NEXT: [[MAT_GEP:%.*]] = getelementptr i8, ptr [[CONST]], i32 4
25+
; CHECK-NEXT: store i32 undef, ptr [[MAT_GEP]], align 4
26+
; CHECK-NEXT: [[MAT_GEP1:%.*]] = getelementptr i8, ptr [[CONST]], i32 160
27+
; CHECK-NEXT: store i32 undef, ptr [[MAT_GEP1]], align 4
28+
; CHECK-NEXT: [[MAT_GEP2:%.*]] = getelementptr i8, ptr [[CONST]], i32 164
29+
; CHECK-NEXT: store i32 undef, ptr [[MAT_GEP2]], align 4
3630
; CHECK-NEXT: ret void
3731
;
3832
bb:

llvm/test/Transforms/ConstantHoisting/ARM/const-hoist-gep-overindexing.ll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ define void @test_inbounds() {
1313
; CHECK-NEXT: bb:
1414
; CHECK-NEXT: [[CONST:%.*]] = bitcast ptr getelementptr inbounds ([[TMP0:%.*]], ptr @global, i32 0, i32 1, i32 0) to ptr
1515
; CHECK-NEXT: store i16 undef, ptr [[CONST]], align 2
16-
; CHECK-NEXT: [[BASE_BITCAST:%.*]] = bitcast ptr [[CONST]] to ptr
17-
; CHECK-NEXT: [[MAT_GEP:%.*]] = getelementptr i8, ptr [[BASE_BITCAST]], i32 2
18-
; CHECK-NEXT: [[MAT_BITCAST:%.*]] = bitcast ptr [[MAT_GEP]] to ptr
19-
; CHECK-NEXT: store i16 undef, ptr [[MAT_BITCAST]], align 2
20-
; CHECK-NEXT: [[BASE_BITCAST1:%.*]] = bitcast ptr [[CONST]] to ptr
21-
; CHECK-NEXT: [[MAT_GEP2:%.*]] = getelementptr i8, ptr [[BASE_BITCAST1]], i32 20
22-
; CHECK-NEXT: [[MAT_BITCAST3:%.*]] = bitcast ptr [[MAT_GEP2]] to ptr
23-
; CHECK-NEXT: store i16 undef, ptr [[MAT_BITCAST3]], align 2
16+
; CHECK-NEXT: [[MAT_GEP:%.*]] = getelementptr i8, ptr [[CONST]], i32 2
17+
; CHECK-NEXT: store i16 undef, ptr [[MAT_GEP]], align 2
18+
; CHECK-NEXT: [[MAT_GEP1:%.*]] = getelementptr i8, ptr [[CONST]], i32 20
19+
; CHECK-NEXT: store i16 undef, ptr [[MAT_GEP1]], align 2
2420
; CHECK-NEXT: ret void
2521
;
2622
bb:

llvm/test/Transforms/ConstantHoisting/ARM/const-hoist-gep.ll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@ define dso_local void @zot() {
2323
; CHECK-NEXT: [[CONST1:%.*]] = bitcast ptr getelementptr inbounds ([[TMP0:%.*]], ptr @global, i32 0, i32 4, i32 11, i32 0) to ptr
2424
; CHECK-NEXT: [[CONST:%.*]] = bitcast ptr getelementptr inbounds ([[TMP0]], ptr @global, i32 0, i32 4, i32 0, i32 0) to ptr
2525
; CHECK-NEXT: store i32 undef, ptr [[CONST]], align 4
26-
; CHECK-NEXT: [[BASE_BITCAST:%.*]] = bitcast ptr [[CONST]] to ptr
27-
; CHECK-NEXT: [[MAT_GEP:%.*]] = getelementptr i8, ptr [[BASE_BITCAST]], i32 4
28-
; CHECK-NEXT: [[MAT_BITCAST:%.*]] = bitcast ptr [[MAT_GEP]] to ptr
29-
; CHECK-NEXT: store i32 undef, ptr [[MAT_BITCAST]], align 4
26+
; CHECK-NEXT: [[MAT_GEP:%.*]] = getelementptr i8, ptr [[CONST]], i32 4
27+
; CHECK-NEXT: store i32 undef, ptr [[MAT_GEP]], align 4
3028
; CHECK-NEXT: store i32 undef, ptr [[CONST1]], align 4
31-
; CHECK-NEXT: [[BASE_BITCAST2:%.*]] = bitcast ptr [[CONST1]] to ptr
32-
; CHECK-NEXT: [[MAT_GEP3:%.*]] = getelementptr i8, ptr [[BASE_BITCAST2]], i32 4
33-
; CHECK-NEXT: [[MAT_BITCAST4:%.*]] = bitcast ptr [[MAT_GEP3]] to ptr
34-
; CHECK-NEXT: store i32 undef, ptr [[MAT_BITCAST4]], align 4
29+
; CHECK-NEXT: [[MAT_GEP2:%.*]] = getelementptr i8, ptr [[CONST1]], i32 4
30+
; CHECK-NEXT: store i32 undef, ptr [[MAT_GEP2]], align 4
3531
; CHECK-NEXT: ret void
3632
;
3733
bb:

0 commit comments

Comments
 (0)