-
Notifications
You must be signed in to change notification settings - Fork 13.6k
switch
not recognized as equivalent to sext
#54561
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I had to use different types because of integer promotion in C++, but here's a clang repro too: long long square(int num) {
switch (num) {
case -1: return -1;
case 0: return 0;
case +1: return +1;
default: __builtin_unreachable();
}
} https://clang.godbolt.org/z/57jqWxbxe square(int): # @square(int)
lea eax, [rdi + 1]
dec rax
ret |
I think we can extend
|
IMHO only extending Is it a nice approach to transform the IR into something like this containing PHI node, and let existing optimization passes to make further optimizations? |
@hkmatsumoto SROA will convert the load/stores into a phi node. |
Oh, I'm convinced. Let me see if I can make a patch for this. |
Opt transformation showing suboptimal current result on trunk: https://llvm.godbolt.org/z/jj6vcv5q3
Alive2 demonstration that the proposed transformation is correct: https://alive2.llvm.org/ce/z/hAAoh_
Original motivating example in rust-lang/rust#95313: https://rust.godbolt.org/z/dvYe9r78c
The following code:
Optimizes to this slightly suboptimal IR:
But as Alive confirms, it could just be a
sext
:The text was updated successfully, but these errors were encountered: