[opaque pointer types] Pass value type to GetElementPtr creation.

This cleans up all GetElementPtr creation in LLVM to explicitly pass a
value type rather than deriving it from the pointer's element-type.

Differential Revision: https://reviews.llvm.org/D57173

llvm-svn: 352913
This commit is contained in:
James Y Knight 2019-02-01 20:44:47 +00:00
parent 14359ef1b6
commit 7716075a17
35 changed files with 212 additions and 169 deletions

View File

@ -2424,16 +2424,18 @@ Error BitcodeReader::parseConstants() {
Elts.push_back(ValueList.getConstantFwdRef(Record[OpNum++], ElTy)); Elts.push_back(ValueList.getConstantFwdRef(Record[OpNum++], ElTy));
} }
if (PointeeType &&
PointeeType !=
cast<PointerType>(Elts[0]->getType()->getScalarType())
->getElementType())
return error("Explicit gep operator type does not match pointee type "
"of pointer operand");
if (Elts.size() < 1) if (Elts.size() < 1)
return error("Invalid gep with no operands"); return error("Invalid gep with no operands");
Type *ImplicitPointeeType =
cast<PointerType>(Elts[0]->getType()->getScalarType())
->getElementType();
if (!PointeeType)
PointeeType = ImplicitPointeeType;
else if (PointeeType != ImplicitPointeeType)
return error("Explicit gep operator type does not match pointee type "
"of pointer operand");
ArrayRef<Constant *> Indices(Elts.begin() + 1, Elts.end()); ArrayRef<Constant *> Indices(Elts.begin() + 1, Elts.end());
V = ConstantExpr::getGetElementPtr(PointeeType, Elts[0], Indices, V = ConstantExpr::getGetElementPtr(PointeeType, Elts[0], Indices,
InBounds, InRangeIndex); InBounds, InRangeIndex);

View File

@ -550,7 +550,7 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
if (StackGuardSlot) { if (StackGuardSlot) {
unsigned Offset = SSL.getObjectOffset(StackGuardSlot); unsigned Offset = SSL.getObjectOffset(StackGuardSlot);
Value *Off = IRB.CreateGEP(BasePointer, // BasePointer is i8* Value *Off = IRB.CreateGEP(Int8Ty, BasePointer, // BasePointer is i8*
ConstantInt::get(Int32Ty, -Offset)); ConstantInt::get(Int32Ty, -Offset));
Value *NewAI = Value *NewAI =
IRB.CreateBitCast(Off, StackGuardSlot->getType(), "StackGuardSlot"); IRB.CreateBitCast(Off, StackGuardSlot->getType(), "StackGuardSlot");
@ -569,7 +569,7 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
if (Size == 0) if (Size == 0)
Size = 1; // Don't create zero-sized stack objects. Size = 1; // Don't create zero-sized stack objects.
Value *Off = IRB.CreateGEP(BasePointer, // BasePointer is i8* Value *Off = IRB.CreateGEP(Int8Ty, BasePointer, // BasePointer is i8*
ConstantInt::get(Int32Ty, -Offset)); ConstantInt::get(Int32Ty, -Offset));
Value *NewArg = IRB.CreateBitCast(Off, Arg->getType(), Value *NewArg = IRB.CreateBitCast(Off, Arg->getType(),
Arg->getName() + ".unsafe-byval"); Arg->getName() + ".unsafe-byval");
@ -609,7 +609,7 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
InsertBefore = User; InsertBefore = User;
IRBuilder<> IRBUser(InsertBefore); IRBuilder<> IRBUser(InsertBefore);
Value *Off = IRBUser.CreateGEP(BasePointer, // BasePointer is i8* Value *Off = IRBUser.CreateGEP(Int8Ty, BasePointer, // BasePointer is i8*
ConstantInt::get(Int32Ty, -Offset)); ConstantInt::get(Int32Ty, -Offset));
Value *Replacement = IRBUser.CreateBitCast(Off, AI->getType(), Name); Value *Replacement = IRBUser.CreateBitCast(Off, AI->getType(), Name);
@ -637,7 +637,7 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
IRB.SetInsertPoint(BasePointer->getNextNode()); IRB.SetInsertPoint(BasePointer->getNextNode());
Value *StaticTop = Value *StaticTop =
IRB.CreateGEP(BasePointer, ConstantInt::get(Int32Ty, -FrameSize), IRB.CreateGEP(Int8Ty, BasePointer, ConstantInt::get(Int32Ty, -FrameSize),
"unsafe_stack_static_top"); "unsafe_stack_static_top");
IRB.CreateStore(StaticTop, UnsafeStackPtr); IRB.CreateStore(StaticTop, UnsafeStackPtr);
return StaticTop; return StaticTop;

View File

@ -2071,7 +2071,7 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
if (Idxs.empty()) return C; if (Idxs.empty()) return C;
Type *GEPTy = GetElementPtrInst::getGEPReturnType( Type *GEPTy = GetElementPtrInst::getGEPReturnType(
C, makeArrayRef((Value *const *)Idxs.data(), Idxs.size())); PointeeTy, C, makeArrayRef((Value *const *)Idxs.data(), Idxs.size()));
if (isa<UndefValue>(C)) if (isa<UndefValue>(C))
return UndefValue::get(GEPTy); return UndefValue::get(GEPTy);

View File

@ -8398,8 +8398,9 @@ bool AArch64TargetLowering::lowerInterleavedLoad(
// If we're generating more than one load, compute the base address of // If we're generating more than one load, compute the base address of
// subsequent loads as an offset from the previous. // subsequent loads as an offset from the previous.
if (LoadCount > 0) if (LoadCount > 0)
BaseAddr = Builder.CreateConstGEP1_32( BaseAddr =
BaseAddr, VecTy->getVectorNumElements() * Factor); Builder.CreateConstGEP1_32(VecTy->getVectorElementType(), BaseAddr,
VecTy->getVectorNumElements() * Factor);
CallInst *LdN = Builder.CreateCall( CallInst *LdN = Builder.CreateCall(
LdNFunc, Builder.CreateBitCast(BaseAddr, PtrTy), "ldN"); LdNFunc, Builder.CreateBitCast(BaseAddr, PtrTy), "ldN");
@ -8561,7 +8562,8 @@ bool AArch64TargetLowering::lowerInterleavedStore(StoreInst *SI,
// If we generating more than one store, we compute the base address of // If we generating more than one store, we compute the base address of
// subsequent stores as an offset from the previous. // subsequent stores as an offset from the previous.
if (StoreCount > 0) if (StoreCount > 0)
BaseAddr = Builder.CreateConstGEP1_32(BaseAddr, LaneLen * Factor); BaseAddr = Builder.CreateConstGEP1_32(SubVecTy->getVectorElementType(),
BaseAddr, LaneLen * Factor);
Ops.push_back(Builder.CreateBitCast(BaseAddr, PtrTy)); Ops.push_back(Builder.CreateBitCast(BaseAddr, PtrTy));
Builder.CreateCall(StNFunc, Ops); Builder.CreateCall(StNFunc, Ops);
@ -11717,8 +11719,9 @@ static Value *UseTlsOffset(IRBuilder<> &IRB, unsigned Offset) {
Function *ThreadPointerFunc = Function *ThreadPointerFunc =
Intrinsic::getDeclaration(M, Intrinsic::thread_pointer); Intrinsic::getDeclaration(M, Intrinsic::thread_pointer);
return IRB.CreatePointerCast( return IRB.CreatePointerCast(
IRB.CreateConstGEP1_32(IRB.CreateCall(ThreadPointerFunc), Offset), IRB.CreateConstGEP1_32(IRB.getInt8Ty(), IRB.CreateCall(ThreadPointerFunc),
Type::getInt8PtrTy(IRB.getContext())->getPointerTo(0)); Offset),
IRB.getInt8PtrTy()->getPointerTo(0));
} }
Value *AArch64TargetLowering::getIRStackGuard(IRBuilder<> &IRB) const { Value *AArch64TargetLowering::getIRStackGuard(IRBuilder<> &IRB) const {

View File

@ -140,17 +140,14 @@ bool AMDGPULowerKernelArguments::runOnFunction(Function &F) {
// //
// Additionally widen any sub-dword load to i32 even if suitably aligned, // Additionally widen any sub-dword load to i32 even if suitably aligned,
// so that CSE between different argument loads works easily. // so that CSE between different argument loads works easily.
ArgPtr = Builder.CreateConstInBoundsGEP1_64( ArgPtr = Builder.CreateConstInBoundsGEP1_64(
KernArgSegment, Builder.getInt8Ty(), KernArgSegment, AlignDownOffset,
AlignDownOffset, Arg.getName() + ".kernarg.offset.align.down");
Arg.getName() + ".kernarg.offset.align.down");
AdjustedArgTy = Builder.getInt32Ty(); AdjustedArgTy = Builder.getInt32Ty();
} else { } else {
ArgPtr = Builder.CreateConstInBoundsGEP1_64( ArgPtr = Builder.CreateConstInBoundsGEP1_64(
KernArgSegment, Builder.getInt8Ty(), KernArgSegment, EltOffset,
EltOffset, Arg.getName() + ".kernarg.offset");
Arg.getName() + ".kernarg.offset");
AdjustedArgTy = ArgTy; AdjustedArgTy = ArgTy;
} }

View File

@ -244,10 +244,10 @@ AMDGPUPromoteAlloca::getLocalSizeYZ(IRBuilder<> &Builder) {
// We could do a single 64-bit load here, but it's likely that the basic // We could do a single 64-bit load here, but it's likely that the basic
// 32-bit and extract sequence is already present, and it is probably easier // 32-bit and extract sequence is already present, and it is probably easier
// to CSE this. The loads should be mergable later anyway. // to CSE this. The loads should be mergable later anyway.
Value *GEPXY = Builder.CreateConstInBoundsGEP1_64(CastDispatchPtr, 1); Value *GEPXY = Builder.CreateConstInBoundsGEP1_64(I32Ty, CastDispatchPtr, 1);
LoadInst *LoadXY = Builder.CreateAlignedLoad(I32Ty, GEPXY, 4); LoadInst *LoadXY = Builder.CreateAlignedLoad(I32Ty, GEPXY, 4);
Value *GEPZU = Builder.CreateConstInBoundsGEP1_64(CastDispatchPtr, 2); Value *GEPZU = Builder.CreateConstInBoundsGEP1_64(I32Ty, CastDispatchPtr, 2);
LoadInst *LoadZU = Builder.CreateAlignedLoad(I32Ty, GEPZU, 4); LoadInst *LoadZU = Builder.CreateAlignedLoad(I32Ty, GEPZU, 4);
MDNode *MD = MDNode::get(Mod->getContext(), None); MDNode *MD = MDNode::get(Mod->getContext(), None);

View File

@ -14906,8 +14906,9 @@ bool ARMTargetLowering::lowerInterleavedLoad(
// If we're generating more than one load, compute the base address of // If we're generating more than one load, compute the base address of
// subsequent loads as an offset from the previous. // subsequent loads as an offset from the previous.
if (LoadCount > 0) if (LoadCount > 0)
BaseAddr = Builder.CreateConstGEP1_32( BaseAddr =
BaseAddr, VecTy->getVectorNumElements() * Factor); Builder.CreateConstGEP1_32(VecTy->getVectorElementType(), BaseAddr,
VecTy->getVectorNumElements() * Factor);
SmallVector<Value *, 2> Ops; SmallVector<Value *, 2> Ops;
Ops.push_back(Builder.CreateBitCast(BaseAddr, Int8Ptr)); Ops.push_back(Builder.CreateBitCast(BaseAddr, Int8Ptr));
@ -15046,7 +15047,8 @@ bool ARMTargetLowering::lowerInterleavedStore(StoreInst *SI,
// If we generating more than one store, we compute the base address of // If we generating more than one store, we compute the base address of
// subsequent stores as an offset from the previous. // subsequent stores as an offset from the previous.
if (StoreCount > 0) if (StoreCount > 0)
BaseAddr = Builder.CreateConstGEP1_32(BaseAddr, LaneLen * Factor); BaseAddr = Builder.CreateConstGEP1_32(SubVecTy->getVectorElementType(),
BaseAddr, LaneLen * Factor);
SmallVector<Value *, 6> Ops; SmallVector<Value *, 6> Ops;
Ops.push_back(Builder.CreateBitCast(BaseAddr, Int8Ptr)); Ops.push_back(Builder.CreateBitCast(BaseAddr, Int8Ptr));

View File

@ -213,7 +213,8 @@ void X86InterleavedAccessGroup::decompose(
// Generate N loads of T type. // Generate N loads of T type.
for (unsigned i = 0; i < NumLoads; i++) { for (unsigned i = 0; i < NumLoads; i++) {
// TODO: Support inbounds GEP. // TODO: Support inbounds GEP.
Value *NewBasePtr = Builder.CreateGEP(VecBasePtr, Builder.getInt32(i)); Value *NewBasePtr =
Builder.CreateGEP(VecBaseTy, VecBasePtr, Builder.getInt32(i));
Instruction *NewLoad = Instruction *NewLoad =
Builder.CreateAlignedLoad(VecBaseTy, NewBasePtr, LI->getAlignment()); Builder.CreateAlignedLoad(VecBaseTy, NewBasePtr, LI->getAlignment());
DecomposedVectors.push_back(NewLoad); DecomposedVectors.push_back(NewLoad);

View File

@ -781,8 +781,8 @@ void WinEHStatePass::addStateStores(Function &F, WinEHFuncInfo &FuncInfo) {
IRBuilder<> Builder(CS.getInstruction()); IRBuilder<> Builder(CS.getInstruction());
Value *State; Value *State;
if (InCleanup) { if (InCleanup) {
Value *StateField = Value *StateField = Builder.CreateStructGEP(RegNode->getAllocatedType(),
Builder.CreateStructGEP(nullptr, RegNode, StateFieldIndex); RegNode, StateFieldIndex);
State = Builder.CreateLoad(Builder.getInt32Ty(), StateField); State = Builder.CreateLoad(Builder.getInt32Ty(), StateField);
} else { } else {
State = Builder.getInt32(getStateForCallSite(BlockColors, FuncInfo, CS)); State = Builder.getInt32(getStateForCallSite(BlockColors, FuncInfo, CS));
@ -793,7 +793,7 @@ void WinEHStatePass::addStateStores(Function &F, WinEHFuncInfo &FuncInfo) {
void WinEHStatePass::insertStateNumberStore(Instruction *IP, int State) { void WinEHStatePass::insertStateNumberStore(Instruction *IP, int State) {
IRBuilder<> Builder(IP); IRBuilder<> Builder(IP);
Value *StateField = Value *StateField = Builder.CreateStructGEP(RegNode->getAllocatedType(),
Builder.CreateStructGEP(nullptr, RegNode, StateFieldIndex); RegNode, StateFieldIndex);
Builder.CreateStore(Builder.getInt32(State), StateField); Builder.CreateStore(Builder.getInt32(State), StateField);
} }

View File

@ -729,7 +729,8 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV) {
break; break;
if (Idxs.size() == GEPI->getNumOperands()-1) if (Idxs.size() == GEPI->getNumOperands()-1)
Changed |= OptimizeAwayTrappingUsesOfValue( Changed |= OptimizeAwayTrappingUsesOfValue(
GEPI, ConstantExpr::getGetElementPtr(nullptr, NewV, Idxs)); GEPI, ConstantExpr::getGetElementPtr(GEPI->getSourceElementType(),
NewV, Idxs));
if (GEPI->use_empty()) { if (GEPI->use_empty()) {
Changed = true; Changed = true;
GEPI->eraseFromParent(); GEPI->eraseFromParent();

View File

@ -2309,7 +2309,8 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
// If we found a path from the src to dest, create the getelementptr now. // If we found a path from the src to dest, create the getelementptr now.
if (SrcElTy == DstElTy) { if (SrcElTy == DstElTy) {
SmallVector<Value *, 8> Idxs(NumZeros + 1, Builder.getInt32(0)); SmallVector<Value *, 8> Idxs(NumZeros + 1, Builder.getInt32(0));
return GetElementPtrInst::CreateInBounds(Src, Idxs); return GetElementPtrInst::CreateInBounds(SrcPTy->getElementType(), Src,
Idxs);
} }
} }

View File

@ -212,8 +212,8 @@ static Instruction *simplifyAllocaArraySize(InstCombiner &IC, AllocaInst &AI) {
Type *IdxTy = IC.getDataLayout().getIntPtrType(AI.getType()); Type *IdxTy = IC.getDataLayout().getIntPtrType(AI.getType());
Value *NullIdx = Constant::getNullValue(IdxTy); Value *NullIdx = Constant::getNullValue(IdxTy);
Value *Idx[2] = {NullIdx, NullIdx}; Value *Idx[2] = {NullIdx, NullIdx};
Instruction *GEP = Instruction *GEP = GetElementPtrInst::CreateInBounds(
GetElementPtrInst::CreateInBounds(New, Idx, New->getName() + ".sub"); NewTy, New, Idx, New->getName() + ".sub");
IC.InsertNewInstBefore(GEP, *It); IC.InsertNewInstBefore(GEP, *It);
// Now make everything use the getelementptr instead of the original // Now make everything use the getelementptr instead of the original

View File

@ -1754,9 +1754,9 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// put NewSrc at same location as %src // put NewSrc at same location as %src
Builder.SetInsertPoint(cast<Instruction>(PtrOp)); Builder.SetInsertPoint(cast<Instruction>(PtrOp));
auto *NewSrc = cast<GetElementPtrInst>( auto *NewSrc = cast<GetElementPtrInst>(
Builder.CreateGEP(SO0, GO1, Src->getName())); Builder.CreateGEP(GEPEltType, SO0, GO1, Src->getName()));
NewSrc->setIsInBounds(Src->isInBounds()); NewSrc->setIsInBounds(Src->isInBounds());
auto *NewGEP = GetElementPtrInst::Create(nullptr, NewSrc, {SO1}); auto *NewGEP = GetElementPtrInst::Create(GEPEltType, NewSrc, {SO1});
NewGEP->setIsInBounds(GEP.isInBounds()); NewGEP->setIsInBounds(GEP.isInBounds());
return NewGEP; return NewGEP;
} }
@ -1880,6 +1880,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
if (StrippedPtr != PtrOp) { if (StrippedPtr != PtrOp) {
bool HasZeroPointerIndex = false; bool HasZeroPointerIndex = false;
Type *StrippedPtrEltTy = StrippedPtrTy->getElementType();
if (auto *C = dyn_cast<ConstantInt>(GEP.getOperand(1))) if (auto *C = dyn_cast<ConstantInt>(GEP.getOperand(1)))
HasZeroPointerIndex = C->isZero(); HasZeroPointerIndex = C->isZero();
@ -1893,11 +1895,11 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
if (HasZeroPointerIndex) { if (HasZeroPointerIndex) {
if (auto *CATy = dyn_cast<ArrayType>(GEPEltType)) { if (auto *CATy = dyn_cast<ArrayType>(GEPEltType)) {
// GEP (bitcast i8* X to [0 x i8]*), i32 0, ... ? // GEP (bitcast i8* X to [0 x i8]*), i32 0, ... ?
if (CATy->getElementType() == StrippedPtrTy->getElementType()) { if (CATy->getElementType() == StrippedPtrEltTy) {
// -> GEP i8* X, ... // -> GEP i8* X, ...
SmallVector<Value*, 8> Idx(GEP.idx_begin()+1, GEP.idx_end()); SmallVector<Value*, 8> Idx(GEP.idx_begin()+1, GEP.idx_end());
GetElementPtrInst *Res = GetElementPtrInst::Create( GetElementPtrInst *Res = GetElementPtrInst::Create(
StrippedPtrTy->getElementType(), StrippedPtr, Idx, GEP.getName()); StrippedPtrEltTy, StrippedPtr, Idx, GEP.getName());
Res->setIsInBounds(GEP.isInBounds()); Res->setIsInBounds(GEP.isInBounds());
if (StrippedPtrTy->getAddressSpace() == GEP.getAddressSpace()) if (StrippedPtrTy->getAddressSpace() == GEP.getAddressSpace())
return Res; return Res;
@ -1910,7 +1912,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
return new AddrSpaceCastInst(Builder.Insert(Res), GEPType); return new AddrSpaceCastInst(Builder.Insert(Res), GEPType);
} }
if (auto *XATy = dyn_cast<ArrayType>(StrippedPtrTy->getElementType())) { if (auto *XATy = dyn_cast<ArrayType>(StrippedPtrEltTy)) {
// GEP (bitcast [10 x i8]* X to [0 x i8]*), i32 0, ... ? // GEP (bitcast [10 x i8]* X to [0 x i8]*), i32 0, ... ?
if (CATy->getElementType() == XATy->getElementType()) { if (CATy->getElementType() == XATy->getElementType()) {
// -> GEP [10 x i8]* X, i32 0, ... // -> GEP [10 x i8]* X, i32 0, ...
@ -1933,11 +1935,12 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// %0 = GEP [10 x i8] addrspace(1)* X, ... // %0 = GEP [10 x i8] addrspace(1)* X, ...
// addrspacecast i8 addrspace(1)* %0 to i8* // addrspacecast i8 addrspace(1)* %0 to i8*
SmallVector<Value*, 8> Idx(GEP.idx_begin(), GEP.idx_end()); SmallVector<Value*, 8> Idx(GEP.idx_begin(), GEP.idx_end());
Value *NewGEP = GEP.isInBounds() Value *NewGEP =
? Builder.CreateInBoundsGEP( GEP.isInBounds()
nullptr, StrippedPtr, Idx, GEP.getName()) ? Builder.CreateInBoundsGEP(StrippedPtrEltTy, StrippedPtr,
: Builder.CreateGEP(nullptr, StrippedPtr, Idx, Idx, GEP.getName())
GEP.getName()); : Builder.CreateGEP(StrippedPtrEltTy, StrippedPtr, Idx,
GEP.getName());
return new AddrSpaceCastInst(NewGEP, GEPType); return new AddrSpaceCastInst(NewGEP, GEPType);
} }
} }
@ -1946,17 +1949,17 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// Transform things like: // Transform things like:
// %t = getelementptr i32* bitcast ([2 x i32]* %str to i32*), i32 %V // %t = getelementptr i32* bitcast ([2 x i32]* %str to i32*), i32 %V
// into: %t1 = getelementptr [2 x i32]* %str, i32 0, i32 %V; bitcast // into: %t1 = getelementptr [2 x i32]* %str, i32 0, i32 %V; bitcast
Type *SrcEltTy = StrippedPtrTy->getElementType(); if (StrippedPtrEltTy->isArrayTy() &&
if (SrcEltTy->isArrayTy() && DL.getTypeAllocSize(StrippedPtrEltTy->getArrayElementType()) ==
DL.getTypeAllocSize(SrcEltTy->getArrayElementType()) ==
DL.getTypeAllocSize(GEPEltType)) { DL.getTypeAllocSize(GEPEltType)) {
Type *IdxType = DL.getIndexType(GEPType); Type *IdxType = DL.getIndexType(GEPType);
Value *Idx[2] = { Constant::getNullValue(IdxType), GEP.getOperand(1) }; Value *Idx[2] = { Constant::getNullValue(IdxType), GEP.getOperand(1) };
Value *NewGEP = Value *NewGEP =
GEP.isInBounds() GEP.isInBounds()
? Builder.CreateInBoundsGEP(nullptr, StrippedPtr, Idx, ? Builder.CreateInBoundsGEP(StrippedPtrEltTy, StrippedPtr, Idx,
GEP.getName()) GEP.getName())
: Builder.CreateGEP(nullptr, StrippedPtr, Idx, GEP.getName()); : Builder.CreateGEP(StrippedPtrEltTy, StrippedPtr, Idx,
GEP.getName());
// V and GEP are both pointer types --> BitCast // V and GEP are both pointer types --> BitCast
return CastInst::CreatePointerBitCastOrAddrSpaceCast(NewGEP, GEPType); return CastInst::CreatePointerBitCastOrAddrSpaceCast(NewGEP, GEPType);
@ -1966,11 +1969,11 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// %V = mul i64 %N, 4 // %V = mul i64 %N, 4
// %t = getelementptr i8* bitcast (i32* %arr to i8*), i32 %V // %t = getelementptr i8* bitcast (i32* %arr to i8*), i32 %V
// into: %t1 = getelementptr i32* %arr, i32 %N; bitcast // into: %t1 = getelementptr i32* %arr, i32 %N; bitcast
if (GEPEltType->isSized() && SrcEltTy->isSized()) { if (GEPEltType->isSized() && StrippedPtrEltTy->isSized()) {
// Check that changing the type amounts to dividing the index by a scale // Check that changing the type amounts to dividing the index by a scale
// factor. // factor.
uint64_t ResSize = DL.getTypeAllocSize(GEPEltType); uint64_t ResSize = DL.getTypeAllocSize(GEPEltType);
uint64_t SrcSize = DL.getTypeAllocSize(SrcEltTy); uint64_t SrcSize = DL.getTypeAllocSize(StrippedPtrEltTy);
if (ResSize && SrcSize % ResSize == 0) { if (ResSize && SrcSize % ResSize == 0) {
Value *Idx = GEP.getOperand(1); Value *Idx = GEP.getOperand(1);
unsigned BitWidth = Idx->getType()->getPrimitiveSizeInBits(); unsigned BitWidth = Idx->getType()->getPrimitiveSizeInBits();
@ -1989,9 +1992,9 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// GEP may not be "inbounds". // GEP may not be "inbounds".
Value *NewGEP = Value *NewGEP =
GEP.isInBounds() && NSW GEP.isInBounds() && NSW
? Builder.CreateInBoundsGEP(nullptr, StrippedPtr, NewIdx, ? Builder.CreateInBoundsGEP(StrippedPtrEltTy, StrippedPtr,
GEP.getName()) NewIdx, GEP.getName())
: Builder.CreateGEP(nullptr, StrippedPtr, NewIdx, : Builder.CreateGEP(StrippedPtrEltTy, StrippedPtr, NewIdx,
GEP.getName()); GEP.getName());
// The NewGEP must be pointer typed, so must the old one -> BitCast // The NewGEP must be pointer typed, so must the old one -> BitCast
@ -2005,13 +2008,13 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// getelementptr i8* bitcast ([100 x double]* X to i8*), i32 %tmp // getelementptr i8* bitcast ([100 x double]* X to i8*), i32 %tmp
// (where tmp = 8*tmp2) into: // (where tmp = 8*tmp2) into:
// getelementptr [100 x double]* %arr, i32 0, i32 %tmp2; bitcast // getelementptr [100 x double]* %arr, i32 0, i32 %tmp2; bitcast
if (GEPEltType->isSized() && SrcEltTy->isSized() && if (GEPEltType->isSized() && StrippedPtrEltTy->isSized() &&
SrcEltTy->isArrayTy()) { StrippedPtrEltTy->isArrayTy()) {
// Check that changing to the array element type amounts to dividing the // Check that changing to the array element type amounts to dividing the
// index by a scale factor. // index by a scale factor.
uint64_t ResSize = DL.getTypeAllocSize(GEPEltType); uint64_t ResSize = DL.getTypeAllocSize(GEPEltType);
uint64_t ArrayEltSize = uint64_t ArrayEltSize =
DL.getTypeAllocSize(SrcEltTy->getArrayElementType()); DL.getTypeAllocSize(StrippedPtrEltTy->getArrayElementType());
if (ResSize && ArrayEltSize % ResSize == 0) { if (ResSize && ArrayEltSize % ResSize == 0) {
Value *Idx = GEP.getOperand(1); Value *Idx = GEP.getOperand(1);
unsigned BitWidth = Idx->getType()->getPrimitiveSizeInBits(); unsigned BitWidth = Idx->getType()->getPrimitiveSizeInBits();
@ -2031,11 +2034,12 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
Type *IndTy = DL.getIndexType(GEPType); Type *IndTy = DL.getIndexType(GEPType);
Value *Off[2] = {Constant::getNullValue(IndTy), NewIdx}; Value *Off[2] = {Constant::getNullValue(IndTy), NewIdx};
Value *NewGEP = GEP.isInBounds() && NSW Value *NewGEP =
? Builder.CreateInBoundsGEP( GEP.isInBounds() && NSW
SrcEltTy, StrippedPtr, Off, GEP.getName()) ? Builder.CreateInBoundsGEP(StrippedPtrEltTy, StrippedPtr,
: Builder.CreateGEP(SrcEltTy, StrippedPtr, Off, Off, GEP.getName())
GEP.getName()); : Builder.CreateGEP(StrippedPtrEltTy, StrippedPtr, Off,
GEP.getName());
// The NewGEP must be pointer typed, so must the old one -> BitCast // The NewGEP must be pointer typed, so must the old one -> BitCast
return CastInst::CreatePointerBitCastOrAddrSpaceCast(NewGEP, return CastInst::CreatePointerBitCastOrAddrSpaceCast(NewGEP,
GEPType); GEPType);
@ -2083,8 +2087,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// constructing an AddrSpaceCastInst // constructing an AddrSpaceCastInst
Value *NGEP = Value *NGEP =
GEP.isInBounds() GEP.isInBounds()
? Builder.CreateInBoundsGEP(nullptr, SrcOp, {Ops[1], Ops[2]}) ? Builder.CreateInBoundsGEP(SrcEltType, SrcOp, {Ops[1], Ops[2]})
: Builder.CreateGEP(nullptr, SrcOp, {Ops[1], Ops[2]}); : Builder.CreateGEP(SrcEltType, SrcOp, {Ops[1], Ops[2]});
NGEP->takeName(&GEP); NGEP->takeName(&GEP);
// Preserve GEP address space to satisfy users // Preserve GEP address space to satisfy users
@ -2131,8 +2135,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
if (FindElementAtOffset(SrcType, Offset.getSExtValue(), NewIndices)) { if (FindElementAtOffset(SrcType, Offset.getSExtValue(), NewIndices)) {
Value *NGEP = Value *NGEP =
GEP.isInBounds() GEP.isInBounds()
? Builder.CreateInBoundsGEP(nullptr, SrcOp, NewIndices) ? Builder.CreateInBoundsGEP(SrcEltType, SrcOp, NewIndices)
: Builder.CreateGEP(nullptr, SrcOp, NewIndices); : Builder.CreateGEP(SrcEltType, SrcOp, NewIndices);
if (NGEP->getType() == GEPType) if (NGEP->getType() == GEPType)
return replaceInstUsesWith(GEP, NGEP); return replaceInstUsesWith(GEP, NGEP);
@ -2158,7 +2162,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
APInt AllocSize(IdxWidth, DL.getTypeAllocSize(AI->getAllocatedType())); APInt AllocSize(IdxWidth, DL.getTypeAllocSize(AI->getAllocatedType()));
if (BasePtrOffset.ule(AllocSize)) { if (BasePtrOffset.ule(AllocSize)) {
return GetElementPtrInst::CreateInBounds( return GetElementPtrInst::CreateInBounds(
PtrOp, makeArrayRef(Ops).slice(1), GEP.getName()); GEP.getSourceElementType(), PtrOp, makeArrayRef(Ops).slice(1),
GEP.getName());
} }
} }
} }

View File

@ -1392,7 +1392,7 @@ static void instrumentMaskedLoadOrStore(AddressSanitizer *Pass,
IRBuilder<> IRB(InsertBefore); IRBuilder<> IRB(InsertBefore);
InstrumentedAddress = InstrumentedAddress =
IRB.CreateGEP(Addr, {Zero, ConstantInt::get(IntptrTy, Idx)}); IRB.CreateGEP(VTy, Addr, {Zero, ConstantInt::get(IntptrTy, Idx)});
doInstrumentAddress(Pass, I, InsertBefore, InstrumentedAddress, Alignment, doInstrumentAddress(Pass, I, InsertBefore, InstrumentedAddress, Alignment,
Granularity, ElemTypeSize, IsWrite, SizeArgument, Granularity, ElemTypeSize, IsWrite, SizeArgument,
UseCalls, Exp); UseCalls, Exp);

View File

@ -1015,7 +1015,8 @@ Value *DFSanFunction::getRetvalTLS() {
Value *DFSanFunction::getArgTLS(unsigned Idx, Instruction *Pos) { Value *DFSanFunction::getArgTLS(unsigned Idx, Instruction *Pos) {
IRBuilder<> IRB(Pos); IRBuilder<> IRB(Pos);
return IRB.CreateConstGEP2_64(getArgTLSPtr(), 0, Idx); return IRB.CreateConstGEP2_64(ArrayType::get(DFS.ShadowTy, 64),
getArgTLSPtr(), 0, Idx);
} }
Value *DFSanFunction::getShadow(Value *V) { Value *DFSanFunction::getShadow(Value *V) {

View File

@ -810,8 +810,8 @@ bool GCOVProfiler::emitProfileArcs() {
auto It = EdgeToCounter.find({Pred, &BB}); auto It = EdgeToCounter.find({Pred, &BB});
assert(It != EdgeToCounter.end()); assert(It != EdgeToCounter.end());
const unsigned Edge = It->second; const unsigned Edge = It->second;
Value *EdgeCounter = Value *EdgeCounter = BuilderForPhi.CreateConstInBoundsGEP2_64(
BuilderForPhi.CreateConstInBoundsGEP2_64(Counters, 0, Edge); Counters->getValueType(), Counters, 0, Edge);
Phi->addIncoming(EdgeCounter, Pred); Phi->addIncoming(EdgeCounter, Pred);
} }
@ -826,8 +826,8 @@ bool GCOVProfiler::emitProfileArcs() {
auto It = EdgeToCounter.find({&BB, nullptr}); auto It = EdgeToCounter.find({&BB, nullptr});
assert(It != EdgeToCounter.end()); assert(It != EdgeToCounter.end());
const unsigned Edge = It->second; const unsigned Edge = It->second;
Value *Counter = Value *Counter = Builder.CreateConstInBoundsGEP2_64(
Builder.CreateConstInBoundsGEP2_64(Counters, 0, Edge); Counters->getValueType(), Counters, 0, Edge);
Value *Count = Builder.CreateLoad(Builder.getInt64Ty(), Counter); Value *Count = Builder.CreateLoad(Builder.getInt64Ty(), Counter);
Count = Builder.CreateAdd(Count, Builder.getInt64(1)); Count = Builder.CreateAdd(Count, Builder.getInt64(1));
Builder.CreateStore(Count, Counter); Builder.CreateStore(Count, Counter);
@ -1084,25 +1084,32 @@ Function *GCOVProfiler::insertCounterWriteout(
PHINode *IV = PHINode *IV =
Builder.CreatePHI(Builder.getInt32Ty(), /*NumReservedValues*/ 2); Builder.CreatePHI(Builder.getInt32Ty(), /*NumReservedValues*/ 2);
IV->addIncoming(Builder.getInt32(0), BB); IV->addIncoming(Builder.getInt32(0), BB);
auto *FileInfoPtr = auto *FileInfoPtr = Builder.CreateInBoundsGEP(
Builder.CreateInBoundsGEP(FileInfoArrayGV, {Builder.getInt32(0), IV}); FileInfoArrayTy, FileInfoArrayGV, {Builder.getInt32(0), IV});
auto *StartFileCallArgsPtr = Builder.CreateStructGEP(FileInfoPtr, 0); auto *StartFileCallArgsPtr =
Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 0);
auto *StartFileCall = Builder.CreateCall( auto *StartFileCall = Builder.CreateCall(
StartFile, StartFile,
{Builder.CreateLoad(StartFileCallArgsTy->getElementType(0), {Builder.CreateLoad(StartFileCallArgsTy->getElementType(0),
Builder.CreateStructGEP(StartFileCallArgsPtr, 0)), Builder.CreateStructGEP(StartFileCallArgsTy,
StartFileCallArgsPtr, 0)),
Builder.CreateLoad(StartFileCallArgsTy->getElementType(1), Builder.CreateLoad(StartFileCallArgsTy->getElementType(1),
Builder.CreateStructGEP(StartFileCallArgsPtr, 1)), Builder.CreateStructGEP(StartFileCallArgsTy,
StartFileCallArgsPtr, 1)),
Builder.CreateLoad(StartFileCallArgsTy->getElementType(2), Builder.CreateLoad(StartFileCallArgsTy->getElementType(2),
Builder.CreateStructGEP(StartFileCallArgsPtr, 2))}); Builder.CreateStructGEP(StartFileCallArgsTy,
StartFileCallArgsPtr, 2))});
if (auto AK = TLI->getExtAttrForI32Param(false)) if (auto AK = TLI->getExtAttrForI32Param(false))
StartFileCall->addParamAttr(2, AK); StartFileCall->addParamAttr(2, AK);
auto *NumCounters = Builder.CreateLoad( auto *NumCounters =
FileInfoTy->getElementType(1), Builder.CreateStructGEP(FileInfoPtr, 1)); Builder.CreateLoad(FileInfoTy->getElementType(1),
auto *EmitFunctionCallArgsArray = Builder.CreateLoad( Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 1));
FileInfoTy->getElementType(2), Builder.CreateStructGEP(FileInfoPtr, 2)); auto *EmitFunctionCallArgsArray =
auto *EmitArcsCallArgsArray = Builder.CreateLoad( Builder.CreateLoad(FileInfoTy->getElementType(2),
FileInfoTy->getElementType(3), Builder.CreateStructGEP(FileInfoPtr, 3)); Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 2));
auto *EmitArcsCallArgsArray =
Builder.CreateLoad(FileInfoTy->getElementType(3),
Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 3));
auto *EnterCounterLoopCond = auto *EnterCounterLoopCond =
Builder.CreateICmpSLT(Builder.getInt32(0), NumCounters); Builder.CreateICmpSLT(Builder.getInt32(0), NumCounters);
Builder.CreateCondBr(EnterCounterLoopCond, CounterLoopHeader, FileLoopLatch); Builder.CreateCondBr(EnterCounterLoopCond, CounterLoopHeader, FileLoopLatch);
@ -1110,21 +1117,26 @@ Function *GCOVProfiler::insertCounterWriteout(
Builder.SetInsertPoint(CounterLoopHeader); Builder.SetInsertPoint(CounterLoopHeader);
auto *JV = Builder.CreatePHI(Builder.getInt32Ty(), /*NumReservedValues*/ 2); auto *JV = Builder.CreatePHI(Builder.getInt32Ty(), /*NumReservedValues*/ 2);
JV->addIncoming(Builder.getInt32(0), FileLoopHeader); JV->addIncoming(Builder.getInt32(0), FileLoopHeader);
auto *EmitFunctionCallArgsPtr = auto *EmitFunctionCallArgsPtr = Builder.CreateInBoundsGEP(
Builder.CreateInBoundsGEP(EmitFunctionCallArgsArray, {JV}); EmitFunctionCallArgsTy, EmitFunctionCallArgsArray, JV);
auto *EmitFunctionCall = Builder.CreateCall( auto *EmitFunctionCall = Builder.CreateCall(
EmitFunction, EmitFunction,
{Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(0), {Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(0),
Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 0)), Builder.CreateStructGEP(EmitFunctionCallArgsTy,
EmitFunctionCallArgsPtr, 0)),
Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(1), Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(1),
Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 1)), Builder.CreateStructGEP(EmitFunctionCallArgsTy,
EmitFunctionCallArgsPtr, 1)),
Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(2), Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(2),
Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 2)), Builder.CreateStructGEP(EmitFunctionCallArgsTy,
EmitFunctionCallArgsPtr, 2)),
Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(3), Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(3),
Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 3)), Builder.CreateStructGEP(EmitFunctionCallArgsTy,
Builder.CreateLoad( EmitFunctionCallArgsPtr, 3)),
EmitFunctionCallArgsTy->getElementType(4), Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(4),
Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 4))}); Builder.CreateStructGEP(EmitFunctionCallArgsTy,
EmitFunctionCallArgsPtr,
4))});
if (auto AK = TLI->getExtAttrForI32Param(false)) { if (auto AK = TLI->getExtAttrForI32Param(false)) {
EmitFunctionCall->addParamAttr(0, AK); EmitFunctionCall->addParamAttr(0, AK);
EmitFunctionCall->addParamAttr(2, AK); EmitFunctionCall->addParamAttr(2, AK);
@ -1132,13 +1144,15 @@ Function *GCOVProfiler::insertCounterWriteout(
EmitFunctionCall->addParamAttr(4, AK); EmitFunctionCall->addParamAttr(4, AK);
} }
auto *EmitArcsCallArgsPtr = auto *EmitArcsCallArgsPtr =
Builder.CreateInBoundsGEP(EmitArcsCallArgsArray, {JV}); Builder.CreateInBoundsGEP(EmitArcsCallArgsTy, EmitArcsCallArgsArray, JV);
auto *EmitArcsCall = Builder.CreateCall( auto *EmitArcsCall = Builder.CreateCall(
EmitArcs, EmitArcs,
{Builder.CreateLoad(EmitArcsCallArgsTy->getElementType(0), {Builder.CreateLoad(
Builder.CreateStructGEP(EmitArcsCallArgsPtr, 0)), EmitArcsCallArgsTy->getElementType(0),
Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 0)),
Builder.CreateLoad(EmitArcsCallArgsTy->getElementType(1), Builder.CreateLoad(EmitArcsCallArgsTy->getElementType(1),
Builder.CreateStructGEP(EmitArcsCallArgsPtr, 1))}); Builder.CreateStructGEP(EmitArcsCallArgsTy,
EmitArcsCallArgsPtr, 1))});
if (auto AK = TLI->getExtAttrForI32Param(false)) if (auto AK = TLI->getExtAttrForI32Param(false))
EmitArcsCall->addParamAttr(0, AK); EmitArcsCall->addParamAttr(0, AK);
auto *NextJV = Builder.CreateAdd(JV, Builder.getInt32(1)); auto *NextJV = Builder.CreateAdd(JV, Builder.getInt32(1));

View File

@ -789,7 +789,8 @@ Value *HWAddressSanitizer::getHwasanThreadSlotPtr(IRBuilder<> &IRB, Type *Ty) {
Function *ThreadPointerFunc = Function *ThreadPointerFunc =
Intrinsic::getDeclaration(M, Intrinsic::thread_pointer); Intrinsic::getDeclaration(M, Intrinsic::thread_pointer);
Value *SlotPtr = IRB.CreatePointerCast( Value *SlotPtr = IRB.CreatePointerCast(
IRB.CreateConstGEP1_32(IRB.CreateCall(ThreadPointerFunc), 0x30), IRB.CreateConstGEP1_32(IRB.getInt8Ty(),
IRB.CreateCall(ThreadPointerFunc), 0x30),
Ty->getPointerTo(0)); Ty->getPointerTo(0));
return SlotPtr; return SlotPtr;
} }

View File

@ -598,7 +598,8 @@ void InstrProfiling::lowerIncrement(InstrProfIncrementInst *Inc) {
IRBuilder<> Builder(Inc); IRBuilder<> Builder(Inc);
uint64_t Index = Inc->getIndex()->getZExtValue(); uint64_t Index = Inc->getIndex()->getZExtValue();
Value *Addr = Builder.CreateConstInBoundsGEP2_64(Counters, 0, Index); Value *Addr = Builder.CreateConstInBoundsGEP2_64(Counters->getValueType(),
Counters, 0, Index);
if (Options.Atomic || AtomicCounterUpdateAll) { if (Options.Atomic || AtomicCounterUpdateAll) {
Builder.CreateAtomicRMW(AtomicRMWInst::Add, Addr, Inc->getStep(), Builder.CreateAtomicRMW(AtomicRMWInst::Add, Addr, Inc->getStep(),

View File

@ -557,6 +557,7 @@ private:
FunctionCallee MemmoveFn, MemcpyFn, MemsetFn; FunctionCallee MemmoveFn, MemcpyFn, MemsetFn;
/// KMSAN callback for task-local function argument shadow. /// KMSAN callback for task-local function argument shadow.
StructType *MsanContextStateTy;
FunctionCallee MsanGetContextStateFn; FunctionCallee MsanGetContextStateFn;
/// Functions for poisoning/unpoisoning local variables /// Functions for poisoning/unpoisoning local variables
@ -677,18 +678,15 @@ void MemorySanitizer::createKernelApi(Module &M) {
IRB.getInt32Ty()); IRB.getInt32Ty());
// Requests the per-task context state (kmsan_context_state*) from the // Requests the per-task context state (kmsan_context_state*) from the
// runtime library. // runtime library.
MsanContextStateTy = StructType::get(
ArrayType::get(IRB.getInt64Ty(), kParamTLSSize / 8),
ArrayType::get(IRB.getInt64Ty(), kRetvalTLSSize / 8),
ArrayType::get(IRB.getInt64Ty(), kParamTLSSize / 8),
ArrayType::get(IRB.getInt64Ty(), kParamTLSSize / 8), /* va_arg_origin */
IRB.getInt64Ty(), ArrayType::get(OriginTy, kParamTLSSize / 4), OriginTy,
OriginTy);
MsanGetContextStateFn = M.getOrInsertFunction( MsanGetContextStateFn = M.getOrInsertFunction(
"__msan_get_context_state", "__msan_get_context_state", PointerType::get(MsanContextStateTy, 0));
PointerType::get(
StructType::get(ArrayType::get(IRB.getInt64Ty(), kParamTLSSize / 8),
ArrayType::get(IRB.getInt64Ty(), kRetvalTLSSize / 8),
ArrayType::get(IRB.getInt64Ty(), kParamTLSSize / 8),
ArrayType::get(IRB.getInt64Ty(),
kParamTLSSize / 8), /* va_arg_origin */
IRB.getInt64Ty(),
ArrayType::get(OriginTy, kParamTLSSize / 4), OriginTy,
OriginTy),
0));
Type *RetTy = StructType::get(PointerType::get(IRB.getInt8Ty(), 0), Type *RetTy = StructType::get(PointerType::get(IRB.getInt8Ty(), 0),
PointerType::get(IRB.getInt32Ty(), 0)); PointerType::get(IRB.getInt32Ty(), 0));
@ -1096,7 +1094,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
for (unsigned i = Ofs; i < (Size + kOriginSize - 1) / kOriginSize; ++i) { for (unsigned i = Ofs; i < (Size + kOriginSize - 1) / kOriginSize; ++i) {
Value *GEP = Value *GEP =
i ? IRB.CreateConstGEP1_32(nullptr, OriginPtr, i) : OriginPtr; i ? IRB.CreateConstGEP1_32(MS.OriginTy, OriginPtr, i) : OriginPtr;
IRB.CreateAlignedStore(Origin, GEP, CurrentAlignment); IRB.CreateAlignedStore(Origin, GEP, CurrentAlignment);
CurrentAlignment = kMinOriginAlignment; CurrentAlignment = kMinOriginAlignment;
} }
@ -1241,20 +1239,22 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
IRBuilder<> IRB(F.getEntryBlock().getFirstNonPHI()); IRBuilder<> IRB(F.getEntryBlock().getFirstNonPHI());
Value *ContextState = IRB.CreateCall(MS.MsanGetContextStateFn, {}); Value *ContextState = IRB.CreateCall(MS.MsanGetContextStateFn, {});
Constant *Zero = IRB.getInt32(0); Constant *Zero = IRB.getInt32(0);
MS.ParamTLS = MS.ParamTLS = IRB.CreateGEP(MS.MsanContextStateTy, ContextState,
IRB.CreateGEP(ContextState, {Zero, IRB.getInt32(0)}, "param_shadow"); {Zero, IRB.getInt32(0)}, "param_shadow");
MS.RetvalTLS = MS.RetvalTLS = IRB.CreateGEP(MS.MsanContextStateTy, ContextState,
IRB.CreateGEP(ContextState, {Zero, IRB.getInt32(1)}, "retval_shadow"); {Zero, IRB.getInt32(1)}, "retval_shadow");
MS.VAArgTLS = MS.VAArgTLS = IRB.CreateGEP(MS.MsanContextStateTy, ContextState,
IRB.CreateGEP(ContextState, {Zero, IRB.getInt32(2)}, "va_arg_shadow"); {Zero, IRB.getInt32(2)}, "va_arg_shadow");
MS.VAArgOriginTLS = MS.VAArgOriginTLS = IRB.CreateGEP(MS.MsanContextStateTy, ContextState,
IRB.CreateGEP(ContextState, {Zero, IRB.getInt32(3)}, "va_arg_origin"); {Zero, IRB.getInt32(3)}, "va_arg_origin");
MS.VAArgOverflowSizeTLS = IRB.CreateGEP( MS.VAArgOverflowSizeTLS =
ContextState, {Zero, IRB.getInt32(4)}, "va_arg_overflow_size"); IRB.CreateGEP(MS.MsanContextStateTy, ContextState,
MS.ParamOriginTLS = {Zero, IRB.getInt32(4)}, "va_arg_overflow_size");
IRB.CreateGEP(ContextState, {Zero, IRB.getInt32(5)}, "param_origin"); MS.ParamOriginTLS = IRB.CreateGEP(MS.MsanContextStateTy, ContextState,
{Zero, IRB.getInt32(5)}, "param_origin");
MS.RetvalOriginTLS = MS.RetvalOriginTLS =
IRB.CreateGEP(ContextState, {Zero, IRB.getInt32(6)}, "retval_origin"); IRB.CreateGEP(MS.MsanContextStateTy, ContextState,
{Zero, IRB.getInt32(6)}, "retval_origin");
return ret; return ret;
} }

View File

@ -269,7 +269,7 @@ SanitizerCoverageModule::CreateSecStartEnd(Module &M, const char *Section,
// Account for the fact that on windows-msvc __start_* symbols actually // Account for the fact that on windows-msvc __start_* symbols actually
// point to a uint64_t before the start of the array. // point to a uint64_t before the start of the array.
auto SecStartI8Ptr = IRB.CreatePointerCast(SecStart, Int8PtrTy); auto SecStartI8Ptr = IRB.CreatePointerCast(SecStart, Int8PtrTy);
auto GEP = IRB.CreateGEP(SecStartI8Ptr, auto GEP = IRB.CreateGEP(Int8Ty, SecStartI8Ptr,
ConstantInt::get(IntptrTy, sizeof(uint64_t))); ConstantInt::get(IntptrTy, sizeof(uint64_t)));
return std::make_pair(IRB.CreatePointerCast(GEP, Ty), SecEndPtr); return std::make_pair(IRB.CreatePointerCast(GEP, Ty), SecEndPtr);
} }
@ -820,7 +820,7 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
} }
if (Options.Inline8bitCounters) { if (Options.Inline8bitCounters) {
auto CounterPtr = IRB.CreateGEP( auto CounterPtr = IRB.CreateGEP(
Function8bitCounterArray, Function8bitCounterArray->getValueType(), Function8bitCounterArray,
{ConstantInt::get(IntptrTy, 0), ConstantInt::get(IntptrTy, Idx)}); {ConstantInt::get(IntptrTy, 0), ConstantInt::get(IntptrTy, Idx)});
auto Load = IRB.CreateLoad(Int8Ty, CounterPtr); auto Load = IRB.CreateLoad(Int8Ty, CounterPtr);
auto Inc = IRB.CreateAdd(Load, ConstantInt::get(Int8Ty, 1)); auto Inc = IRB.CreateAdd(Load, ConstantInt::get(Int8Ty, 1));

View File

@ -945,6 +945,7 @@ static bool tryToShorten(Instruction *EarlierWrite, int64_t &EarlierOffset,
Value *Indices[1] = { Value *Indices[1] = {
ConstantInt::get(EarlierWriteLength->getType(), OffsetMoved)}; ConstantInt::get(EarlierWriteLength->getType(), OffsetMoved)};
GetElementPtrInst *NewDestGEP = GetElementPtrInst::CreateInBounds( GetElementPtrInst *NewDestGEP = GetElementPtrInst::CreateInBounds(
EarlierIntrinsic->getRawDest()->getType()->getPointerElementType(),
EarlierIntrinsic->getRawDest(), Indices, "", EarlierWrite); EarlierIntrinsic->getRawDest(), Indices, "", EarlierWrite);
EarlierIntrinsic->setDest(NewDestGEP); EarlierIntrinsic->setDest(NewDestGEP);
EarlierOffset = EarlierOffset + OffsetMoved; EarlierOffset = EarlierOffset + OffsetMoved;

View File

@ -2288,7 +2288,8 @@ static Value *genLoopLimit(PHINode *IndVar, const SCEV *IVCount, Loop *L,
"unit stride pointer IV must be i8*"); "unit stride pointer IV must be i8*");
IRBuilder<> Builder(L->getLoopPreheader()->getTerminator()); IRBuilder<> Builder(L->getLoopPreheader()->getTerminator());
return Builder.CreateGEP(nullptr, GEPBase, GEPOffset, "lftr.limit"); return Builder.CreateGEP(GEPBase->getType()->getPointerElementType(),
GEPBase, GEPOffset, "lftr.limit");
} else { } else {
// In any other case, convert both IVInit and IVCount to integers before // In any other case, convert both IVInit and IVCount to integers before
// comparing. This may result in SCEV expansion of pointers, but in practice // comparing. This may result in SCEV expansion of pointers, but in practice

View File

@ -1134,8 +1134,10 @@ bool MemCpyOptPass::processMemSetMemCpyDependence(MemCpyInst *MemCpy,
Value *SizeDiff = Builder.CreateSub(DestSize, SrcSize); Value *SizeDiff = Builder.CreateSub(DestSize, SrcSize);
Value *MemsetLen = Builder.CreateSelect( Value *MemsetLen = Builder.CreateSelect(
Ule, ConstantInt::getNullValue(DestSize->getType()), SizeDiff); Ule, ConstantInt::getNullValue(DestSize->getType()), SizeDiff);
Builder.CreateMemSet(Builder.CreateGEP(Dest, SrcSize), MemSet->getOperand(1), Builder.CreateMemSet(
MemsetLen, Align); Builder.CreateGEP(Dest->getType()->getPointerElementType(), Dest,
SrcSize),
MemSet->getOperand(1), MemsetLen, Align);
MD->removeInstruction(MemSet); MD->removeInstruction(MemSet);
MemSet->eraseFromParent(); MemSet->eraseFromParent();

View File

@ -426,8 +426,8 @@ NaryReassociatePass::tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
RHS = Builder.CreateMul( RHS = Builder.CreateMul(
RHS, ConstantInt::get(IntPtrTy, IndexedSize / ElementSize)); RHS, ConstantInt::get(IntPtrTy, IndexedSize / ElementSize));
} }
GetElementPtrInst *NewGEP = GetElementPtrInst *NewGEP = cast<GetElementPtrInst>(
cast<GetElementPtrInst>(Builder.CreateGEP(Candidate, RHS)); Builder.CreateGEP(GEP->getResultElementType(), Candidate, RHS));
NewGEP->setIsInBounds(GEP->isInBounds()); NewGEP->setIsInBounds(GEP->isInBounds());
NewGEP->takeName(GEP); NewGEP->takeName(GEP);
return NewGEP; return NewGEP;

View File

@ -1371,8 +1371,8 @@ static Value *buildGEP(IRBuilderTy &IRB, Value *BasePtr,
if (Indices.size() == 1 && cast<ConstantInt>(Indices.back())->isZero()) if (Indices.size() == 1 && cast<ConstantInt>(Indices.back())->isZero())
return BasePtr; return BasePtr;
return IRB.CreateInBoundsGEP(nullptr, BasePtr, Indices, return IRB.CreateInBoundsGEP(BasePtr->getType()->getPointerElementType(),
NamePrefix + "sroa_idx"); BasePtr, Indices, NamePrefix + "sroa_idx");
} }
/// Get a natural GEP off of the BasePtr walking through Ty toward /// Get a natural GEP off of the BasePtr walking through Ty toward
@ -3298,7 +3298,7 @@ private:
assert(Ty->isSingleValueType()); assert(Ty->isSingleValueType());
// Load the single value and insert it using the indices. // Load the single value and insert it using the indices.
Value *GEP = Value *GEP =
IRB.CreateInBoundsGEP(nullptr, Ptr, GEPIndices, Name + ".gep"); IRB.CreateInBoundsGEP(BaseTy, Ptr, GEPIndices, Name + ".gep");
LoadInst *Load = IRB.CreateAlignedLoad(Ty, GEP, Align, Name + ".load"); LoadInst *Load = IRB.CreateAlignedLoad(Ty, GEP, Align, Name + ".load");
if (AATags) if (AATags)
Load->setAAMetadata(AATags); Load->setAAMetadata(AATags);
@ -3343,7 +3343,7 @@ private:
Value *ExtractValue = Value *ExtractValue =
IRB.CreateExtractValue(Agg, Indices, Name + ".extract"); IRB.CreateExtractValue(Agg, Indices, Name + ".extract");
Value *InBoundsGEP = Value *InBoundsGEP =
IRB.CreateInBoundsGEP(nullptr, Ptr, GEPIndices, Name + ".gep"); IRB.CreateInBoundsGEP(BaseTy, Ptr, GEPIndices, Name + ".gep");
StoreInst *Store = StoreInst *Store =
IRB.CreateAlignedStore(ExtractValue, InBoundsGEP, Align); IRB.CreateAlignedStore(ExtractValue, InBoundsGEP, Align);
if (AATags) if (AATags)

View File

@ -245,14 +245,13 @@ Value *Scatterer::operator[](unsigned I) {
return CV[I]; return CV[I];
IRBuilder<> Builder(BB, BBI); IRBuilder<> Builder(BB, BBI);
if (PtrTy) { if (PtrTy) {
Type *ElTy = PtrTy->getElementType()->getVectorElementType();
if (!CV[0]) { if (!CV[0]) {
Type *Ty = Type *NewPtrTy = PointerType::get(ElTy, PtrTy->getAddressSpace());
PointerType::get(PtrTy->getElementType()->getVectorElementType(), CV[0] = Builder.CreateBitCast(V, NewPtrTy, V->getName() + ".i0");
PtrTy->getAddressSpace());
CV[0] = Builder.CreateBitCast(V, Ty, V->getName() + ".i0");
} }
if (I != 0) if (I != 0)
CV[I] = Builder.CreateConstGEP1_32(nullptr, CV[0], I, CV[I] = Builder.CreateConstGEP1_32(ElTy, CV[0], I,
V->getName() + ".i" + Twine(I)); V->getName() + ".i" + Twine(I));
} else { } else {
// Search through a chain of InsertElementInsts looking for element I. // Search through a chain of InsertElementInsts looking for element I.

View File

@ -682,9 +682,13 @@ void StraightLineStrengthReduce::rewriteCandidateWithBasis(
// Canonicalize bump to pointer size. // Canonicalize bump to pointer size.
Bump = Builder.CreateSExtOrTrunc(Bump, IntPtrTy); Bump = Builder.CreateSExtOrTrunc(Bump, IntPtrTy);
if (InBounds) if (InBounds)
Reduced = Builder.CreateInBoundsGEP(nullptr, Basis.Ins, Bump); Reduced = Builder.CreateInBoundsGEP(
cast<GetElementPtrInst>(Basis.Ins)->getResultElementType(),
Basis.Ins, Bump);
else else
Reduced = Builder.CreateGEP(nullptr, Basis.Ins, Bump); Reduced = Builder.CreateGEP(
cast<GetElementPtrInst>(Basis.Ins)->getResultElementType(),
Basis.Ins, Bump);
} }
break; break;
} }

View File

@ -343,18 +343,18 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
// into a pointer to its first member. // into a pointer to its first member.
// FIXME: This could be extended to support arrays as well. // FIXME: This could be extended to support arrays as well.
if (StructType *STy = dyn_cast<StructType>(NewTy)) { if (StructType *STy = dyn_cast<StructType>(NewTy)) {
NewTy = STy->getTypeAtIndex(0U);
IntegerType *IdxTy = IntegerType::get(NewTy->getContext(), 32); IntegerType *IdxTy = IntegerType::get(NewTy->getContext(), 32);
Constant *IdxZero = ConstantInt::get(IdxTy, 0, false); Constant *IdxZero = ConstantInt::get(IdxTy, 0, false);
Constant * const IdxList[] = {IdxZero, IdxZero}; Constant * const IdxList[] = {IdxZero, IdxZero};
Ptr = ConstantExpr::getGetElementPtr(nullptr, Ptr, IdxList); Ptr = ConstantExpr::getGetElementPtr(NewTy, Ptr, IdxList);
if (auto *FoldedPtr = ConstantFoldConstant(Ptr, DL, TLI)) if (auto *FoldedPtr = ConstantFoldConstant(Ptr, DL, TLI))
Ptr = FoldedPtr; Ptr = FoldedPtr;
NewTy = STy->getTypeAtIndex(0U);
// If we can't improve the situation by introspecting NewTy, // If we can't improve the situation by introspecting NewTy,
// we have to give up. // we have to give up.
} else { } else {
LLVM_DEBUG(dbgs() << "Failed to bitcast constant ptr, can not " LLVM_DEBUG(dbgs() << "Failed to bitcast constant ptr, can not "
"evaluate.\n"); "evaluate.\n");

View File

@ -332,9 +332,10 @@ static void createMemMoveLoop(Instruction *InsertBefore,
Value *IndexPtr = LoopBuilder.CreateSub( Value *IndexPtr = LoopBuilder.CreateSub(
LoopPhi, ConstantInt::get(TypeOfCopyLen, 1), "index_ptr"); LoopPhi, ConstantInt::get(TypeOfCopyLen, 1), "index_ptr");
Value *Element = LoopBuilder.CreateLoad( Value *Element = LoopBuilder.CreateLoad(
EltTy, LoopBuilder.CreateInBoundsGEP(SrcAddr, IndexPtr), "element"); EltTy, LoopBuilder.CreateInBoundsGEP(EltTy, SrcAddr, IndexPtr),
LoopBuilder.CreateStore(Element, "element");
LoopBuilder.CreateInBoundsGEP(DstAddr, IndexPtr)); LoopBuilder.CreateStore(
Element, LoopBuilder.CreateInBoundsGEP(EltTy, DstAddr, IndexPtr));
LoopBuilder.CreateCondBr( LoopBuilder.CreateCondBr(
LoopBuilder.CreateICmpEQ(IndexPtr, ConstantInt::get(TypeOfCopyLen, 0)), LoopBuilder.CreateICmpEQ(IndexPtr, ConstantInt::get(TypeOfCopyLen, 0)),
ExitBB, LoopBB); ExitBB, LoopBB);
@ -349,9 +350,10 @@ static void createMemMoveLoop(Instruction *InsertBefore,
IRBuilder<> FwdLoopBuilder(FwdLoopBB); IRBuilder<> FwdLoopBuilder(FwdLoopBB);
PHINode *FwdCopyPhi = FwdLoopBuilder.CreatePHI(TypeOfCopyLen, 0, "index_ptr"); PHINode *FwdCopyPhi = FwdLoopBuilder.CreatePHI(TypeOfCopyLen, 0, "index_ptr");
Value *FwdElement = FwdLoopBuilder.CreateLoad( Value *FwdElement = FwdLoopBuilder.CreateLoad(
EltTy, FwdLoopBuilder.CreateInBoundsGEP(SrcAddr, FwdCopyPhi), "element"); EltTy, FwdLoopBuilder.CreateInBoundsGEP(EltTy, SrcAddr, FwdCopyPhi),
"element");
FwdLoopBuilder.CreateStore( FwdLoopBuilder.CreateStore(
FwdElement, FwdLoopBuilder.CreateInBoundsGEP(DstAddr, FwdCopyPhi)); FwdElement, FwdLoopBuilder.CreateInBoundsGEP(EltTy, DstAddr, FwdCopyPhi));
Value *FwdIndexPtr = FwdLoopBuilder.CreateAdd( Value *FwdIndexPtr = FwdLoopBuilder.CreateAdd(
FwdCopyPhi, ConstantInt::get(TypeOfCopyLen, 1), "index_increment"); FwdCopyPhi, ConstantInt::get(TypeOfCopyLen, 1), "index_increment");
FwdLoopBuilder.CreateCondBr(FwdLoopBuilder.CreateICmpEQ(FwdIndexPtr, CopyLen), FwdLoopBuilder.CreateCondBr(FwdLoopBuilder.CreateICmpEQ(FwdIndexPtr, CopyLen),

View File

@ -737,7 +737,8 @@ Value *LibCallSimplifier::optimizeStrStr(CallInst *CI, IRBuilder<> &B) {
// strstr("abcd", "bc") -> gep((char*)"abcd", 1) // strstr("abcd", "bc") -> gep((char*)"abcd", 1)
Value *Result = castToCStr(CI->getArgOperand(0), B); Value *Result = castToCStr(CI->getArgOperand(0), B);
Result = B.CreateConstInBoundsGEP1_64(Result, Offset, "strstr"); Result =
B.CreateConstInBoundsGEP1_64(B.getInt8Ty(), Result, Offset, "strstr");
return B.CreateBitCast(Result, CI->getType()); return B.CreateBitCast(Result, CI->getType());
} }

View File

@ -2058,7 +2058,7 @@ void InnerLoopVectorizer::vectorizeInterleaveGroup(Instruction *Instr,
// A[i] = b; // Member of index 0 // A[i] = b; // Member of index 0
// A[i+2] = c; // Member of index 2 (Current instruction) // A[i+2] = c; // Member of index 2 (Current instruction)
// Current pointer is pointed to A[i+2], adjust it to A[i]. // Current pointer is pointed to A[i+2], adjust it to A[i].
NewPtr = Builder.CreateGEP(NewPtr, Builder.getInt32(-Index)); NewPtr = Builder.CreateGEP(ScalarTy, NewPtr, Builder.getInt32(-Index));
if (InBounds) if (InBounds)
cast<GetElementPtrInst>(NewPtr)->setIsInBounds(true); cast<GetElementPtrInst>(NewPtr)->setIsInBounds(true);
@ -2246,16 +2246,16 @@ void InnerLoopVectorizer::vectorizeMemoryInstruction(Instruction *Instr,
// If the address is consecutive but reversed, then the // If the address is consecutive but reversed, then the
// wide store needs to start at the last vector element. // wide store needs to start at the last vector element.
PartPtr = cast<GetElementPtrInst>( PartPtr = cast<GetElementPtrInst>(
Builder.CreateGEP(Ptr, Builder.getInt32(-Part * VF))); Builder.CreateGEP(ScalarDataTy, Ptr, Builder.getInt32(-Part * VF)));
PartPtr->setIsInBounds(InBounds); PartPtr->setIsInBounds(InBounds);
PartPtr = cast<GetElementPtrInst>( PartPtr = cast<GetElementPtrInst>(
Builder.CreateGEP(PartPtr, Builder.getInt32(1 - VF))); Builder.CreateGEP(ScalarDataTy, PartPtr, Builder.getInt32(1 - VF)));
PartPtr->setIsInBounds(InBounds); PartPtr->setIsInBounds(InBounds);
if (isMaskRequired) // Reverse of a null all-one mask is a null mask. if (isMaskRequired) // Reverse of a null all-one mask is a null mask.
Mask[Part] = reverseVector(Mask[Part]); Mask[Part] = reverseVector(Mask[Part]);
} else { } else {
PartPtr = cast<GetElementPtrInst>( PartPtr = cast<GetElementPtrInst>(
Builder.CreateGEP(Ptr, Builder.getInt32(Part * VF))); Builder.CreateGEP(ScalarDataTy, Ptr, Builder.getInt32(Part * VF)));
PartPtr->setIsInBounds(InBounds); PartPtr->setIsInBounds(InBounds);
} }
@ -2673,7 +2673,7 @@ Value *InnerLoopVectorizer::emitTransformedIndex(
assert(isa<SCEVConstant>(Step) && assert(isa<SCEVConstant>(Step) &&
"Expected constant step for pointer induction"); "Expected constant step for pointer induction");
return B.CreateGEP( return B.CreateGEP(
nullptr, StartValue, StartValue->getType()->getPointerElementType(), StartValue,
CreateMul(Index, Exp.expandCodeFor(Step, Index->getType(), CreateMul(Index, Exp.expandCodeFor(Step, Index->getType(),
&*B.GetInsertPoint()))); &*B.GetInsertPoint())));
} }
@ -3943,9 +3943,11 @@ void InnerLoopVectorizer::widenInstruction(Instruction &I) {
// Create the new GEP. Note that this GEP may be a scalar if VF == 1, // Create the new GEP. Note that this GEP may be a scalar if VF == 1,
// but it should be a vector, otherwise. // but it should be a vector, otherwise.
auto *NewGEP = GEP->isInBounds() auto *NewGEP =
? Builder.CreateInBoundsGEP(Ptr, Indices) GEP->isInBounds()
: Builder.CreateGEP(Ptr, Indices); ? Builder.CreateInBoundsGEP(GEP->getSourceElementType(), Ptr,
Indices)
: Builder.CreateGEP(GEP->getSourceElementType(), Ptr, Indices);
assert((VF == 1 || NewGEP->getType()->isVectorTy()) && assert((VF == 1 || NewGEP->getType()->isVectorTy()) &&
"NewGEP is not a pointer vector"); "NewGEP is not a pointer vector");
VectorLoopValueMap.setVectorValue(&I, Part, NewGEP); VectorLoopValueMap.setVectorValue(&I, Part, NewGEP);

View File

@ -108,7 +108,7 @@ TEST_F(BasicAATest, AliasInstWithFullObjectOfImpreciseSize) {
Value *ArbitraryI32 = F->arg_begin(); Value *ArbitraryI32 = F->arg_begin();
AllocaInst *I8 = B.CreateAlloca(B.getInt8Ty(), B.getInt32(2)); AllocaInst *I8 = B.CreateAlloca(B.getInt8Ty(), B.getInt32(2));
auto *I8AtUncertainOffset = auto *I8AtUncertainOffset =
cast<GetElementPtrInst>(B.CreateGEP(I8, ArbitraryI32)); cast<GetElementPtrInst>(B.CreateGEP(B.getInt8Ty(), I8, ArbitraryI32));
BasicAAResult &BasicAA = setupAnalyses(); BasicAAResult &BasicAA = setupAnalyses();
ASSERT_EQ(BasicAA.alias( ASSERT_EQ(BasicAA.alias(

View File

@ -1227,7 +1227,7 @@ TEST_F(MemorySSATest, LifetimeMarkersAreClobbers) {
B.SetInsertPoint(Entry); B.SetInsertPoint(Entry);
Value *Foo = &*F->arg_begin(); Value *Foo = &*F->arg_begin();
Value *Bar = B.CreateGEP(Foo, B.getInt64(1), "bar"); Value *Bar = B.CreateGEP(B.getInt8Ty(), Foo, B.getInt64(1), "bar");
B.CreateStore(B.getInt8(0), Foo); B.CreateStore(B.getInt8(0), Foo);
B.CreateStore(B.getInt8(0), Bar); B.CreateStore(B.getInt8(0), Bar);

View File

@ -773,7 +773,8 @@ TEST_F(ScalarEvolutionsTest, SCEVZeroExtendExprNonIntegral) {
Phi->addIncoming(Add, L); Phi->addIncoming(Add, L);
Builder.SetInsertPoint(Post); Builder.SetInsertPoint(Post);
Value *GepBase = Builder.CreateGEP(Arg, ConstantInt::get(T_int64, 1)); Value *GepBase =
Builder.CreateGEP(T_int64, Arg, ConstantInt::get(T_int64, 1));
Instruction *Ret = Builder.CreateRetVoid(); Instruction *Ret = Builder.CreateRetVoid();
ScalarEvolution SE = buildSE(*F); ScalarEvolution SE = buildSE(*F);

View File

@ -647,7 +647,8 @@ TEST_F(ModuleWithFunctionTest, DropPoisonGeneratingFlags) {
{ {
Value *GEPBase = Constant::getNullValue(B.getInt8PtrTy()); Value *GEPBase = Constant::getNullValue(B.getInt8PtrTy());
auto *GI = cast<GetElementPtrInst>(B.CreateInBoundsGEP(GEPBase, {Arg0})); auto *GI = cast<GetElementPtrInst>(
B.CreateInBoundsGEP(B.getInt8Ty(), GEPBase, Arg0));
ASSERT_TRUE(GI->isInBounds()); ASSERT_TRUE(GI->isInBounds());
GI->dropPoisonGeneratingFlags(); GI->dropPoisonGeneratingFlags();
ASSERT_FALSE(GI->isInBounds()); ASSERT_FALSE(GI->isInBounds());