Skip to content

[InstCombine] samesign flag should be dropped #112350

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
dtcxzyw opened this issue Oct 15, 2024 · 4 comments · Fixed by #112390
Closed

[InstCombine] samesign flag should be dropped #112350

dtcxzyw opened this issue Oct 15, 2024 · 4 comments · Fixed by #112390

Comments

@dtcxzyw
Copy link
Member

dtcxzyw commented Oct 15, 2024

Reproducer:

define i1 @src(i64 %x, i64 %y, i1 %cond) {
  %cmp1 = icmp ult i64 %x, %y
  %cmp2 = icmp samesign uge i64 %x, %y
  %sel = select i1 %cond, i1 %cmp1, i1 %cmp2
  ret i1 %sel
}

define i1 @tgt(i64 %x, i64 %y, i1 %cond) {
  %cmp2 = icmp samesign uge i64 %x, %y
  %sel = xor i1 %cond, %cmp2
  ret i1 %sel
}
@antoniofrighetto
Copy link
Contributor

Don't we miss checking the flag in hasPoisonGeneratingFlags?

@dtcxzyw
Copy link
Member Author

dtcxzyw commented Oct 15, 2024

Don't we miss checking the flag in hasPoisonGeneratingFlags?

Yeah. I am preparing a patch.

@dtcxzyw
Copy link
Member Author

dtcxzyw commented Oct 15, 2024

But adding support in hasPoisonGeneratingFlags doesn't address this issue :(

@antoniofrighetto
Copy link
Contributor

But adding support in hasPoisonGeneratingFlags doesn't address this issue :(

I assume we may need to dropPoisonGeneratingFlags in InstCombineCompares, where needed?

dtcxzyw added a commit that referenced this issue Oct 16, 2024
In #93591 we introduced
`isKnownInversion` and assumes `X` is poison implies `Y` is poison
because they share common operands. But after introducing `samesign`
this assumption no longer hold if `X` is an icmp has `samesign` flag.

Alive2 link: https://alive2.llvm.org/ce/z/rj3EwQ (Please run it locally
with this patch and AliveToolkit/alive2#1098).

This approach is the most conservative way in my mind to address this
problem. If `X` has `samesign` flag, it will check if `Y` also has this
flag and make sure constant RHS operands have the same sign.

Fixes #112350.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants