-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[InstCombine] Missed optimization: fold other_cond && (a s> -1) && a s< b
to other_cond && a u< b
when b
is a specific constant
#76623
Comments
It would be fixed by #76621 if we know that |
For cases with a bitwise outer operation, this is handled by
|
I think this issue can be handled easier. Note that: |
I will try to file a simple solution for it. Though I also have one much complex patch. |
…6823) Fixes #76623 Alive2 proof: https://alive2.llvm.org/ce/z/gX6znJ (I'm not sure how to write a proof for such transform, maybe there are mistakes) In most cases, `icmp(a, C1) && (other_cond && icmp(a, C2))` will be reduced to `icmp(a, C1) & (other_cond && icmp(a, C2))`, since latter icmp always implies the poison of the former. After reduction, it's easier to simplify the icmp chain. Similarly, this patch does the same thing for `(A && B) && C --> A && (B & C)`. Maybe we could constraint such reduction only on icmps if there is regression in benchmarks.
Alive2 proof: https://alive2.llvm.org/ce/z/DT9eDZ
Motivating example:
can be folded to:
However, it folds if we replace the logical
and
with a bitwiseand
. I thought that Reassociate should be to blame, but godbolt told me that similar fold for bitwiseand
is handled by InstCombine. Therefore, I tag InstCombine here.Real-world motivation
This snippet of IR is derived from qemu/net/util.c@net_parse_macaddr (after O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, see also:https://godbolt.org/z/Ea8GGxKba
Let me know if you can confirm that it's an optimization opportunity, thanks.
The text was updated successfully, but these errors were encountered: