[PATCH] D26117: [Devirtualization] Decorate vfunction load with invariant.load

Piotr Padlewski via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 29 08:38:06 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL285497: [Devirtualization] Decorate vfunction load with invariant.load (authored by Prazek).

Changed prior to commit:
  https://reviews.llvm.org/D26117?vs=76303&id=76306#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26117

Files:
  cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
  cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp


Index: cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
===================================================================
--- cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
+++ cfe/trunk/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: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1623,7 +1623,22 @@
 
     llvm::Value *VFuncPtr =
         CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
-    VFunc = CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+    auto *VFuncLoad =
+        CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+
+    // Add !invariant.load md to virtual function load to indicate that
+    // function didn't change inside vtable.
+    // It's safe to add it without -fstrict-vtable-pointers, but it would not
+    // help in devirtualization because it will only matter if we will have 2
+    // the same virtual function loads from the same vtable load, which won't
+    // happen without enabled devirtualization with -fstrict-vtable-pointers.
+    if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+        CGM.getCodeGenOpts().StrictVTablePointers)
+      VFuncLoad->setMetadata(
+          llvm::LLVMContext::MD_invariant_load,
+          llvm::MDNode::get(CGM.getLLVMContext(),
+                            llvm::ArrayRef<llvm::Metadata *>()));
+    VFunc = VFuncLoad;
   }
 
   CGCallee Callee(MethodDecl, VFunc);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26117.76306.patch
Type: text/x-patch
Size: 2299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161029/37efde90/attachment-0001.bin>


More information about the cfe-commits mailing list