<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 - LLVM should better understand subtraction of `zext i1`s"
href="https://bugs.llvm.org/show_bug.cgi?id=43198">43198</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LLVM should better understand subtraction of `zext i1`s
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</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>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>me22.ca@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>I found this trying to make a better implementation of Rust's `Ord::cmp` for
integers.
C++ repro <a href="https://godbolt.org/z/tL0-oW">https://godbolt.org/z/tL0-oW</a>
```
int spaceship(int a, int b) {
return (a > b) - (a < b);
}
bool my_lt(int a, int b) {
return spaceship(a, b) == -1;
}
```
`my_lt` there should be foldable down to just `a < b`, but that doesn't happen
```
define dso_local zeroext i1 @_Z5my_ltii(i32 %0, i32 %1) local_unnamed_addr #0 {
%3 = icmp sgt i32 %0, %1
%4 = zext i1 %3 to i32
%5 = icmp slt i32 %0, %1
%6 = zext i1 %5 to i32
%7 = sub nsw i32 %4, %6
%8 = icmp eq i32 %7, -1
ret i1 %8
}
```
(And running it through `opt` again doesn't help either,
<a href="https://godbolt.org/z/-hl5H0">https://godbolt.org/z/-hl5H0</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>