<html>
<head>
<base href="https://bugs.llvm.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 - Missed fold for if-else chain"
href="https://bugs.llvm.org/show_bug.cgi?id=51323">51323</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed fold for if-else chain
</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>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm@rifkin.dev
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>LLVM identifier conv2 is a nop but not conv1 <a href="https://godbolt.org/z/q3Eq34EY6">https://godbolt.org/z/q3Eq34EY6</a>
int conv1(std::strong_ordering s){
if(s==std::strong_ordering::less) return -1;
if(s==std::strong_ordering::equal) return 0;
if(s==std::strong_ordering::greater) return 1;
__builtin_unreachable();
}
std::strong_ordering conv2(int i){
switch(i){
case -1: return std::strong_ordering::less;
case 0: return std::strong_ordering::equal;
case 1: return std::strong_ordering::greater;
default: __builtin_unreachable();
}
}
It's valid to optimize down to a nop here <a href="https://alive2.llvm.org/ce/z/HcSsp0">https://alive2.llvm.org/ce/z/HcSsp0</a>.
Problem appears to be related to switch <-> if-chain conversion. If conv2 is
converted to an if-chain LLVM no longer identifies it as a nop.
I submitted a related bug report last week
<a class="bz_bug_link
bz_status_NEW "
title="NEW - LLVM optimization and code generation for if-else chains vs ternary chains vs a switch"
href="show_bug.cgi?id=51285">https://bugs.llvm.org/show_bug.cgi?id=51285</a>, though in this case LLVM does
correctly do a switch <-> if-chain conversion as is able to make further
optimizations because of it.
This is related to a GCC bug:
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94566">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94566</a>.</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>