r248982 - Decorating virtual functions load with invariant.load
Piotr Padlewski via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 30 20:50:42 PDT 2015
Author: prazek
Date: Wed Sep 30 22:50:41 2015
New Revision: 248982
URL: http://llvm.org/viewvc/llvm-project?rev=248982&view=rev
Log:
Decorating virtual functions load with invariant.load
http://reviews.llvm.org/D13279
Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=248982&r1=248981&r2=248982&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed Sep 30 22:50:41 2015
@@ -1609,7 +1609,16 @@ llvm::Value *ItaniumCXXABI::getVirtualFu
uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD);
llvm::Value *VFuncPtr =
CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
- return CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+ auto *Inst = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+ // It's safe to add "invariant.load" without -fstrict-vtable-pointers, but it
+ // would not help in devirtualization.
+ if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+ CGM.getCodeGenOpts().StrictVTablePointers)
+ Inst->setMetadata(llvm::LLVMContext::MD_invariant_load,
+ llvm::MDNode::get(CGM.getLLVMContext(),
+ llvm::ArrayRef<llvm::Metadata *>()));
+ return Inst;
}
llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(
Modified: cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp?rev=248982&r1=248981&r2=248982&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp Wed Sep 30 22:50:41 2015
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -emit-llvm -o - -fstrict-vtable-pointers -O1 | FileCheck --check-prefix=CHECK-INVARIANT %s
// PR5021
namespace PR5021 {
@@ -42,10 +43,14 @@ namespace VirtualNoreturn {
[[noreturn]] virtual void f();
};
- // CHECK: @_ZN15VirtualNoreturn1f
+ // CHECK-LABEL: @_ZN15VirtualNoreturn1f
+ // CHECK-INVARIANT-LABEL: define void @_ZN15VirtualNoreturn1f
void f(A *p) {
p->f();
// CHECK: call {{.*}}void %{{[^#]*$}}
// CHECK-NOT: unreachable
+ // CHECK-INVARIANT: load {{.*}} align 8, !invariant.load ![[EMPTY_NODE:[0-9]]]
}
}
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
More information about the cfe-commits
mailing list