From bf1a99861c2e98cfd85792fdefe2ef9c7ec11f52 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 17 Mar 2022 14:54:18 +0100 Subject: [PATCH] [CodeGen] Avoid some pointer element type accesses --- clang/lib/CodeGen/CGDecl.cpp | 11 +++++------ clang/lib/CodeGen/CGExpr.cpp | 3 +-- clang/lib/CodeGen/CGExprScalar.cpp | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index a324117..e54101f 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -2277,6 +2277,8 @@ static void emitPartialArrayDestroy(CodeGenFunction &CGF, llvm::Value *begin, llvm::Value *end, QualType type, CharUnits elementAlign, CodeGenFunction::Destroyer *destroyer) { + llvm::Type *elemTy = CGF.ConvertTypeForMem(type); + // If the element type is itself an array, drill down. unsigned arrayDepth = 0; while (const ArrayType *arrayType = CGF.getContext().getAsArrayType(type)) { @@ -2290,7 +2292,6 @@ static void emitPartialArrayDestroy(CodeGenFunction &CGF, llvm::Value *zero = llvm::ConstantInt::get(CGF.SizeTy, 0); SmallVector gepIndices(arrayDepth+1, zero); - llvm::Type *elemTy = begin->getType()->getPointerElementType(); begin = CGF.Builder.CreateInBoundsGEP( elemTy, begin, gepIndices, "pad.arraybegin"); end = CGF.Builder.CreateInBoundsGEP( @@ -2473,11 +2474,9 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg, assert(getContext().getTargetAddressSpace(SrcLangAS) == CGM.getDataLayout().getAllocaAddrSpace()); auto DestAS = getContext().getTargetAddressSpace(DestLangAS); - auto *T = V->getType()->getPointerElementType()->getPointerTo(DestAS); - DeclPtr = - Address::deprecated(getTargetHooks().performAddrSpaceCast( - *this, V, SrcLangAS, DestLangAS, T, true), - DeclPtr.getAlignment()); + auto *T = DeclPtr.getElementType()->getPointerTo(DestAS); + DeclPtr = DeclPtr.withPointer(getTargetHooks().performAddrSpaceCast( + *this, V, SrcLangAS, DestLangAS, T, true)); } // Push a destructor cleanup for this parameter if the ABI requires it. diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 6cd3cab..b0eeddd 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -1852,8 +1852,7 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr, if (const auto *ClangVecTy = Ty->getAs()) { auto *VecTy = dyn_cast(SrcTy); if (VecTy && ClangVecTy->isExtVectorBoolType()) { - auto *MemIntTy = - cast(Addr.getType()->getPointerElementType()); + auto *MemIntTy = cast(Addr.getElementType()); // Expand to the memory bit width. unsigned MemNumElems = MemIntTy->getPrimitiveSizeInBits(); // -->

. diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 18f0dac..18a22b5 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -2641,7 +2641,7 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, = CGF.getContext().getAsVariableArrayType(type)) { llvm::Value *numElts = CGF.getVLASize(vla).NumElts; if (!isInc) numElts = Builder.CreateNSWNeg(numElts, "vla.negsize"); - llvm::Type *elemTy = value->getType()->getPointerElementType(); + llvm::Type *elemTy = CGF.ConvertTypeForMem(vla->getElementType()); if (CGF.getLangOpts().isSignedOverflowDefined()) value = Builder.CreateGEP(elemTy, value, numElts, "vla.inc"); else @@ -3519,7 +3519,7 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF, // GEP indexes are signed, and scaling an index isn't permitted to // signed-overflow, so we use the same semantics for our explicit // multiply. We suppress this if overflow is not undefined behavior. - llvm::Type *elemTy = pointer->getType()->getPointerElementType(); + llvm::Type *elemTy = CGF.ConvertTypeForMem(vla->getElementType()); if (CGF.getLangOpts().isSignedOverflowDefined()) { index = CGF.Builder.CreateMul(index, numElements, "vla.index"); pointer = CGF.Builder.CreateGEP(elemTy, pointer, index, "add.ptr"); -- 2.7.4