<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 --- - cost models should allow something more than an instruction as an input"
href="https://llvm.org/bugs/show_bug.cgi?id=31274">31274</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>cost models should allow something more than an instruction as an input
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>Transformation Utilities
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>spatel+llvm@rotateright.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Filing a bug to keep track of a suggestion that has come up a few times
recently:
<a href="http://lists.llvm.org/pipermail/llvm-dev/2016-November/107489.html">http://lists.llvm.org/pipermail/llvm-dev/2016-November/107489.html</a>
<a href="http://lists.llvm.org/pipermail/llvm-dev/2016-November/106879.html">http://lists.llvm.org/pipermail/llvm-dev/2016-November/106879.html</a>
Here's a umax example to illustrate:
$ cat costmodel_patterns.ll
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"
define i32 @max(i32* nocapture readonly %x, i32 %N) #0 {
entry:
%cmp11 = icmp eq i32 %N, 0
br i1 %cmp11, label %for.cond.cleanup, label %for.body.preheader
for.body.preheader:
%wide.trip.count = zext i32 %N to i64
br label %for.body
for.cond.cleanup.loopexit:
br label %for.cond.cleanup
for.cond.cleanup:
%ret.0.lcssa = phi i32 [ 0, %entry ], [ %.ret.0, %for.cond.cleanup.loopexit ]
ret i32 %ret.0.lcssa
for.body:
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0,
%for.body.preheader ]
%ret.012 = phi i32 [ %.ret.0, %for.body ], [ 0, %for.body.preheader ]
%arrayidx = getelementptr inbounds i32, i32* %x, i64 %indvars.iv
%0 = load i32, i32* %arrayidx, align 4
%cmp1 = icmp ugt i32 %0, %ret.012
%.ret.0 = select i1 %cmp1, i32 %0, i32 %ret.012
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
%exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body
}
attributes #0 = { "target-features"="+avx" }
-----------------------------------------------------------------------------
This is IR for a target that has AVX, therefore, 'umax' is a single and simple
instruction with expected throughput of 1 inst / cycle:
$ ./opt -loop-vectorize costmodel_patterns.ll -S | ./llc -o - |grep max
...
vpmaxud %xmm4, %xmm1, %xmm1
...
The cost model interface, however, is limited to providing costs for individual
IR instructions. For example:
/// \returns The expected cost of compare and select instructions.
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy = nullptr) const;
That means we see something like this:
$ ./opt -cost-model -analyze costmodel_patterns.ll -S
Printing analysis 'Cost Model Analysis' for function 'max':
...
Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp ugt
i32 %0, %ret.012
Cost Model: Found an estimated cost of 1 for instruction: %.ret.0 = select i1
%cmp1, i32 %0, i32 %ret.012
...so we calculate a cost of '2' for a max idiom that should have a cost of '1'
(both in terms of machine instruction count and throughput).</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>