This is an archive of the discontinued LLVM Phabricator instance.

Vtable aliasing improvement: makes obj->vtable noalias obj and modref(obj->virt_call, obj->vtable) = REF
AbandonedPublic

Authored by andrew.zhogin on Jul 29 2015, 12:46 PM.

Details

Summary

This patch contains two improvements for basicaa alias analysis:

  • Knowledge that object pointer can't be aliased with vtable loaded from this object (obj->vtable noalias obj).
  • Knowledge that virtual call to object can't change this object's vtable. modrefinfo(obj->virt_call, obj->vtable) = REF; modrefinfo(obj->virt_call, obj->vtable->fn) = REF;

Vtable is identified by TBAA metadata (isTBAAVtableAccess - already existing function).

Combined with this patch (http://reviews.llvm.org/D11547) it makes very simple in-loop devirtualization works. This bug's example is fixed: https://llvm.org/bugs/show_bug.cgi?id=20801

But just a bit more complex samples require AliasSetTracker's merge sets problem to be fixed.
"alias set collapse and LICM": https://groups.google.com/forum/#!topic/llvm-dev/Qy66vhi5NaY

Diff Detail

Event Timeline

andrew.zhogin retitled this revision from to Vtable aliasing improvement: makes obj->vtable noalias obj and modref(obj->virt_call, obj->vtable) = REF.
andrew.zhogin updated this object.
andrew.zhogin added reviewers: hfinkel, reames, sanjoy.
andrew.zhogin added a subscriber: llvm-commits.
rsmith requested changes to this revision.Aug 5 2015, 2:05 PM
rsmith added a reviewer: rsmith.
rsmith added a subscriber: rsmith.

Your assumption that the vptr for an object cannot change during a virtual call to that object is not correct; the rules here are more subtle. See the recent "Clang devirtualization proposal" thread on llvm-dev / cfe-dev for an approach that handles the cases where the vptr actually cannot change; Piotr Padlewski is currently working on implementing that approach.

lib/Analysis/BasicAliasAnalysis.cpp
1462–1464

This is redundant in many cases (we can already deduce this if the load from the object has TBAA metadata, or if we can see the pointers are distinct), and wrong in other cases (for instance, using memcpy to write over the storage for an object that had a vptr).

This revision now requires changes to proceed.Aug 5 2015, 2:05 PM
andrew.zhogin abandoned this revision.Mar 30 2016, 12:01 PM