<html>
<head>
<base href="https://bugs.freedesktop.org/" />
</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 - Merge similar if-statements"
href="https://bugs.freedesktop.org/show_bug.cgi?id=94744">94744</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Merge similar if-statements
</td>
</tr>
<tr>
<th>Product</th>
<td>Mesa
</td>
</tr>
<tr>
<th>Version</th>
<td>git
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>medium
</td>
</tr>
<tr>
<th>Component</th>
<td>glsl-compiler
</td>
</tr>
<tr>
<th>Assignee</th>
<td>idr@freedesktop.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>idr@freedesktop.org
</td>
</tr>
<tr>
<th>QA Contact</th>
<td>intel-3d-bugs@lists.freedesktop.org
</td>
</tr></table>
<p>
<div>
<pre>I recently encountered some generated NIR like:
vec1 ssa_0 = load_const (0x00000000 /* 0.000000 */)
...
/* succs: block_3 block_4 */
if ssa_122 {
block block_3:
/* preds: block_2 */
/* succs: block_5 */
} else {
block block_4:
/* preds: block_2 */
vec1 ssa_139 = fmul ssa_138, ssa_1
/* succs: block_5 */
}
block block_5:
/* preds: block_3 block_4 */
vec1 ssa_140 = phi block_3: ssa_0, block_4: ssa_139
vec1 ssa_141 = fadd ssa_17, ssa_140
/* succs: block_6 block_7 */
if ssa_122 {
block block_6:
/* preds: block_5 */
vec1 ssa_142 = fmul ssa_138, ssa_1
/* succs: block_8 */
} else {
block block_7:
/* preds: block_5 */
/* succs: block_8 */
}
block block_8:
/* preds: block_6 block_7 */
vec1 ssa_143 = phi block_6: ssa_142, block_7: ssa_0
The i965 backend generates the obvious, terrible code for this. There are two
levels of optimization that could occur on just the NIR. First, merge the two
if-statements.
/* succs: block_3 block_4 */
if ssa_122 {
block block_3:
/* preds: block_2 */
vec1 ssa_142 = fmul ssa_138, ssa_1
/* succs: block_5 */
} else {
block block_4:
/* preds: block_2 */
vec1 ssa_139 = fmul ssa_138, ssa_1
/* succs: block_5 */
}
block block_5:
/* preds: block_3 block_4 */
vec1 ssa_140 = phi block_3: ssa_0, block_4: ssa_139
vec1 ssa_143 = phi block_6: ssa_142, block_7: ssa_0
vec1 ssa_141 = fadd ssa_17, ssa_140
Second, notice that the calculations in both branches is the same, and pull it
out.
vec1 ssa_999 = fmul ssa_138, ssa_1
/* succs: block_3 block_4 */
if ssa_122 {
block block_3:
/* preds: block_2 */
/* succs: block_5 */
} else {
block block_4:
/* preds: block_2 */
/* succs: block_5 */
}
block block_5:
/* preds: block_3 block_4 */
vec1 ssa_140 = phi block_3: ssa_0, block_4: ssa_999
vec1 ssa_143 = phi block_6: ssa_999, block_7: ssa_0
vec1 ssa_141 = fadd ssa_17, ssa_140
Existing optimization passes should turn this into a pair of bcsel
instructions.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the QA Contact for the bug.</li>
</ul>
</body>
</html>