[ObjC] Mark loads from __NSArray0 and __NSDictionary0 as invariant.load.

Also, simplify code by calling MakeNaturalAlignAddrLValue.

This is a follow-up to r300396.

llvm-svn: 300454
This commit is contained in:
Akira Hatanaka
2017-04-17 15:21:55 +00:00
parent 7205f3c2e4
commit b5d1ea44af
2 changed files with 7 additions and 5 deletions

View File

@@ -126,10 +126,12 @@ llvm::Value *CodeGenFunction::EmitObjCCollectionLiteral(const Expr *E,
QualType IdTy(CGM.getContext().getObjCIdType());
llvm::Constant *Constant =
CGM.CreateRuntimeVariable(ConvertType(IdTy), ConstantName);
Address Addr(Constant, Context.getTypeAlignInChars(IdTy));
LValue LV = MakeAddrLValue(Addr, IdTy);
return Builder.CreateBitCast(EmitLoadOfScalar(LV, E->getLocStart()),
ConvertType(E->getType()));
LValue LV = MakeNaturalAlignAddrLValue(Constant, IdTy);
llvm::Value *Ptr = EmitLoadOfScalar(LV, E->getLocStart());
cast<llvm::LoadInst>(Ptr)->setMetadata(
CGM.getModule().getMDKindID("invariant.load"),
llvm::MDNode::get(getLLVMContext(), None));
return Builder.CreateBitCast(Ptr, ConvertType(E->getType()));
}
// Compute the type of the array we're initializing.

View File

@@ -41,7 +41,7 @@ void test_empty_dictionary() {
// CHECK-WITH-EMPTY-COLLECTIONS-LABEL: define void @test_empty_dictionary
// CHECK-WITH-EMPTY-COLLECTIONS-NOT: ret void
// CHECK-WITH-EMPTY-COLLECTIONS: load {{.*}} @__NSDictionary0__
// CHECK-WITH-EMPTY-COLLECTIONS: load {{.*}} @__NSDictionary0__{{.*}}!invariant.load
// CHECK-WITH-EMPTY-COLLECTIONS-NOT: ret void
// CHECK-WITH-EMPTY-COLLECTIONS: {{call.*objc_retain\(}}
// CHECK-WITH-EMPTY-COLLECTIONS-NOT: ret void