Skip to content

[InstCombine] Missed optimization: fold chained selects with exclusive condition but one identical arm #85833

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

Closed
XChy opened this issue Mar 19, 2024 · 4 comments

Comments

@XChy
Copy link
Member

XChy commented Mar 19, 2024

Alive2 proof: https://alive2.llvm.org/ce/z/ZkjFRM

Motivating example

define ptr @src(i32 %level, ptr %level.addr) local_unnamed_addr #0 {
entry:
  %c1 = icmp eq i32 %level, 0
  %c2 = icmp eq i32 %level, 1
  %s1 = select i1 %c1, ptr %level.addr, ptr null
  %s2 = select i1 %c2, ptr null, ptr %s1
  ret ptr %s2
}

can be folded to:

define ptr @tgt(i32 %level, ptr %level.addr) local_unnamed_addr #0 {
entry:
  %cond = icmp eq i32 %level, 0
  %s1 = select i1 %cond, ptr %level.addr, ptr null
  ret ptr %s1
}

Real-world motivation

This snippet of IR is derived from openssl/crypto/shlib/cmp_util.c@OSSL_CMP_print_to_bio (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/qrh916jj8

Let me know if you can confirm that it's an optimization opportunity, thanks.

@marcauberer
Copy link
Member

I would like to work on this

@marcauberer
Copy link
Member

This can be further generalized to: https://alive2.llvm.org/ce/z/pnK3jW

@sftlbcn
Copy link

sftlbcn commented Mar 21, 2024

duplicate of #82350?

@XChy
Copy link
Member Author

XChy commented Mar 21, 2024

duplicate of #82350?

Oh, it's a duplicate. Close it now.

@XChy XChy closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2024
@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants