[llvm] a7ee80f - [llvm] Drop some more typed pointer bitcasts etc.

Bjorn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 13 07:53:17 PDT 2023


Author: Bjorn Pettersson
Date: 2023-08-13T16:46:56+02:00
New Revision: a7ee80fab213fe7a52b159e3a6c13c7355c30b25

URL: https://github.com/llvm/llvm-project/commit/a7ee80fab213fe7a52b159e3a6c13c7355c30b25
DIFF: https://github.com/llvm/llvm-project/commit/a7ee80fab213fe7a52b159e3a6c13c7355c30b25.diff

LOG: [llvm] Drop some more typed pointer bitcasts etc.

Added: 
    

Modified: 
    llvm/lib/CodeGen/CodeGenPrepare.cpp
    llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
    llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp
    llvm/lib/CodeGen/JMCInstrumenter.cpp
    llvm/lib/IR/Constants.cpp
    llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
    llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
    llvm/lib/Transforms/Utils/LoopUtils.cpp
    llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
    llvm/test/Transforms/ConstantHoisting/AArch64/const-hoist-gep.ll
    llvm/test/Transforms/ConstantHoisting/ARM/const-hoist-gep-overindexing.ll
    llvm/test/Transforms/ConstantHoisting/ARM/const-hoist-gep.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index ac4a29338abd06..e44682fc21f710 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -7841,9 +7841,7 @@ static bool splitMergedValStore(StoreInst &SI, const DataLayout &DL,
   bool IsLE = SI.getModule()->getDataLayout().isLittleEndian();
   auto CreateSplitStore = [&](Value *V, bool Upper) {
     V = Builder.CreateZExtOrBitCast(V, SplitStoreType);
-    Value *Addr = Builder.CreateBitCast(
-        SI.getOperand(1),
-        SplitStoreType->getPointerTo(SI.getPointerAddressSpace()));
+    Value *Addr = SI.getPointerOperand();
     Align Alignment = SI.getAlign();
     const bool IsOffsetStore = (IsLE && Upper) || (!IsLE && !Upper);
     if (IsOffsetStore) {

diff  --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 023f72b84fd7c8..5a93bb9c32eaaf 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -689,7 +689,7 @@ llvm::createMemLibcall(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
     LLT OpLLT = MRI.getType(Reg);
     Type *OpTy = nullptr;
     if (OpLLT.isPointer())
-      OpTy = Type::getInt8PtrTy(Ctx, OpLLT.getAddressSpace());
+      OpTy = PointerType::get(Ctx, OpLLT.getAddressSpace());
     else
       OpTy = IntegerType::get(Ctx, OpLLT.getSizeInBits());
     Args.push_back({Reg, OpTy, 0});

diff  --git a/llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp b/llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp
index 49f40495d6fc9f..246aa88b09acf6 100644
--- a/llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp
@@ -934,9 +934,8 @@ void LoadStoreOpt::initializeStoreMergeTargetInfo(unsigned AddrSpace) {
   BitVector LegalSizes(MaxStoreSizeToForm * 2);
   const auto &LI = *MF->getSubtarget().getLegalizerInfo();
   const auto &DL = MF->getFunction().getParent()->getDataLayout();
-  Type *IntPtrIRTy =
-      DL.getIntPtrType(MF->getFunction().getContext(), AddrSpace);
-  LLT PtrTy = getLLTForType(*IntPtrIRTy->getPointerTo(AddrSpace), DL);
+  Type *IRPtrTy = PointerType::get(MF->getFunction().getContext(), AddrSpace);
+  LLT PtrTy = getLLTForType(*IRPtrTy, DL);
   // We assume that we're not going to be generating any stores wider than
   // MaxStoreSizeToForm bits for now.
   for (unsigned Size = 2; Size <= MaxStoreSizeToForm; Size *= 2) {

diff  --git a/llvm/lib/CodeGen/JMCInstrumenter.cpp b/llvm/lib/CodeGen/JMCInstrumenter.cpp
index f1953c363b5969..a1f0a50406643e 100644
--- a/llvm/lib/CodeGen/JMCInstrumenter.cpp
+++ b/llvm/lib/CodeGen/JMCInstrumenter.cpp
@@ -120,7 +120,7 @@ void attachDebugInfo(GlobalVariable &GV, DISubprogram &SP) {
 
 FunctionType *getCheckFunctionType(LLVMContext &Ctx) {
   Type *VoidTy = Type::getVoidTy(Ctx);
-  PointerType *VoidPtrTy = Type::getInt8PtrTy(Ctx);
+  PointerType *VoidPtrTy = PointerType::getUnqual(Ctx);
   return FunctionType::get(VoidTy, VoidPtrTy, false);
 }
 

diff  --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 8ea799f0232c56..c9b94ba647c70f 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -1770,7 +1770,7 @@ BlockAddress *BlockAddress::get(Function *F, BasicBlock *BB) {
 }
 
 BlockAddress::BlockAddress(Function *F, BasicBlock *BB)
-    : Constant(Type::getInt8PtrTy(F->getContext(), F->getAddressSpace()),
+    : Constant(PointerType::get(F->getContext(), F->getAddressSpace()),
                Value::BlockAddressVal, &Op<0>(), 2) {
   setOperand(0, F);
   setOperand(1, BB);

diff  --git a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
index 7e68e05dc63e23..51ef72b873a516 100644
--- a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
@@ -2054,7 +2054,7 @@ bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop,
   // includes the load that feeds the stores.  Check for an alias by generating
   // the base address and checking everything.
   Value *StoreBasePtr = Expander.expandCodeFor(StoreEv->getStart(),
-      Builder.getInt8PtrTy(SI->getPointerAddressSpace()), ExpPt);
+      Builder.getPtrTy(SI->getPointerAddressSpace()), ExpPt);
   Value *LoadBasePtr = nullptr;
 
   bool Overlap = false;
@@ -2125,7 +2125,7 @@ bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop,
   // For a memcpy, we have to make sure that the input array is not being
   // mutated by the loop.
   LoadBasePtr = Expander.expandCodeFor(LoadEv->getStart(),
-      Builder.getInt8PtrTy(LI->getPointerAddressSpace()), ExpPt);
+      Builder.getPtrTy(LI->getPointerAddressSpace()), ExpPt);
 
   SmallPtrSet<Instruction*, 2> Ignore2;
   Ignore2.insert(SI);

diff  --git a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
index 611e64bd097680..0c9dea343a25e7 100644
--- a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
@@ -761,12 +761,8 @@ void ConstantHoistingPass::emitBaseConstants(Instruction *Base,
   if (Adj->Offset) {
     if (Adj->Ty) {
       // Constant being rebased is a ConstantExpr.
-      PointerType *Int8PtrTy = Type::getInt8PtrTy(
-          *Ctx, cast<PointerType>(Adj->Ty)->getAddressSpace());
-      Base = new BitCastInst(Base, Int8PtrTy, "base_bitcast", Adj->MatInsertPt);
       Mat = GetElementPtrInst::Create(Type::getInt8Ty(*Ctx), Base, Adj->Offset,
                                       "mat_gep", Adj->MatInsertPt);
-      Mat = new BitCastInst(Mat, Adj->Ty, "mat_bitcast", Adj->MatInsertPt);
     } else
       // Constant being rebased is a ConstantInt.
       Mat = BinaryOperator::Create(Instruction::Add, Base, Adj->Offset,

diff  --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 273c6591dd5013..f99cf3d4b3320a 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -1640,7 +1640,7 @@ static PointerBounds expandBounds(const RuntimeCheckingPtrGroup *CG,
                                   Loop *TheLoop, Instruction *Loc,
                                   SCEVExpander &Exp) {
   LLVMContext &Ctx = Loc->getContext();
-  Type *PtrArithTy = Type::getInt8PtrTy(Ctx, CG->AddressSpace);
+  Type *PtrArithTy = PointerType::get(Ctx, CG->AddressSpace);
 
   Value *Start = nullptr, *End = nullptr;
   LLVM_DEBUG(dbgs() << "LAA: Adding RT check for range:\n");
@@ -1693,21 +1693,13 @@ Value *llvm::addRuntimeChecks(
     const PointerBounds &A = Check.first, &B = Check.second;
     // Check if two pointers (A and B) conflict where conflict is computed as:
     // start(A) <= end(B) && start(B) <= end(A)
-    unsigned AS0 = A.Start->getType()->getPointerAddressSpace();
-    unsigned AS1 = B.Start->getType()->getPointerAddressSpace();
 
-    assert((AS0 == B.End->getType()->getPointerAddressSpace()) &&
-           (AS1 == A.End->getType()->getPointerAddressSpace()) &&
+    assert((A.Start->getType()->getPointerAddressSpace() ==
+            B.End->getType()->getPointerAddressSpace()) &&
+           (B.Start->getType()->getPointerAddressSpace() ==
+            A.End->getType()->getPointerAddressSpace()) &&
            "Trying to bounds check pointers with 
diff erent address spaces");
 
-    Type *PtrArithTy0 = Type::getInt8PtrTy(Ctx, AS0);
-    Type *PtrArithTy1 = Type::getInt8PtrTy(Ctx, AS1);
-
-    Value *Start0 = ChkBuilder.CreateBitCast(A.Start, PtrArithTy0, "bc");
-    Value *Start1 = ChkBuilder.CreateBitCast(B.Start, PtrArithTy1, "bc");
-    Value *End0 = ChkBuilder.CreateBitCast(A.End, PtrArithTy1, "bc");
-    Value *End1 = ChkBuilder.CreateBitCast(B.End, PtrArithTy0, "bc");
-
     // [A|B].Start points to the first accessed byte under base [A|B].
     // [A|B].End points to the last accessed byte, plus one.
     // There is no conflict when the intervals are disjoint:
@@ -1716,8 +1708,8 @@ Value *llvm::addRuntimeChecks(
     // bound0 = (B.Start < A.End)
     // bound1 = (A.Start < B.End)
     //  IsConflict = bound0 & bound1
-    Value *Cmp0 = ChkBuilder.CreateICmpULT(Start0, End1, "bound0");
-    Value *Cmp1 = ChkBuilder.CreateICmpULT(Start1, End0, "bound1");
+    Value *Cmp0 = ChkBuilder.CreateICmpULT(A.Start, B.End, "bound0");
+    Value *Cmp1 = ChkBuilder.CreateICmpULT(B.Start, A.End, "bound1");
     Value *IsConflict = ChkBuilder.CreateAnd(Cmp0, Cmp1, "found.conflict");
     if (MemoryRuntimeCheck) {
       IsConflict =

diff  --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index f41aa47c7c9b83..a6c7e0628a0c19 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -170,11 +170,10 @@ Value *SCEVExpander::InsertNoopCastOfTo(Value *V, Type *Ty) {
   if (Op == Instruction::IntToPtr) {
     auto *PtrTy = cast<PointerType>(Ty);
     if (DL.isNonIntegralPointerType(PtrTy)) {
-      auto *Int8PtrTy = Builder.getInt8PtrTy(PtrTy->getAddressSpace());
       assert(DL.getTypeAllocSize(Builder.getInt8Ty()) == 1 &&
              "alloc size of i8 must by 1 byte for the GEP to be correct");
       return Builder.CreateGEP(
-          Builder.getInt8Ty(), Constant::getNullValue(Int8PtrTy), V, "scevgep");
+          Builder.getInt8Ty(), Constant::getNullValue(PtrTy), V, "scevgep");
     }
   }
   // Short-circuit unnecessary bitcasts.
@@ -2138,8 +2137,7 @@ Value *SCEVExpander::generateOverflowCheck(const SCEVAddRecExpr *AR,
     bool NeedNegCheck = !SE.isKnownPositive(Step);
 
     if (PointerType *ARPtrTy = dyn_cast<PointerType>(ARTy)) {
-      StartValue = InsertNoopCastOfTo(
-          StartValue, Builder.getInt8PtrTy(ARPtrTy->getAddressSpace()));
+      StartValue = InsertNoopCastOfTo(StartValue, ARPtrTy);
       Value *NegMulV = Builder.CreateNeg(MulV);
       if (NeedPosCheck)
         Add = Builder.CreateGEP(Builder.getInt8Ty(), StartValue, MulV);
@@ -2245,7 +2243,7 @@ Value *SCEVExpander::fixupLCSSAFormFor(Value *V) {
   // instruction.
   Type *ToTy;
   if (DefI->getType()->isIntegerTy())
-    ToTy = DefI->getType()->getPointerTo();
+    ToTy = PointerType::get(DefI->getContext(), 0);
   else
     ToTy = Type::getInt32Ty(DefI->getContext());
   Instruction *User =

diff  --git a/llvm/test/Transforms/ConstantHoisting/AArch64/const-hoist-gep.ll b/llvm/test/Transforms/ConstantHoisting/AArch64/const-hoist-gep.ll
index e53d2b3833d009..e540b146f560f4 100644
--- a/llvm/test/Transforms/ConstantHoisting/AArch64/const-hoist-gep.ll
+++ b/llvm/test/Transforms/ConstantHoisting/AArch64/const-hoist-gep.ll
@@ -21,18 +21,12 @@ define dso_local void @zot() {
 ; CHECK-NEXT:  bb:
 ; CHECK-NEXT:    [[CONST:%.*]] = bitcast ptr getelementptr inbounds ([[TMP0:%.*]], ptr @global, i32 0, i32 4, i32 0, i32 0) to ptr
 ; CHECK-NEXT:    store i32 undef, ptr [[CONST]], align 4
-; CHECK-NEXT:    [[BASE_BITCAST:%.*]] = bitcast ptr [[CONST]] to ptr
-; CHECK-NEXT:    [[MAT_GEP:%.*]] = getelementptr i8, ptr [[BASE_BITCAST]], i32 4
-; CHECK-NEXT:    [[MAT_BITCAST:%.*]] = bitcast ptr [[MAT_GEP]] to ptr
-; CHECK-NEXT:    store i32 undef, ptr [[MAT_BITCAST]], align 4
-; CHECK-NEXT:    [[BASE_BITCAST1:%.*]] = bitcast ptr [[CONST]] to ptr
-; CHECK-NEXT:    [[MAT_GEP2:%.*]] = getelementptr i8, ptr [[BASE_BITCAST1]], i32 160
-; CHECK-NEXT:    [[MAT_BITCAST3:%.*]] = bitcast ptr [[MAT_GEP2]] to ptr
-; CHECK-NEXT:    store i32 undef, ptr [[MAT_BITCAST3]], align 4
-; CHECK-NEXT:    [[BASE_BITCAST4:%.*]] = bitcast ptr [[CONST]] to ptr
-; CHECK-NEXT:    [[MAT_GEP5:%.*]] = getelementptr i8, ptr [[BASE_BITCAST4]], i32 164
-; CHECK-NEXT:    [[MAT_BITCAST6:%.*]] = bitcast ptr [[MAT_GEP5]] to ptr
-; CHECK-NEXT:    store i32 undef, ptr [[MAT_BITCAST6]], align 4
+; CHECK-NEXT:    [[MAT_GEP:%.*]] = getelementptr i8, ptr [[CONST]], i32 4
+; CHECK-NEXT:    store i32 undef, ptr [[MAT_GEP]], align 4
+; CHECK-NEXT:    [[MAT_GEP1:%.*]] = getelementptr i8, ptr [[CONST]], i32 160
+; CHECK-NEXT:    store i32 undef, ptr [[MAT_GEP1]], align 4
+; CHECK-NEXT:    [[MAT_GEP2:%.*]] = getelementptr i8, ptr [[CONST]], i32 164
+; CHECK-NEXT:    store i32 undef, ptr [[MAT_GEP2]], align 4
 ; CHECK-NEXT:    ret void
 ;
 bb:

diff  --git a/llvm/test/Transforms/ConstantHoisting/ARM/const-hoist-gep-overindexing.ll b/llvm/test/Transforms/ConstantHoisting/ARM/const-hoist-gep-overindexing.ll
index 98083534fa89b6..36ef7045fd05ee 100644
--- a/llvm/test/Transforms/ConstantHoisting/ARM/const-hoist-gep-overindexing.ll
+++ b/llvm/test/Transforms/ConstantHoisting/ARM/const-hoist-gep-overindexing.ll
@@ -13,14 +13,10 @@ define void @test_inbounds() {
 ; CHECK-NEXT:  bb:
 ; CHECK-NEXT:    [[CONST:%.*]] = bitcast ptr getelementptr inbounds ([[TMP0:%.*]], ptr @global, i32 0, i32 1, i32 0) to ptr
 ; CHECK-NEXT:    store i16 undef, ptr [[CONST]], align 2
-; CHECK-NEXT:    [[BASE_BITCAST:%.*]] = bitcast ptr [[CONST]] to ptr
-; CHECK-NEXT:    [[MAT_GEP:%.*]] = getelementptr i8, ptr [[BASE_BITCAST]], i32 2
-; CHECK-NEXT:    [[MAT_BITCAST:%.*]] = bitcast ptr [[MAT_GEP]] to ptr
-; CHECK-NEXT:    store i16 undef, ptr [[MAT_BITCAST]], align 2
-; CHECK-NEXT:    [[BASE_BITCAST1:%.*]] = bitcast ptr [[CONST]] to ptr
-; CHECK-NEXT:    [[MAT_GEP2:%.*]] = getelementptr i8, ptr [[BASE_BITCAST1]], i32 20
-; CHECK-NEXT:    [[MAT_BITCAST3:%.*]] = bitcast ptr [[MAT_GEP2]] to ptr
-; CHECK-NEXT:    store i16 undef, ptr [[MAT_BITCAST3]], align 2
+; CHECK-NEXT:    [[MAT_GEP:%.*]] = getelementptr i8, ptr [[CONST]], i32 2
+; CHECK-NEXT:    store i16 undef, ptr [[MAT_GEP]], align 2
+; CHECK-NEXT:    [[MAT_GEP1:%.*]] = getelementptr i8, ptr [[CONST]], i32 20
+; CHECK-NEXT:    store i16 undef, ptr [[MAT_GEP1]], align 2
 ; CHECK-NEXT:    ret void
 ;
 bb:

diff  --git a/llvm/test/Transforms/ConstantHoisting/ARM/const-hoist-gep.ll b/llvm/test/Transforms/ConstantHoisting/ARM/const-hoist-gep.ll
index c7c709b80288f5..b5c58aaa367098 100644
--- a/llvm/test/Transforms/ConstantHoisting/ARM/const-hoist-gep.ll
+++ b/llvm/test/Transforms/ConstantHoisting/ARM/const-hoist-gep.ll
@@ -23,15 +23,11 @@ define dso_local void @zot() {
 ; CHECK-NEXT:    [[CONST1:%.*]] = bitcast ptr getelementptr inbounds ([[TMP0:%.*]], ptr @global, i32 0, i32 4, i32 11, i32 0) to ptr
 ; CHECK-NEXT:    [[CONST:%.*]] = bitcast ptr getelementptr inbounds ([[TMP0]], ptr @global, i32 0, i32 4, i32 0, i32 0) to ptr
 ; CHECK-NEXT:    store i32 undef, ptr [[CONST]], align 4
-; CHECK-NEXT:    [[BASE_BITCAST:%.*]] = bitcast ptr [[CONST]] to ptr
-; CHECK-NEXT:    [[MAT_GEP:%.*]] = getelementptr i8, ptr [[BASE_BITCAST]], i32 4
-; CHECK-NEXT:    [[MAT_BITCAST:%.*]] = bitcast ptr [[MAT_GEP]] to ptr
-; CHECK-NEXT:    store i32 undef, ptr [[MAT_BITCAST]], align 4
+; CHECK-NEXT:    [[MAT_GEP:%.*]] = getelementptr i8, ptr [[CONST]], i32 4
+; CHECK-NEXT:    store i32 undef, ptr [[MAT_GEP]], align 4
 ; CHECK-NEXT:    store i32 undef, ptr [[CONST1]], align 4
-; CHECK-NEXT:    [[BASE_BITCAST2:%.*]] = bitcast ptr [[CONST1]] to ptr
-; CHECK-NEXT:    [[MAT_GEP3:%.*]] = getelementptr i8, ptr [[BASE_BITCAST2]], i32 4
-; CHECK-NEXT:    [[MAT_BITCAST4:%.*]] = bitcast ptr [[MAT_GEP3]] to ptr
-; CHECK-NEXT:    store i32 undef, ptr [[MAT_BITCAST4]], align 4
+; CHECK-NEXT:    [[MAT_GEP2:%.*]] = getelementptr i8, ptr [[CONST1]], i32 4
+; CHECK-NEXT:    store i32 undef, ptr [[MAT_GEP2]], align 4
 ; CHECK-NEXT:    ret void
 ;
 bb:


        


More information about the llvm-commits mailing list