-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Remove common add
s when icmp eq
ing two select
s [InstCombine]
#134024
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
Comments
Hmm, I tried fixing this on the rust side (for how we emit enum discriminants, rust-lang/rust#139729), but it looks like the "move inside the select" part runs before the "it's an add on both sides of So that might be a good thing to fix too? |
Yeah. It is the canonical form. llvm-project/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp Lines 863 to 864 in 3ed8363
|
Take the following IR, extracted from part of how Rust generates
==
on enums:Today, when optimizing
get_discr
InstCombine will change the https://llvm.godbolt.org/z/6Eq87h6h7to
which is reasonable on its own.
The problem, though, is that that makes things worse later in
discr_eq
.It's unable to undo that transformation after the inlining, and thus ends up as https://llvm.godbolt.org/z/31MdEhfcv
But there's no reason to do those
add
s any more -- they could be pulled outside theselect
s where they'd cancel out.Phrased as C, it's doing
when instead it could be doing
So InstCombine should be able to detect this case, and rewrite it back to
Alive2 proof of correctness for that: https://alive2.llvm.org/ce/z/AWCmDs
The text was updated successfully, but these errors were encountered: