Use the inbounds variant of getelementptr for common pointer arithmetic.

llvm-svn: 78756
This commit is contained in:
Dan Gohman 2009-08-12 00:33:55 +00:00
parent 76733748e1
commit 43b4484f87
4 changed files with 8 additions and 8 deletions

View File

@ -889,7 +889,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
Idx = Builder.CreateUDiv(Idx, Idx = Builder.CreateUDiv(Idx,
llvm::ConstantInt::get(Idx->getType(), llvm::ConstantInt::get(Idx->getType(),
BaseTypeSize)); BaseTypeSize));
Address = Builder.CreateGEP(Base, Idx, "arrayidx"); Address = Builder.CreateInBoundsGEP(Base, Idx, "arrayidx");
} else if (const ObjCInterfaceType *OIT = } else if (const ObjCInterfaceType *OIT =
dyn_cast<ObjCInterfaceType>(E->getType())) { dyn_cast<ObjCInterfaceType>(E->getType())) {
llvm::Value *InterfaceSize = llvm::Value *InterfaceSize =
@ -899,11 +899,11 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
Idx = Builder.CreateMul(Idx, InterfaceSize); Idx = Builder.CreateMul(Idx, InterfaceSize);
llvm::Type *i8PTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::Type *i8PTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
Address = Builder.CreateGEP(Builder.CreateBitCast(Base, i8PTy), Address = Builder.CreateGEP(Builder.CreateBitCast(Base, i8PTy),
Idx, "arrayidx"); Idx, "arrayidx");
Address = Builder.CreateBitCast(Address, Base->getType()); Address = Builder.CreateBitCast(Address, Base->getType());
} else { } else {
Address = Builder.CreateGEP(Base, Idx, "arrayidx"); Address = Builder.CreateInBoundsGEP(Base, Idx, "arrayidx");
} }
QualType T = E->getBase()->getType()->getPointeeType(); QualType T = E->getBase()->getType()->getPointeeType();

View File

@ -724,7 +724,7 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
LV = LValue::MakeAddr(lhs, ValTy.getCVRQualifiers(), LV = LValue::MakeAddr(lhs, ValTy.getCVRQualifiers(),
CGF.getContext().getObjCGCAttrKind(ValTy)); CGF.getContext().getObjCGCAttrKind(ValTy));
} else } else
NextVal = Builder.CreateGEP(InVal, Inc, "ptrincdec"); NextVal = Builder.CreateInBoundsGEP(InVal, Inc, "ptrincdec");
} else { } else {
const llvm::Type *i8Ty = const llvm::Type *i8Ty =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
@ -1094,7 +1094,7 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) {
return Builder.CreateBitCast(Res, Ptr->getType()); return Builder.CreateBitCast(Res, Ptr->getType());
} }
return Builder.CreateGEP(Ptr, Idx, "add.ptr"); return Builder.CreateInBoundsGEP(Ptr, Idx, "add.ptr");
} }
Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) { Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) {
@ -1160,7 +1160,7 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) {
return Builder.CreateBitCast(Res, Ops.LHS->getType()); return Builder.CreateBitCast(Res, Ops.LHS->getType());
} }
return Builder.CreateGEP(Ops.LHS, Idx, "sub.ptr"); return Builder.CreateInBoundsGEP(Ops.LHS, Idx, "sub.ptr");
} else { } else {
// pointer - pointer // pointer - pointer
Value *LHS = Ops.LHS; Value *LHS = Ops.LHS;

View File

@ -1,6 +1,6 @@
// RUN: clang-cc -triple=x86_64-apple-darwin9 -emit-llvm %s -o %t && // RUN: clang-cc -triple=x86_64-apple-darwin9 -emit-llvm %s -o %t &&
// RUN: grep "call void @_ZN1AC1Ev" %t | count 1 && // RUN: grep "call void @_ZN1AC1Ev" %t | count 1 &&
// RUN: grep "call i32 @__cxa_atexit(void (i8\*)\* bitcast (void (%.truct.A\*)\* @_ZN1AD1Ev to void (i8\*)\*), i8\* getelementptr (%.truct.A\* @a, i32 0, i32 0), i8\* bitcast (i8\*\* @__dso_handle to i8\*))" %t | count 1 // RUN: grep "call i32 @__cxa_atexit(void (i8\*)\* bitcast (void (%.truct.A\*)\* @_ZN1AD1Ev to void (i8\*)\*), i8\* getelementptr inbounds (%.truct.A\* @a, i32 0, i32 0), i8\* bitcast (i8\*\* @__dso_handle to i8\*))" %t | count 1
struct A { struct A {
A(); A();

View File

@ -1,6 +1,6 @@
// RUN: clang-cc -triple=x86_64-apple-darwin9 -emit-llvm %s -o %t && // RUN: clang-cc -triple=x86_64-apple-darwin9 -emit-llvm %s -o %t &&
// RUN: grep "call void @_ZN1AC1Ev" %t | count 1 && // RUN: grep "call void @_ZN1AC1Ev" %t | count 1 &&
// RUN: grep "call i32 @__cxa_atexit(void (i8\*)\* bitcast (void (%.truct.A\*)\* @_ZN1AD1Ev to void (i8\*)\*), i8\* getelementptr (%.truct.A\* @_ZZ1fvE1a, i32 0, i32 0), i8\* bitcast (i8\*\* @__dso_handle to i8\*))" %t | count 1 // RUN: grep "call i32 @__cxa_atexit(void (i8\*)\* bitcast (void (%.truct.A\*)\* @_ZN1AD1Ev to void (i8\*)\*), i8\* getelementptr inbounds (%.truct.A\* @_ZZ1fvE1a, i32 0, i32 0), i8\* bitcast (i8\*\* @__dso_handle to i8\*))" %t | count 1
struct A { struct A {
A(); A();