Skip to content
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] very different results with nearly identical functions with a select and icmp eq #58275

Open
mikebenfield opened this issue Oct 10, 2022 · 4 comments

Comments

@mikebenfield
Copy link

Two nearly identical functions

InstCombine optimizes one of them very well. The other one not so much. Unfortunately I don't have the terminology to describe what's going on better than pointing to that link. Maybe someone else could help me out.

@RalfJung
Copy link
Contributor

RalfJung commented Oct 11, 2022

Cc @nikic your help with this would be appreciated :)

@nikic
Copy link
Contributor

nikic commented Oct 11, 2022

cc @rotateright Looks like another issue with missing trunc vs and canonicalization for icmps?

@rotateright
Copy link
Contributor

cc @rotateright Looks like another issue with missing trunc vs and canonicalization for icmps?

Yes, I think the fold itself is easy:
https://alive2.llvm.org/ce/z/umK_t-
...but it can interfere with other pattern-matching, and we likely have conflicting folds (infinite loop potential) buried in there, so we probably have to untangle some other transforms.

@rotateright
Copy link
Contributor

I looked at this, and it's probably better to try the reverse of what I posted above:
https://alive2.llvm.org/ce/z/ZQZ9zb
(create a mask op instead of truncating)
...because we already do that for equality predicates, and that works for unsigned preds too.

But then we hit another problem because we chop off the low bit of the mask in the example shown here:

define i1 @myfunction1(i16 %0) local_unnamed_addr #0 {
start:
  %1 = and i16 %0, 254
  %2 = icmp ult i16 %1, 50
  %z.mask = and i16 %0, 255
  %3 = icmp eq i16 %z.mask, 47
  %4 = and i1 %2, %3
  ret i1 %4
}

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