// sizeof(int64).
//
// Emit an uglygep in this case.
- Type *I8PtrTy = Type::getInt8PtrTy(GEP->getContext(),
- GEP->getPointerAddressSpace());
- NewGEP = new BitCastInst(NewGEP, I8PtrTy, "", GEP);
- NewGEP = GetElementPtrInst::Create(
- Type::getInt8Ty(GEP->getContext()), NewGEP,
- ConstantInt::get(IntPtrTy, AccumulativeByteOffset, true), "uglygep",
- GEP);
+ IRBuilder<> Builder(GEP);
+ Type *I8PtrTy =
+ Builder.getInt8Ty()->getPointerTo(GEP->getPointerAddressSpace());
+
+ NewGEP = cast<Instruction>(Builder.CreateGEP(
+ Builder.getInt8Ty(), Builder.CreateBitCast(NewGEP, I8PtrTy),
+ {ConstantInt::get(IntPtrTy, AccumulativeByteOffset, true)}, "uglygep",
+ GEPWasInBounds));
+
NewGEP->copyMetadata(*GEP);
- // Inherit the inbounds attribute of the original GEP.
- cast<GetElementPtrInst>(NewGEP)->setIsInBounds(GEPWasInBounds);
- if (GEP->getType() != I8PtrTy)
- NewGEP = new BitCastInst(NewGEP, GEP->getType(), GEP->getName(), GEP);
+ NewGEP = cast<Instruction>(Builder.CreateBitCast(NewGEP, GEP->getType()));
}
GEP->replaceAllUsesWith(NewGEP);
; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[I:%.*]] to i64
; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[J:%.*]] to i64
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr [1024 x %struct.Packed], ptr addrspace(3) @packed_struct_array, i64 0, i64 [[TMP0]], i32 1, i64 [[TMP1]]
-; CHECK-NEXT: [[TMP3:%.*]] = bitcast ptr addrspace(3) [[TMP2]] to ptr addrspace(3)
-; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr inbounds i8, ptr addrspace(3) [[TMP3]], i64 100
+; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr inbounds i8, ptr addrspace(3) [[TMP2]], i64 100
; CHECK-NEXT: ret ptr addrspace(3) [[UGLYGEP]]
;
entry: