Skip to content

Commit

Permalink
[CodeGen] Avoid some pointer element type accesses
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Mar 17, 2022
1 parent 7ed1abd commit 6c0af92
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
3 changes: 1 addition & 2 deletions clang/lib/CodeGen/CGCall.cpp
Expand Up @@ -3513,8 +3513,7 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
--EI;
llvm::Value *ArgStruct = &*EI;
llvm::Value *SRet = Builder.CreateStructGEP(
EI->getType()->getPointerElementType(), ArgStruct,
RetAI.getInAllocaFieldIndex());
FI.getArgStruct(), ArgStruct, RetAI.getInAllocaFieldIndex());
llvm::Type *Ty =
cast<llvm::GetElementPtrInst>(SRet)->getResultElementType();
RV = Builder.CreateAlignedLoad(Ty, SRet, getPointerAlign(), "sret");
Expand Down
13 changes: 6 additions & 7 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp
Expand Up @@ -9990,6 +9990,7 @@ void CGOpenMPRuntime::emitUserDefinedMapper(const OMPDeclareMapperDecl *D,
cast<VarDecl>(cast<DeclRefExpr>(D->getMapperVarRef())->getDecl());
SourceLocation Loc = D->getLocation();
CharUnits ElementSize = C.getTypeSizeInChars(Ty);
llvm::Type *ElemTy = CGM.getTypes().ConvertTypeForMem(Ty);

// Prepare mapper function arguments and attributes.
ImplicitParamDecl HandleArg(C, /*DC=*/nullptr, Loc, /*Id=*/nullptr,
Expand Down Expand Up @@ -10044,8 +10045,7 @@ void CGOpenMPRuntime::emitUserDefinedMapper(const OMPDeclareMapperDecl *D,
Size, MapperCGF.Builder.getInt64(ElementSize.getQuantity()));
llvm::Value *PtrBegin = MapperCGF.Builder.CreateBitCast(
BeginIn, CGM.getTypes().ConvertTypeForMem(PtrTy));
llvm::Value *PtrEnd = MapperCGF.Builder.CreateGEP(
PtrBegin->getType()->getPointerElementType(), PtrBegin, Size);
llvm::Value *PtrEnd = MapperCGF.Builder.CreateGEP(ElemTy, PtrBegin, Size);
llvm::Value *MapType = MapperCGF.EmitLoadOfScalar(
MapperCGF.GetAddrOfLocalVar(&TypeArg), /*Volatile=*/false,
C.getPointerType(Int64Ty), Loc);
Expand Down Expand Up @@ -10077,10 +10077,10 @@ void CGOpenMPRuntime::emitUserDefinedMapper(const OMPDeclareMapperDecl *D,
llvm::PHINode *PtrPHI = MapperCGF.Builder.CreatePHI(
PtrBegin->getType(), 2, "omp.arraymap.ptrcurrent");
PtrPHI->addIncoming(PtrBegin, EntryBB);
Address PtrCurrent =
Address::deprecated(PtrPHI, MapperCGF.GetAddrOfLocalVar(&BeginArg)
.getAlignment()
.alignmentOfArrayElement(ElementSize));
Address PtrCurrent(PtrPHI, ElemTy,
MapperCGF.GetAddrOfLocalVar(&BeginArg)
.getAlignment()
.alignmentOfArrayElement(ElementSize));
// Privatize the declared variable of mapper to be the current array element.
CodeGenFunction::OMPPrivateScope Scope(MapperCGF);
Scope.addPrivate(MapperVarDecl, PtrCurrent);
Expand Down Expand Up @@ -10202,7 +10202,6 @@ void CGOpenMPRuntime::emitUserDefinedMapper(const OMPDeclareMapperDecl *D,

// Update the pointer to point to the next element that needs to be mapped,
// and check whether we have mapped all elements.
llvm::Type *ElemTy = PtrPHI->getType()->getPointerElementType();
llvm::Value *PtrNext = MapperCGF.Builder.CreateConstGEP1_32(
ElemTy, PtrPHI, /*Idx0=*/1, "omp.arraymap.next");
PtrPHI->addIncoming(PtrNext, LastBB);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenFunction.cpp
Expand Up @@ -1104,7 +1104,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
llvm::Function::arg_iterator EI = CurFn->arg_end();
--EI;
llvm::Value *Addr = Builder.CreateStructGEP(
EI->getType()->getPointerElementType(), &*EI, Idx);
CurFnInfo->getArgStruct(), &*EI, Idx);
llvm::Type *Ty =
cast<llvm::GetElementPtrInst>(Addr)->getResultElementType();
ReturnValuePointer = Address(Addr, Ty, getPointerAlign());
Expand Down

0 comments on commit 6c0af92

Please sign in to comment.