r300454 - [ObjC] Mark loads from __NSArray0 and __NSDictionary0 as invariant.load.
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 17 08:21:55 PDT 2017
Author: ahatanak
Date: Mon Apr 17 10:21:55 2017
New Revision: 300454
URL: http://llvm.org/viewvc/llvm-project?rev=300454&view=rev
Log:
[ObjC] Mark loads from __NSArray0 and __NSDictionary0 as invariant.load.
Also, simplify code by calling MakeNaturalAlignAddrLValue.
This is a follow-up to r300396.
Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/test/CodeGenObjC/empty-collection-literals.m
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=300454&r1=300453&r2=300454&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Mon Apr 17 10:21:55 2017
@@ -126,10 +126,12 @@ llvm::Value *CodeGenFunction::EmitObjCCo
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.
Modified: cfe/trunk/test/CodeGenObjC/empty-collection-literals.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/empty-collection-literals.m?rev=300454&r1=300453&r2=300454&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/empty-collection-literals.m (original)
+++ cfe/trunk/test/CodeGenObjC/empty-collection-literals.m Mon Apr 17 10:21:55 2017
@@ -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
More information about the cfe-commits
mailing list