Open XChy opened 8 months ago
For reference, GCC does optimize it as expected: https://godbolt.org/z/zEc9T14cf
Hm, I feel like I've seen a patch for something like this before. Maybe lost somewhere on phabricator...
This looks very related to the issue that https://github.com/llvm/llvm-project/pull/114262 addressed. This case is slightly different because the default branch doesn't go to a dedicated block, it goes directly to the phi. cc @michaelmaitland
Alive2 proof: https://alive2.llvm.org/ce/z/8U-LhB
Motivating example
switch(13)
andswitch(0)
produce the same%ret
as default case:Real-world motivation
This snippet of IR is derived from openssl/crypto/bio/bss_conn.c@conn_ctrl (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/nndaqfM9e
Let me know if you can confirm that it's an optimization opportunity, thanks.