r248982 - Decorating virtual functions load with invariant.load

Piotr Padlewski via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 1 11:13:12 PDT 2015


I added !invariant.load to virtual functions load, so when optimizer see
case like this

%vtable = load ...
%1 = load (...) %vtable, !invariant.load !0
call %1(...)
%2 = load (...) %vtable, !invariant.load !0
call %2(...)


can merge the 2 virtual functions load into one like this:

%vtable = load ...
%1 = load (...) %vtable, !invariant.load !0
call %1(...)
call %1(...)

This change requires -fstrict-vtable-pointers because without
!invariant.group optimizer will not merge vtable load into one load,
and because of it !invariant.load will be useless.



On Wed, Sep 30, 2015 at 9:28 PM, Chandler Carruth <chandlerc at gmail.com>
wrote:

> On Wed, Sep 30, 2015 at 8:52 PM Piotr Padlewski via cfe-commits <
> cfe-commits at lists.llvm.org> wrote:
>
>> 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
>>
>
> This change description really doesn't tell me anything about what this
> change does. Could you try to write more detailed and explanatory change
> logs?
>
> Imagine a reader that has little or no context reading the change log to
> gain the context necessary to read the actual patch and understand what is
> going on with it.
>
>
>>
>> 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]] = !{}
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151001/2bd7d6f3/attachment-0001.html>


More information about the cfe-commits mailing list