<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - -fstrict-vtable-pointers does not seem to optimise vtable access as much as I would expect."
href="https://llvm.org/bugs/show_bug.cgi?id=28724">28724</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-fstrict-vtable-pointers does not seem to optimise vtable access as much as I would expect.
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>2.6
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>oliver@apple.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=16811" name="attach_16811" title="example code">attachment 16811</a> <a href="attachment.cgi?id=16811&action=edit" title="example code">[details]</a></span>
example code
If I take the attached example and compile with:
clang++ -Os -std=c++11 -fstrict-vtable-pointers example.cpp -emit-llvm -S -o -
The output for the main for-loop is
for.body: ; preds = %for.body, %entry
%i.07 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%vtable = load void (%class.Bar*)**, void (%class.Bar*)*** %0, align 8,
!invariant.group !8
%1 = load void (%class.Bar*)*, void (%class.Bar*)** %vtable, align 8
tail call void %1(%class.Bar* nonnull %call)
%vfn2 = getelementptr inbounds void (%class.Bar*)*, void (%class.Bar*)**
%vtable, i64 1
%2 = load void (%class.Bar*)*, void (%class.Bar*)** %vfn2, align 8
tail call void %2(%class.Bar* nonnull %call)
%inc = add nuw nsw i32 %i.07, 1
%exitcond = icmp eq i32 %inc, 100
br i1 %exitcond, label %for.cond.cleanup, label %for.body
}
My interpretation of the -fstrict-vtable-pointers flag is that we're deciding
that the an object's vtable pointer cannot be mutated. If that is the case then
in the above IR %vtable should be a loop invariant as %0 is also invariant.
That means the assignment to %vtable should be hoistable via LICM.
Once %vtable is hoisted, then %1 and %2 should also be hoisted, as vtables are
constant under my understanding of -fstrict-vtable-pointers.
So I think we should be able to produce IR that looks something like:
%vtable = load void (%class.Bar*)**, void (%class.Bar*)*** %0, align 8,
!invariant.group !8
%1 = load void (%class.Bar*)*, void (%class.Bar*)** %vtable, align 8
%vfn2 = getelementptr inbounds void (%class.Bar*)*, void (%class.Bar*)**
%vtable, i64 1
%2 = load void (%class.Bar*)*, void (%class.Bar*)** %vfn2, align 8
for.body: ; preds = %for.body, %entry
%i.07 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
tail call void %1(%class.Bar* nonnull %call)
tail call void %2(%class.Bar* nonnull %call)
%inc = add nuw nsw i32 %i.07, 1
%exitcond = icmp eq i32 %inc, 100
br i1 %exitcond, label %for.cond.cleanup, label %for.body
}
This IR is a rough approximation via the wonders of cut/paste, so be gentle
with errors :D
I'm unsure how common code would benefit, but this does go against my intuition
of expected behaviour.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>