[PATCH] D26117: [Devirtualization] Decorate vfunction load with invariant.load
Piotr Padlewski via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 29 07:18:46 PDT 2016
Prazek created this revision.
Prazek added reviewers: rsmith, rengolin.
Prazek added subscribers: cfe-commits, rjmccall, nlewycky.
This patch was introduced one year ago, but because my google account
was disabled, I didn't get email with failing buildbot and I missed
revert of this commit. There was small but in test regex.
I am back.
https://reviews.llvm.org/D26117
Files:
lib/CodeGen/ItaniumCXXABI.cpp
test/CodeGenCXX/virtual-function-calls.cpp
Index: test/CodeGenCXX/virtual-function-calls.cpp
===================================================================
--- test/CodeGenCXX/virtual-function-calls.cpp
+++ test/CodeGenCXX/virtual-function-calls.cpp
@@ -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 @@
[[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 {{.*}} !invariant.load ![[EMPTY_NODE:[0-9]+]]
}
}
+
+// CHECK-INVARIANT: ![[EMPTY_NODE]] = !{}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1618,7 +1618,16 @@
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;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26117.76301.patch
Type: text/x-patch
Size: 1885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161029/80ac2fbe/attachment.bin>
More information about the cfe-commits
mailing list