diff --git a/llvm/lib/CodeGen/ExpandMemCmp.cpp b/llvm/lib/CodeGen/ExpandMemCmp.cpp --- a/llvm/lib/CodeGen/ExpandMemCmp.cpp +++ b/llvm/lib/CodeGen/ExpandMemCmp.cpp @@ -288,17 +288,11 @@ Align RhsAlign = RhsSource->getPointerAlignment(DL); if (OffsetBytes > 0) { auto *ByteType = Type::getInt8Ty(CI->getContext()); - LhsSource = Builder.CreateConstGEP1_64( - ByteType, Builder.CreateBitCast(LhsSource, ByteType->getPointerTo()), - OffsetBytes); - RhsSource = Builder.CreateConstGEP1_64( - ByteType, Builder.CreateBitCast(RhsSource, ByteType->getPointerTo()), - OffsetBytes); + LhsSource = Builder.CreateConstGEP1_64(ByteType, LhsSource, OffsetBytes); + RhsSource = Builder.CreateConstGEP1_64(ByteType, RhsSource, OffsetBytes); LhsAlign = commonAlignment(LhsAlign, OffsetBytes); RhsAlign = commonAlignment(RhsAlign, OffsetBytes); } - LhsSource = Builder.CreateBitCast(LhsSource, LoadSizeType->getPointerTo()); - RhsSource = Builder.CreateBitCast(RhsSource, LoadSizeType->getPointerTo()); // Create a constant or a load from the source. Value *Lhs = nullptr; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -2029,8 +2029,8 @@ // registers the usual way. SmallVector PtrValueVTs; ComputeValueVTs(TLI, DL, - F->getReturnType()->getPointerTo( - DAG.getDataLayout().getAllocaAddrSpace()), + PointerType::get(F->getContext(), + DAG.getDataLayout().getAllocaAddrSpace()), PtrValueVTs); SDValue RetPtr = @@ -10362,7 +10362,8 @@ // The instruction result is the result of loading from the // hidden sret parameter. SmallVector PVTs; - Type *PtrRetTy = OrigRetTy->getPointerTo(DL.getAllocaAddrSpace()); + Type *PtrRetTy = + PointerType::get(OrigRetTy->getContext(), DL.getAllocaAddrSpace()); ComputeValueVTs(*this, DL, PtrRetTy, PVTs); assert(PVTs.size() == 1 && "Pointers should fit in one register"); @@ -10690,8 +10691,8 @@ // Put in an sret pointer parameter before all the other parameters. SmallVector ValueVTs; ComputeValueVTs(*TLI, DAG.getDataLayout(), - F.getReturnType()->getPointerTo( - DAG.getDataLayout().getAllocaAddrSpace()), + PointerType::get(F.getContext(), + DAG.getDataLayout().getAllocaAddrSpace()), ValueVTs); // NOTE: Assuming that a pointer will never break down to more than one VT @@ -10884,8 +10885,8 @@ // from the sret argument into it. SmallVector ValueVTs; ComputeValueVTs(*TLI, DAG.getDataLayout(), - F.getReturnType()->getPointerTo( - DAG.getDataLayout().getAllocaAddrSpace()), + PointerType::get(F.getContext(), + DAG.getDataLayout().getAllocaAddrSpace()), ValueVTs); MVT VT = ValueVTs[0].getSimpleVT(); MVT RegVT = TLI->getRegisterType(*CurDAG->getContext(), VT); diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp --- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp +++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp @@ -803,8 +803,7 @@ Builder.getInt32(Offset1.getZExtValue())); } // Generate wider load. - Value *NewPtr = Builder.CreateBitCast(Load1Ptr, WiderType->getPointerTo(AS)); - NewLoad = Builder.CreateAlignedLoad(WiderType, NewPtr, LI1->getAlign(), + NewLoad = Builder.CreateAlignedLoad(WiderType, Load1Ptr, LI1->getAlign(), LI1->isVolatile(), ""); NewLoad->takeName(LI1); // Set the New Load AATags Metadata. diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -3715,9 +3715,10 @@ } // Now insert something that simplifycfg will turn into an unreachable. Type *Int8Ty = Type::getInt8Ty(BB->getContext()); - new StoreInst(PoisonValue::get(Int8Ty), - Constant::getNullValue(Int8Ty->getPointerTo()), - BB->getTerminator()); + new StoreInst( + PoisonValue::get(Int8Ty), + Constant::getNullValue(PointerType::getUnqual(BB->getContext())), + BB->getTerminator()); } void NewGVN::markInstructionForDeletion(Instruction *I) { diff --git a/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp b/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp --- a/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp +++ b/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp @@ -170,10 +170,6 @@ // Adjust alignment for the scalar instruction. const Align AdjustedAlignVal = commonAlignment(AlignVal, EltTy->getPrimitiveSizeInBits() / 8); - // Bitcast %addr from i8* to EltTy* - Type *NewPtrType = - EltTy->getPointerTo(Ptr->getType()->getPointerAddressSpace()); - Value *FirstEltPtr = Builder.CreateBitCast(Ptr, NewPtrType); unsigned VectorWidth = cast(VecType)->getNumElements(); // The result vector @@ -183,7 +179,7 @@ for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) { if (cast(Mask)->getAggregateElement(Idx)->isNullValue()) continue; - Value *Gep = Builder.CreateConstInBoundsGEP1_32(EltTy, FirstEltPtr, Idx); + Value *Gep = Builder.CreateConstInBoundsGEP1_32(EltTy, Ptr, Idx); LoadInst *Load = Builder.CreateAlignedLoad(EltTy, Gep, AdjustedAlignVal); VResult = Builder.CreateInsertElement(VResult, Load, Idx); } @@ -232,7 +228,7 @@ CondBlock->setName("cond.load"); Builder.SetInsertPoint(CondBlock->getTerminator()); - Value *Gep = Builder.CreateConstInBoundsGEP1_32(EltTy, FirstEltPtr, Idx); + Value *Gep = Builder.CreateConstInBoundsGEP1_32(EltTy, Ptr, Idx); LoadInst *Load = Builder.CreateAlignedLoad(EltTy, Gep, AdjustedAlignVal); Value *NewVResult = Builder.CreateInsertElement(VResult, Load, Idx); @@ -309,10 +305,6 @@ // Adjust alignment for the scalar instruction. const Align AdjustedAlignVal = commonAlignment(AlignVal, EltTy->getPrimitiveSizeInBits() / 8); - // Bitcast %addr from i8* to EltTy* - Type *NewPtrType = - EltTy->getPointerTo(Ptr->getType()->getPointerAddressSpace()); - Value *FirstEltPtr = Builder.CreateBitCast(Ptr, NewPtrType); unsigned VectorWidth = cast(VecType)->getNumElements(); if (isConstantIntVector(Mask)) { @@ -320,7 +312,7 @@ if (cast(Mask)->getAggregateElement(Idx)->isNullValue()) continue; Value *OneElt = Builder.CreateExtractElement(Src, Idx); - Value *Gep = Builder.CreateConstInBoundsGEP1_32(EltTy, FirstEltPtr, Idx); + Value *Gep = Builder.CreateConstInBoundsGEP1_32(EltTy, Ptr, Idx); Builder.CreateAlignedStore(OneElt, Gep, AdjustedAlignVal); } CI->eraseFromParent(); @@ -367,7 +359,7 @@ Builder.SetInsertPoint(CondBlock->getTerminator()); Value *OneElt = Builder.CreateExtractElement(Src, Idx); - Value *Gep = Builder.CreateConstInBoundsGEP1_32(EltTy, FirstEltPtr, Idx); + Value *Gep = Builder.CreateConstInBoundsGEP1_32(EltTy, Ptr, Idx); Builder.CreateAlignedStore(OneElt, Gep, AdjustedAlignVal); // Create "else" block, fill it in the next iteration diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1550,30 +1550,21 @@ // First, see if we can fold either argument to a constant. Value *LHSV = nullptr; - if (auto *LHSC = dyn_cast(LHS)) { - LHSC = ConstantExpr::getBitCast(LHSC, IntType->getPointerTo()); + if (auto *LHSC = dyn_cast(LHS)) LHSV = ConstantFoldLoadFromConstPtr(LHSC, IntType, DL); - } + Value *RHSV = nullptr; - if (auto *RHSC = dyn_cast(RHS)) { - RHSC = ConstantExpr::getBitCast(RHSC, IntType->getPointerTo()); + if (auto *RHSC = dyn_cast(RHS)) RHSV = ConstantFoldLoadFromConstPtr(RHSC, IntType, DL); - } // Don't generate unaligned loads. If either source is constant data, // alignment doesn't matter for that source because there is no load. if ((LHSV || getKnownAlignment(LHS, DL, CI) >= PrefAlignment) && (RHSV || getKnownAlignment(RHS, DL, CI) >= PrefAlignment)) { - if (!LHSV) { - Type *LHSPtrTy = - IntType->getPointerTo(LHS->getType()->getPointerAddressSpace()); - LHSV = B.CreateLoad(IntType, B.CreateBitCast(LHS, LHSPtrTy), "lhsv"); - } - if (!RHSV) { - Type *RHSPtrTy = - IntType->getPointerTo(RHS->getType()->getPointerAddressSpace()); - RHSV = B.CreateLoad(IntType, B.CreateBitCast(RHS, RHSPtrTy), "rhsv"); - } + if (!LHSV) + LHSV = B.CreateLoad(IntType, LHS, "lhsv"); + if (!RHSV) + RHSV = B.CreateLoad(IntType, RHS, "rhsv"); return B.CreateZExt(B.CreateICmpNE(LHSV, RHSV), CI->getType(), "memcmp"); } }