New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize C++ spaceship comparison #49210
Comments
assigned to @rotateright |
Can you please post relevant standalone snippets here, as links to godbolt? |
#include bool test1(int x, int y){return (x<=>y)<0;} bool test2(int x){return (x<=>1)<0;} bool test3(int x){return (x<=>0)>0;} bool test4(int x){return (x<=>0)<0;} define dso_local zeroext i1 @_Z5test1ii(i32 %0, i32 %1) local_unnamed_addr #0 { define dso_local zeroext i1 @_Z5test2i(i32 %0) local_unnamed_addr #0 { define dso_local zeroext i1 @_Z5test3i(i32 %0) local_unnamed_addr #0 { define dso_local zeroext i1 @_Z5test4i(i32 %0) local_unnamed_addr #0 { |
define i1 @src(i32 %0) { https://alive2.llvm.org/ce/z/jAqWw4 We somehow miss this transformation for SLT, |
Looks like we're just missing a basic icmp fold for a truncated value: I'll post a patch. |
This should get the example in the description: If there are other examples, please reopen or file more bugs. Thanks! |
Extended Description
Similar to gcc's https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94589 , it would be nice to optimize (x<=>y)@0 to x@y for all comparisons @, and clang/llvm seems to manage for some but not all.
#include
int n(int x){return (x<=>0)<0;}
Debian clang version 13.0.0-++20210129063721+010b176cdefb-1~exp1
x86_64-pc-linux-gnu
The text was updated successfully, but these errors were encountered: