diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -942,7 +942,7 @@ if (CI.isNested()) byrefPointer = Builder.CreateLoad(src, "byref.capture"); else - byrefPointer = Builder.CreateBitCast(src.getPointer(), VoidPtrTy); + byrefPointer = src.getPointer(); // Write that void* into the capture field. Builder.CreateStore(byrefPointer, blockField); @@ -1667,7 +1667,6 @@ llvm::Value *BlockVarAddr; if (LoadBlockVarAddr) { BlockVarAddr = CGF.Builder.CreateLoad(Addr); - BlockVarAddr = CGF.Builder.CreateBitCast(BlockVarAddr, CGF.VoidPtrTy); } else { BlockVarAddr = Addr.getPointer(); } @@ -1975,9 +1974,7 @@ } case BlockCaptureEntityKind::BlockObject: { llvm::Value *srcValue = Builder.CreateLoad(srcField, "blockcopy.src"); - srcValue = Builder.CreateBitCast(srcValue, VoidPtrTy); - llvm::Value *dstAddr = - Builder.CreateBitCast(dstField.getPointer(), VoidPtrTy); + llvm::Value *dstAddr = dstField.getPointer(); llvm::Value *args[] = { dstAddr, srcValue, llvm::ConstantInt::get(Int32Ty, flags.getBitMask()) }; @@ -2774,10 +2771,8 @@ void CodeGenFunction::BuildBlockRelease(llvm::Value *V, BlockFieldFlags flags, bool CanThrow) { llvm::FunctionCallee F = CGM.getBlockObjectDispose(); - llvm::Value *args[] = { - Builder.CreateBitCast(V, Int8PtrTy), - llvm::ConstantInt::get(Int32Ty, flags.getBitMask()) - }; + llvm::Value *args[] = {V, + llvm::ConstantInt::get(Int32Ty, flags.getBitMask())}; if (CanThrow) EmitRuntimeCallOrInvoke(F, args); diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -215,16 +215,12 @@ assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType())); llvm::Value *DestPtr = CheckAtomicAlignment(CGF, E); - unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); - llvm::IntegerType *IntType = - llvm::IntegerType::get(CGF.getLLVMContext(), - CGF.getContext().getTypeSize(T)); - llvm::Type *IntPtrType = - llvm::PointerType::get(CGF.getLLVMContext(), AddrSpace); + llvm::IntegerType *IntType = llvm::IntegerType::get( + CGF.getLLVMContext(), CGF.getContext().getTypeSize(T)); llvm::Value *Args[2]; - Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); + Args[0] = DestPtr; Args[1] = CGF.EmitScalarExpr(E->getArg(1)); llvm::Type *ValueType = Args[1]->getType(); Args[1] = EmitToInt(CGF, Args[1], T, IntType); @@ -238,12 +234,8 @@ Value *Val = CGF.EmitScalarExpr(E->getArg(0)); Value *Address = CGF.EmitScalarExpr(E->getArg(1)); - // Convert the type of the pointer to a pointer to the stored type. Val = CGF.EmitToMemory(Val, E->getArg(0)->getType()); - unsigned SrcAddrSpace = Address->getType()->getPointerAddressSpace(); - Value *BC = CGF.Builder.CreateBitCast( - Address, llvm::PointerType::get(Val->getType(), SrcAddrSpace), "cast"); - LValue LV = CGF.MakeNaturalAlignAddrLValue(BC, E->getArg(0)->getType()); + LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getArg(0)->getType()); LV.setNontemporal(true); CGF.EmitStoreOfScalar(Val, LV, false); return nullptr; @@ -800,11 +792,6 @@ } Value *CodeGenFunction::EmitVAStartEnd(Value *ArgValue, bool IsStart) { - llvm::Type *DestType = Int8PtrTy; - if (ArgValue->getType() != DestType) - ArgValue = - Builder.CreateBitCast(ArgValue, DestType, ArgValue->getName().data()); - Intrinsic::ID inst = IsStart ? Intrinsic::vastart : Intrinsic::vaend; return Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue); } @@ -2636,11 +2623,6 @@ case Builtin::BI__builtin_va_copy: { Value *DstPtr = EmitVAListRef(E->getArg(0)).getPointer(); Value *SrcPtr = EmitVAListRef(E->getArg(1)).getPointer(); - - llvm::Type *Type = Int8PtrTy; - - DstPtr = Builder.CreateBitCast(DstPtr, Type); - SrcPtr = Builder.CreateBitCast(SrcPtr, Type); Builder.CreateCall(CGM.getIntrinsic(Intrinsic::vacopy), {DstPtr, SrcPtr}); return RValue::get(nullptr); } @@ -3940,7 +3922,6 @@ } case Builtin::BI__builtin_longjmp: { Value *Buf = EmitScalarExpr(E->getArg(0)); - Buf = Builder.CreateBitCast(Buf, Int8PtrTy); // Call LLVM's EH longjmp, which is lightweight. Builder.CreateCall(CGM.getIntrinsic(Intrinsic::eh_sjlj_longjmp), Buf); @@ -9286,8 +9267,6 @@ SmallVectorImpl &Ops, unsigned IntID) { llvm::ScalableVectorType *VTy = getSVEType(TypeFlags); - auto VecPtrTy = llvm::PointerType::getUnqual(VTy); - auto EltPtrTy = llvm::PointerType::getUnqual(VTy->getElementType()); unsigned N; switch (IntID) { @@ -9306,14 +9285,13 @@ auto RetTy = llvm::VectorType::get(VTy->getElementType(), VTy->getElementCount() * N); - Value *Predicate = EmitSVEPredicateCast(Ops[0], VTy); - Value *BasePtr= Builder.CreateBitCast(Ops[1], VecPtrTy); + Value *Predicate = EmitSVEPredicateCast(Ops[0], VTy); + Value *BasePtr = Ops[1]; // Does the load have an offset? if (Ops.size() > 2) BasePtr = Builder.CreateGEP(VTy, BasePtr, Ops[2]); - BasePtr = Builder.CreateBitCast(BasePtr, EltPtrTy); Function *F = CGM.getIntrinsic(IntID, {VTy}); Value *Call = Builder.CreateCall(F, {Predicate, BasePtr}); unsigned MinElts = VTy->getMinNumElements(); @@ -9330,8 +9308,6 @@ SmallVectorImpl &Ops, unsigned IntID) { llvm::ScalableVectorType *VTy = getSVEType(TypeFlags); - auto VecPtrTy = llvm::PointerType::getUnqual(VTy); - auto EltPtrTy = llvm::PointerType::getUnqual(VTy->getElementType()); unsigned N; switch (IntID) { @@ -9349,13 +9325,12 @@ } Value *Predicate = EmitSVEPredicateCast(Ops[0], VTy); - Value *BasePtr = Builder.CreateBitCast(Ops[1], VecPtrTy); + Value *BasePtr = Ops[1]; // Does the store have an offset? if (Ops.size() > 3) BasePtr = Builder.CreateGEP(VTy, BasePtr, Ops[2]); - BasePtr = Builder.CreateBitCast(BasePtr, EltPtrTy); Value *Val = Ops.back(); // The llvm.aarch64.sve.st2/3/4 intrinsics take legal part vectors, so we @@ -10245,8 +10220,7 @@ : Intrinsic::aarch64_ldxp); Value *LdPtr = EmitScalarExpr(E->getArg(0)); - Value *Val = Builder.CreateCall(F, Builder.CreateBitCast(LdPtr, Int8PtrTy), - "ldxp"); + Value *Val = Builder.CreateCall(F, LdPtr, "ldxp"); Value *Val0 = Builder.CreateExtractValue(Val, 1); Value *Val1 = Builder.CreateExtractValue(Val, 0); @@ -10303,8 +10277,7 @@ Value *Arg0 = Builder.CreateExtractValue(Val, 0); Value *Arg1 = Builder.CreateExtractValue(Val, 1); - Value *StPtr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), - Int8PtrTy); + Value *StPtr = EmitScalarExpr(E->getArg(1)); return Builder.CreateCall(F, {Arg0, Arg1, StPtr}, "stxp"); } @@ -10753,14 +10726,12 @@ } case NEON::BI__builtin_neon_vldrq_p128: { llvm::Type *Int128Ty = llvm::Type::getIntNTy(getLLVMContext(), 128); - llvm::Type *Int128PTy = llvm::PointerType::get(Int128Ty, 0); - Value *Ptr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), Int128PTy); + Value *Ptr = EmitScalarExpr(E->getArg(0)); return Builder.CreateAlignedLoad(Int128Ty, Ptr, CharUnits::fromQuantity(16)); } case NEON::BI__builtin_neon_vstrq_p128: { - llvm::Type *Int128PTy = llvm::PointerType::getUnqual(getLLVMContext()); - Value *Ptr = Builder.CreateBitCast(Ops[0], Int128PTy); + Value *Ptr = Ops[0]; return Builder.CreateDefaultAlignedStore(EmitScalarExpr(E->getArg(1)), Ptr); } case NEON::BI__builtin_neon_vcvts_f32_u32: @@ -12278,19 +12249,15 @@ } case NEON::BI__builtin_neon_vld1_v: case NEON::BI__builtin_neon_vld1q_v: { - Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy)); return Builder.CreateAlignedLoad(VTy, Ops[0], PtrOp0.getAlignment()); } case NEON::BI__builtin_neon_vst1_v: case NEON::BI__builtin_neon_vst1q_v: - Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy)); Ops[1] = Builder.CreateBitCast(Ops[1], VTy); return Builder.CreateAlignedStore(Ops[1], Ops[0], PtrOp0.getAlignment()); case NEON::BI__builtin_neon_vld1_lane_v: case NEON::BI__builtin_neon_vld1q_lane_v: { Ops[1] = Builder.CreateBitCast(Ops[1], Ty); - Ty = llvm::PointerType::getUnqual(VTy->getElementType()); - Ops[0] = Builder.CreateBitCast(Ops[0], Ty); Ops[0] = Builder.CreateAlignedLoad(VTy->getElementType(), Ops[0], PtrOp0.getAlignment()); return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vld1_lane"); @@ -12298,8 +12265,6 @@ case NEON::BI__builtin_neon_vldap1_lane_s64: case NEON::BI__builtin_neon_vldap1q_lane_s64: { Ops[1] = Builder.CreateBitCast(Ops[1], Ty); - Ty = llvm::PointerType::getUnqual(VTy->getElementType()); - Ops[0] = Builder.CreateBitCast(Ops[0], Ty); llvm::LoadInst *LI = Builder.CreateAlignedLoad( VTy->getElementType(), Ops[0], PtrOp0.getAlignment()); LI->setAtomic(llvm::AtomicOrdering::Acquire); @@ -12309,8 +12274,6 @@ case NEON::BI__builtin_neon_vld1_dup_v: case NEON::BI__builtin_neon_vld1q_dup_v: { Value *V = PoisonValue::get(Ty); - Ty = llvm::PointerType::getUnqual(VTy->getElementType()); - Ops[0] = Builder.CreateBitCast(Ops[0], Ty); Ops[0] = Builder.CreateAlignedLoad(VTy->getElementType(), Ops[0], PtrOp0.getAlignment()); llvm::Constant *CI = ConstantInt::get(Int32Ty, 0); @@ -12328,38 +12291,30 @@ case NEON::BI__builtin_neon_vstl1q_lane_s64: { Ops[1] = Builder.CreateBitCast(Ops[1], Ty); Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]); - Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); - llvm::StoreInst *SI = Builder.CreateAlignedStore( - Ops[1], Builder.CreateBitCast(Ops[0], Ty), PtrOp0.getAlignment()); + llvm::StoreInst *SI = + Builder.CreateAlignedStore(Ops[1], Ops[0], PtrOp0.getAlignment()); SI->setAtomic(llvm::AtomicOrdering::Release); return SI; } case NEON::BI__builtin_neon_vld2_v: case NEON::BI__builtin_neon_vld2q_v: { - llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); - Ops[1] = Builder.CreateBitCast(Ops[1], PTy); + llvm::Type *PTy = llvm::PointerType::getUnqual(getLLVMContext()); llvm::Type *Tys[2] = { VTy, PTy }; Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2, Tys); Ops[1] = Builder.CreateCall(F, Ops[1], "vld2"); - Ops[0] = Builder.CreateBitCast(Ops[0], - llvm::PointerType::getUnqual(Ops[1]->getType())); return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); } case NEON::BI__builtin_neon_vld3_v: case NEON::BI__builtin_neon_vld3q_v: { - llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); - Ops[1] = Builder.CreateBitCast(Ops[1], PTy); + llvm::Type *PTy = llvm::PointerType::getUnqual(getLLVMContext()); llvm::Type *Tys[2] = { VTy, PTy }; Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3, Tys); Ops[1] = Builder.CreateCall(F, Ops[1], "vld3"); - Ops[0] = Builder.CreateBitCast(Ops[0], - llvm::PointerType::getUnqual(Ops[1]->getType())); return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); } case NEON::BI__builtin_neon_vld4_v: case NEON::BI__builtin_neon_vld4q_v: { - llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); - Ops[1] = Builder.CreateBitCast(Ops[1], PTy); + llvm::Type *PTy = llvm::PointerType::getUnqual(getLLVMContext()); llvm::Type *Tys[2] = { VTy, PTy }; Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4, Tys); Ops[1] = Builder.CreateCall(F, Ops[1], "vld4"); @@ -12369,38 +12324,26 @@ } case NEON::BI__builtin_neon_vld2_dup_v: case NEON::BI__builtin_neon_vld2q_dup_v: { - llvm::Type *PTy = - llvm::PointerType::getUnqual(VTy->getElementType()); - Ops[1] = Builder.CreateBitCast(Ops[1], PTy); + llvm::Type *PTy = llvm::PointerType::getUnqual(getLLVMContext()); llvm::Type *Tys[2] = { VTy, PTy }; Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2r, Tys); Ops[1] = Builder.CreateCall(F, Ops[1], "vld2"); - Ops[0] = Builder.CreateBitCast(Ops[0], - llvm::PointerType::getUnqual(Ops[1]->getType())); return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); } case NEON::BI__builtin_neon_vld3_dup_v: case NEON::BI__builtin_neon_vld3q_dup_v: { - llvm::Type *PTy = - llvm::PointerType::getUnqual(VTy->getElementType()); - Ops[1] = Builder.CreateBitCast(Ops[1], PTy); + llvm::Type *PTy = llvm::PointerType::getUnqual(getLLVMContext()); llvm::Type *Tys[2] = { VTy, PTy }; Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3r, Tys); Ops[1] = Builder.CreateCall(F, Ops[1], "vld3"); - Ops[0] = Builder.CreateBitCast(Ops[0], - llvm::PointerType::getUnqual(Ops[1]->getType())); return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); } case NEON::BI__builtin_neon_vld4_dup_v: case NEON::BI__builtin_neon_vld4q_dup_v: { - llvm::Type *PTy = - llvm::PointerType::getUnqual(VTy->getElementType()); - Ops[1] = Builder.CreateBitCast(Ops[1], PTy); + llvm::Type *PTy = llvm::PointerType::getUnqual(getLLVMContext()); llvm::Type *Tys[2] = { VTy, PTy }; Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4r, Tys); Ops[1] = Builder.CreateCall(F, Ops[1], "vld4"); - Ops[0] = Builder.CreateBitCast(Ops[0], - llvm::PointerType::getUnqual(Ops[1]->getType())); return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); } case NEON::BI__builtin_neon_vld2_lane_v: @@ -12412,8 +12355,6 @@ Ops[2] = Builder.CreateBitCast(Ops[2], Ty); Ops[3] = Builder.CreateZExt(Ops[3], Int64Ty); Ops[1] = Builder.CreateCall(F, ArrayRef(Ops).slice(1), "vld2_lane"); - Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); - Ops[0] = Builder.CreateBitCast(Ops[0], Ty); return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); } case NEON::BI__builtin_neon_vld3_lane_v: @@ -12426,8 +12367,6 @@ Ops[3] = Builder.CreateBitCast(Ops[3], Ty); Ops[4] = Builder.CreateZExt(Ops[4], Int64Ty); Ops[1] = Builder.CreateCall(F, ArrayRef(Ops).slice(1), "vld3_lane"); - Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); - Ops[0] = Builder.CreateBitCast(Ops[0], Ty); return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); } case NEON::BI__builtin_neon_vld4_lane_v: @@ -12441,8 +12380,6 @@ Ops[4] = Builder.CreateBitCast(Ops[4], Ty); Ops[5] = Builder.CreateZExt(Ops[5], Int64Ty); Ops[1] = Builder.CreateCall(F, ArrayRef(Ops).slice(1), "vld4_lane"); - Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); - Ops[0] = Builder.CreateBitCast(Ops[0], Ty); return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); } case NEON::BI__builtin_neon_vst2_v: @@ -12492,7 +12429,6 @@ } case NEON::BI__builtin_neon_vtrn_v: case NEON::BI__builtin_neon_vtrnq_v: { - Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); Ops[1] = Builder.CreateBitCast(Ops[1], Ty); Ops[2] = Builder.CreateBitCast(Ops[2], Ty); Value *SV = nullptr; @@ -12511,7 +12447,6 @@ } case NEON::BI__builtin_neon_vuzp_v: case NEON::BI__builtin_neon_vuzpq_v: { - Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); Ops[1] = Builder.CreateBitCast(Ops[1], Ty); Ops[2] = Builder.CreateBitCast(Ops[2], Ty); Value *SV = nullptr; @@ -12529,7 +12464,6 @@ } case NEON::BI__builtin_neon_vzip_v: case NEON::BI__builtin_neon_vzipq_v: { - Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); Ops[1] = Builder.CreateBitCast(Ops[1], Ty); Ops[2] = Builder.CreateBitCast(Ops[2], Ty); Value *SV = nullptr; @@ -12748,9 +12682,7 @@ static Value *EmitX86MaskedStore(CodeGenFunction &CGF, ArrayRef Ops, Align Alignment) { - // Cast the pointer to right type. - Value *Ptr = CGF.Builder.CreateBitCast(Ops[0], - llvm::PointerType::getUnqual(Ops[1]->getType())); + Value *Ptr = Ops[0]; Value *MaskVec = getMaskVecValue( CGF, Ops[2], @@ -12761,10 +12693,8 @@ static Value *EmitX86MaskedLoad(CodeGenFunction &CGF, ArrayRef Ops, Align Alignment) { - // Cast the pointer to right type. llvm::Type *Ty = Ops[1]->getType(); - Value *Ptr = - CGF.Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); + Value *Ptr = Ops[0]; Value *MaskVec = getMaskVecValue( CGF, Ops[2], cast(Ty)->getNumElements()); @@ -12775,11 +12705,7 @@ static Value *EmitX86ExpandLoad(CodeGenFunction &CGF, ArrayRef Ops) { auto *ResultTy = cast(Ops[1]->getType()); - llvm::Type *PtrTy = ResultTy->getElementType(); - - // Cast the pointer to element type. - Value *Ptr = CGF.Builder.CreateBitCast(Ops[0], - llvm::PointerType::getUnqual(PtrTy)); + Value *Ptr = Ops[0]; Value *MaskVec = getMaskVecValue( CGF, Ops[2], cast(ResultTy)->getNumElements()); @@ -12805,11 +12731,7 @@ static Value *EmitX86CompressStore(CodeGenFunction &CGF, ArrayRef Ops) { auto *ResultTy = cast(Ops[1]->getType()); - llvm::Type *PtrTy = ResultTy->getElementType(); - - // Cast the pointer to element type. - Value *Ptr = CGF.Builder.CreateBitCast(Ops[0], - llvm::PointerType::getUnqual(PtrTy)); + Value *Ptr = Ops[0]; Value *MaskVec = getMaskVecValue(CGF, Ops[2], ResultTy->getNumElements()); @@ -13620,13 +13542,13 @@ Address Tmp = CreateMemTemp(E->getArg(0)->getType()); Builder.CreateStore(Ops[0], Tmp); return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr), - Builder.CreateBitCast(Tmp.getPointer(), Int8PtrTy)); + Tmp.getPointer()); } case X86::BI_mm_getcsr: case X86::BI__builtin_ia32_stmxcsr: { Address Tmp = CreateMemTemp(E->getType()); Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr), - Builder.CreateBitCast(Tmp.getPointer(), Int8PtrTy)); + Tmp.getPointer()); return Builder.CreateLoad(Tmp, "stmxcsr"); } case X86::BI__builtin_ia32_xsave: @@ -15976,11 +15898,8 @@ SmallVector Ops; Ops.push_back(EmitScalarExpr(E->getArg(0))); Ops.push_back(EmitScalarExpr(E->getArg(1))); - if(BuiltinID == PPC::BI__builtin_vsx_lxvl || - BuiltinID == PPC::BI__builtin_vsx_lxvll){ - Ops[0] = Builder.CreateBitCast(Ops[0], Int8PtrTy); - }else { - Ops[1] = Builder.CreateBitCast(Ops[1], Int8PtrTy); + if (!(BuiltinID == PPC::BI__builtin_vsx_lxvl || + BuiltinID == PPC::BI__builtin_vsx_lxvll)) { Ops[0] = Builder.CreateGEP(Int8Ty, Ops[1], Ops[0]); Ops.pop_back(); } @@ -16048,11 +15967,8 @@ Ops.push_back(EmitScalarExpr(E->getArg(0))); Ops.push_back(EmitScalarExpr(E->getArg(1))); Ops.push_back(EmitScalarExpr(E->getArg(2))); - if(BuiltinID == PPC::BI__builtin_vsx_stxvl || - BuiltinID == PPC::BI__builtin_vsx_stxvll ){ - Ops[1] = Builder.CreateBitCast(Ops[1], Int8PtrTy); - }else { - Ops[2] = Builder.CreateBitCast(Ops[2], Int8PtrTy); + if (!(BuiltinID == PPC::BI__builtin_vsx_stxvl || + BuiltinID == PPC::BI__builtin_vsx_stxvll)) { Ops[1] = Builder.CreateGEP(Int8Ty, Ops[2], Ops[1]); Ops.pop_back(); } @@ -16588,7 +16504,7 @@ } case PPC::BI__builtin_ppc_load2r: { Function *F = CGM.getIntrinsic(Intrinsic::ppc_load2r); - Value *Op0 = Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), Int8PtrTy); + Value *Op0 = EmitScalarExpr(E->getArg(0)); Value *LoadIntrinsic = Builder.CreateCall(F, {Op0}); return Builder.CreateTrunc(LoadIntrinsic, Int16Ty); } @@ -16813,7 +16729,7 @@ case PPC::BI__builtin_ppc_sthcx: { llvm::Function *F = CGM.getIntrinsic(Intrinsic::ppc_sthcx); - Value *Op0 = Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), Int8PtrTy); + Value *Op0 = EmitScalarExpr(E->getArg(0)); Value *Op1 = Builder.CreateSExt(EmitScalarExpr(E->getArg(1)), Int32Ty); return Builder.CreateCall(F, {Op0, Op1}); } @@ -16887,10 +16803,8 @@ BuiltinID == PPC::BI__builtin_mma_stxvp) { if (BuiltinID == PPC::BI__builtin_vsx_lxvp || BuiltinID == PPC::BI__builtin_mma_lxvp) { - Ops[1] = Builder.CreateBitCast(Ops[1], Int8PtrTy); Ops[0] = Builder.CreateGEP(Int8Ty, Ops[1], Ops[0]); } else { - Ops[2] = Builder.CreateBitCast(Ops[2], Int8PtrTy); Ops[1] = Builder.CreateGEP(Int8Ty, Ops[2], Ops[1]); } Ops.pop_back(); @@ -20022,8 +19936,7 @@ auto MakeCircOp = [this, E](unsigned IntID, bool IsLoad) { // The base pointer is passed by address, so it needs to be loaded. Address A = EmitPointerWithAlignment(E->getArg(0)); - Address BP = Address(Builder.CreateBitCast( - A.getPointer(), Int8PtrPtrTy), Int8PtrTy, A.getAlignment()); + Address BP = Address(A.getPointer(), Int8PtrTy, A.getAlignment()); llvm::Value *Base = Builder.CreateLoad(BP); // The treatment of both loads and stores is the same: the arguments for // the builtin are the same as the arguments for the intrinsic. @@ -20058,15 +19971,13 @@ // The intrinsic generates one result, which is the new value for the base // pointer. It needs to be returned. The result of the load instruction is // passed to intrinsic by address, so the value needs to be stored. - llvm::Value *BaseAddress = - Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), Int8PtrTy); + llvm::Value *BaseAddress = EmitScalarExpr(E->getArg(0)); // Expressions like &(*pt++) will be incremented per evaluation. // EmitPointerWithAlignment and EmitScalarExpr evaluates the expression // per call. Address DestAddr = EmitPointerWithAlignment(E->getArg(1)); - DestAddr = Address(Builder.CreateBitCast(DestAddr.getPointer(), Int8PtrTy), - Int8Ty, DestAddr.getAlignment()); + DestAddr = Address(DestAddr.getPointer(), Int8Ty, DestAddr.getAlignment()); llvm::Value *DestAddress = DestAddr.getPointer(); // Operands are Base, Dest, Modifier. diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -403,11 +403,8 @@ assert(PathBegin != PathEnd && "Base path should not be empty!"); QualType DerivedTy = - getContext().getCanonicalType(getContext().getTagDeclType(Derived)); - unsigned AddrSpace = BaseAddr.getAddressSpace(); + getContext().getCanonicalType(getContext().getTagDeclType(Derived)); llvm::Type *DerivedValueTy = ConvertType(DerivedTy); - llvm::Type *DerivedPtrTy = - llvm::PointerType::get(getLLVMContext(), AddrSpace); llvm::Value *NonVirtualOffset = CGM.GetNonVirtualBaseClassOffset(Derived, PathBegin, PathEnd); @@ -432,13 +429,10 @@ } // Apply the offset. - llvm::Value *Value = Builder.CreateBitCast(BaseAddr.getPointer(), Int8PtrTy); + llvm::Value *Value = BaseAddr.getPointer(); Value = Builder.CreateInBoundsGEP( Int8Ty, Value, Builder.CreateNeg(NonVirtualOffset), "sub.ptr"); - // Just cast. - Value = Builder.CreateBitCast(Value, DerivedPtrTy); - // Produce a PHI if we had a null-check. if (NullCheckValue) { Builder.CreateBr(CastEnd); @@ -1676,8 +1670,7 @@ CodeGenFunction::SanitizerScope SanScope(&CGF); // Pass in void pointer and size of region as arguments to runtime // function - SmallVector Args = { - CGF.Builder.CreateBitCast(Ptr, CGF.VoidPtrTy)}; + SmallVector Args = {Ptr}; SmallVector ArgTypes = {CGF.VoidPtrTy}; if (PoisonSize.has_value()) { @@ -1756,10 +1749,8 @@ llvm::ConstantInt *OffsetSizePtr = llvm::ConstantInt::get(CGF.SizeTy, PoisonStart.getQuantity()); - llvm::Value *OffsetPtr = CGF.Builder.CreateGEP( - CGF.Int8Ty, - CGF.Builder.CreateBitCast(CGF.LoadCXXThis(), CGF.Int8PtrTy), - OffsetSizePtr); + llvm::Value *OffsetPtr = + CGF.Builder.CreateGEP(CGF.Int8Ty, CGF.LoadCXXThis(), OffsetSizePtr); CharUnits PoisonEnd; if (EndIndex >= Layout.getFieldCount()) { @@ -2736,7 +2727,6 @@ llvm::Value *TypeId = llvm::MetadataAsValue::get(CGM.getLLVMContext(), MD); - llvm::Value *CastedVTable = Builder.CreateBitCast(VTable, Int8PtrTy); // If we already know that the call has hidden LTO visibility, emit // @llvm.type.test(). Otherwise emit @llvm.public.type.test(), which WPD // will convert to @llvm.type.test() if we assert at link time that we have @@ -2745,7 +2735,7 @@ ? llvm::Intrinsic::type_test : llvm::Intrinsic::public_type_test; llvm::Value *TypeTest = - Builder.CreateCall(CGM.getIntrinsic(IID), {CastedVTable, TypeId}); + Builder.CreateCall(CGM.getIntrinsic(IID), {VTable, TypeId}); Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::assume), TypeTest); } } @@ -2849,9 +2839,8 @@ CGM.CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0)); llvm::Value *TypeId = llvm::MetadataAsValue::get(getLLVMContext(), MD); - llvm::Value *CastedVTable = Builder.CreateBitCast(VTable, Int8PtrTy); llvm::Value *TypeTest = Builder.CreateCall( - CGM.getIntrinsic(llvm::Intrinsic::type_test), {CastedVTable, TypeId}); + CGM.getIntrinsic(llvm::Intrinsic::type_test), {VTable, TypeId}); llvm::Constant *StaticData[] = { llvm::ConstantInt::get(Int8Ty, TCK), @@ -2861,7 +2850,7 @@ auto CrossDsoTypeId = CGM.CreateCrossDsoCfiTypeId(MD); if (CGM.getCodeGenOpts().SanitizeCfiCrossDso && CrossDsoTypeId) { - EmitCfiSlowPathCheck(M, TypeTest, CrossDsoTypeId, CastedVTable, StaticData); + EmitCfiSlowPathCheck(M, TypeTest, CrossDsoTypeId, VTable, StaticData); return; } @@ -2874,9 +2863,9 @@ CGM.getLLVMContext(), llvm::MDString::get(CGM.getLLVMContext(), "all-vtables")); llvm::Value *ValidVtable = Builder.CreateCall( - CGM.getIntrinsic(llvm::Intrinsic::type_test), {CastedVTable, AllVtables}); + CGM.getIntrinsic(llvm::Intrinsic::type_test), {VTable, AllVtables}); EmitCheck(std::make_pair(TypeTest, M), SanitizerHandler::CFICheckFail, - StaticData, {CastedVTable, ValidVtable}); + StaticData, {VTable, ValidVtable}); } bool CodeGenFunction::ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD) { @@ -2907,11 +2896,9 @@ CGM.CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0)); llvm::Value *TypeId = llvm::MetadataAsValue::get(CGM.getLLVMContext(), MD); - llvm::Value *CastedVTable = Builder.CreateBitCast(VTable, Int8PtrTy); llvm::Value *CheckedLoad = Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::type_checked_load), - {CastedVTable, llvm::ConstantInt::get(Int32Ty, VTableByteOffset), - TypeId}); + {VTable, llvm::ConstantInt::get(Int32Ty, VTableByteOffset), TypeId}); llvm::Value *CheckResult = Builder.CreateExtractValue(CheckedLoad, 1); std::string TypeName = RD->getQualifiedNameAsString(); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -140,9 +140,8 @@ auto *VectorTy = llvm::FixedVectorType::get(ArrayTy->getElementType(), ArrayTy->getNumElements()); - Result = Address( - Builder.CreateBitCast(Result.getPointer(), VectorTy->getPointerTo()), - VectorTy, Result.getAlignment(), KnownNonNull); + Result = Address(Result.getPointer(), VectorTy, Result.getAlignment(), + KnownNonNull); } return Result; } @@ -746,9 +745,8 @@ llvm::Value *Min = Builder.getFalse(); llvm::Value *NullIsUnknown = Builder.getFalse(); llvm::Value *Dynamic = Builder.getFalse(); - llvm::Value *CastAddr = Builder.CreateBitCast(Ptr, Int8PtrTy); llvm::Value *LargeEnough = Builder.CreateICmpUGE( - Builder.CreateCall(F, {CastAddr, Min, NullIsUnknown, Dynamic}), Size); + Builder.CreateCall(F, {Ptr, Min, NullIsUnknown, Dynamic}), Size); Checks.push_back(std::make_pair(LargeEnough, SanitizerKind::ObjectSize)); } } @@ -825,9 +823,7 @@ // Load the vptr, and compute hash_16_bytes(TypeHash, vptr). llvm::Value *Low = llvm::ConstantInt::get(Int64Ty, TypeHash); - llvm::Type *VPtrTy = llvm::PointerType::get(IntPtrTy, 0); - Address VPtrAddr(Builder.CreateBitCast(Ptr, VPtrTy), IntPtrTy, - getPointerAlign()); + Address VPtrAddr(Ptr, IntPtrTy, getPointerAlign()); llvm::Value *VPtrVal = Builder.CreateLoad(VPtrAddr); llvm::Value *High = Builder.CreateZExt(VPtrVal, Int64Ty); @@ -2492,14 +2488,6 @@ } } -static llvm::Value * -EmitBitCastOfLValueToProperType(CodeGenFunction &CGF, - llvm::Value *V, llvm::Type *IRType, - StringRef Name = StringRef()) { - unsigned AS = cast(V->getType())->getAddressSpace(); - return CGF.Builder.CreateBitCast(V, IRType->getPointerTo(AS), Name); -} - static LValue EmitThreadPrivateVarDeclLValue( CodeGenFunction &CGF, const VarDecl *VD, QualType T, Address Addr, llvm::Type *RealVarTy, SourceLocation Loc) { @@ -2600,7 +2588,6 @@ V = CGF.Builder.CreateThreadLocalAddress(V); llvm::Type *RealVarTy = CGF.getTypes().ConvertTypeForMem(VD->getType()); - V = EmitBitCastOfLValueToProperType(CGF, V, RealVarTy); CharUnits Alignment = CGF.getContext().getDeclAlign(VD); Address Addr(V, RealVarTy, Alignment); // Emit reference to the private copy of the variable if it is an OpenMP @@ -3421,8 +3408,7 @@ "__cfi_slowpath_diag", llvm::FunctionType::get(VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false)); - CheckCall = Builder.CreateCall( - SlowPathFn, {TypeId, Ptr, Builder.CreateBitCast(InfoPtr, Int8PtrTy)}); + CheckCall = Builder.CreateCall(SlowPathFn, {TypeId, Ptr, InfoPtr}); } else { SlowPathFn = CGM.getModule().getOrInsertFunction( "__cfi_slowpath", @@ -5365,8 +5351,7 @@ AlignedCalleePtr = CalleePtr; } - llvm::Value *CalleePrefixStruct = Builder.CreateBitCast( - AlignedCalleePtr, llvm::PointerType::getUnqual(PrefixStructTy)); + llvm::Value *CalleePrefixStruct = AlignedCalleePtr; llvm::Value *CalleeSigPtr = Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, -1, 0); llvm::Value *CalleeSig = @@ -5413,9 +5398,8 @@ llvm::Value *TypeId = llvm::MetadataAsValue::get(getLLVMContext(), MD); llvm::Value *CalleePtr = Callee.getFunctionPointer(); - llvm::Value *CastedCallee = Builder.CreateBitCast(CalleePtr, Int8PtrTy); llvm::Value *TypeTest = Builder.CreateCall( - CGM.getIntrinsic(llvm::Intrinsic::type_test), {CastedCallee, TypeId}); + CGM.getIntrinsic(llvm::Intrinsic::type_test), {CalleePtr, TypeId}); auto CrossDsoTypeId = CGM.CreateCrossDsoCfiTypeId(MD); llvm::Constant *StaticData[] = { @@ -5425,18 +5409,17 @@ }; if (CGM.getCodeGenOpts().SanitizeCfiCrossDso && CrossDsoTypeId) { EmitCfiSlowPathCheck(SanitizerKind::CFIICall, TypeTest, CrossDsoTypeId, - CastedCallee, StaticData); + CalleePtr, StaticData); } else { EmitCheck(std::make_pair(TypeTest, SanitizerKind::CFIICall), SanitizerHandler::CFICheckFail, StaticData, - {CastedCallee, llvm::UndefValue::get(IntPtrTy)}); + {CalleePtr, llvm::UndefValue::get(IntPtrTy)}); } } CallArgList Args; if (Chain) - Args.add(RValue::get(Builder.CreateBitCast(Chain, CGM.VoidPtrTy)), - CGM.getContext().VoidPtrTy); + Args.add(RValue::get(Chain), CGM.getContext().VoidPtrTy); // C++17 requires that we evaluate arguments to a call using assignment syntax // right-to-left, and that we evaluate arguments to certain other operators @@ -5507,10 +5490,8 @@ isa(E) && (!TargetDecl || !isa(TargetDecl))) { llvm::Value *Handle = Callee.getFunctionPointer(); - auto *Cast = - Builder.CreateBitCast(Handle, Handle->getType()->getPointerTo()); auto *Stub = Builder.CreateLoad( - Address(Cast, Handle->getType(), CGM.getPointerAlign())); + Address(Handle, Handle->getType(), CGM.getPointerAlign())); Callee.setFunctionPointer(Stub); } llvm::CallBase *CallOrInvoke = nullptr; diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -3690,8 +3690,8 @@ index = CGF.Builder.CreateMul(index, objectSize); - Value *result = CGF.Builder.CreateBitCast(pointer, CGF.VoidPtrTy); - result = CGF.Builder.CreateGEP(CGF.Int8Ty, result, index, "add.ptr"); + Value *result = + CGF.Builder.CreateGEP(CGF.Int8Ty, pointer, index, "add.ptr"); return CGF.Builder.CreateBitCast(result, pointer->getType()); } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -2049,8 +2049,7 @@ NullConstant, Twine()); CharUnits NullAlign = DestPtr.getAlignment(); NullVariable->setAlignment(NullAlign.getAsAlign()); - Address SrcPtr(Builder.CreateBitCast(NullVariable, Builder.getInt8PtrTy()), - Builder.getInt8Ty(), NullAlign); + Address SrcPtr(NullVariable, Builder.getInt8Ty(), NullAlign); if (vla) return emitNonZeroVLAInit(*this, Ty, DestPtr, SrcPtr, SizeVal);