[llvm-bugs] [Bug 43198] New: LLVM should better understand subtraction of `zext i1`s
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Sep 2 15:29:29 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=43198
Bug ID: 43198
Summary: LLVM should better understand subtraction of `zext
i1`s
Product: new-bugs
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: me22.ca at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
I found this trying to make a better implementation of Rust's `Ord::cmp` for
integers.
C++ repro https://godbolt.org/z/tL0-oW
```
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,
https://godbolt.org/z/-hl5H0)
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190902/f88ba82f/attachment.html>
More information about the llvm-bugs
mailing list