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

select -> fneg/copysign propagates nsz incorrectly #54077

Closed
nunoplopes opened this issue Feb 25, 2022 · 2 comments
Closed

select -> fneg/copysign propagates nsz incorrectly #54077

nunoplopes opened this issue Feb 25, 2022 · 2 comments

Comments

@nunoplopes
Copy link
Member

Test Transforms/InstCombine/select.ll, fn copysign2:
Simplified without vectors:

define float @src(float %x) {
%0:
  %i = bitcast float %x to i32
  %isneg = icmp slt i32 %i, 0
  %r = select nsz i1 %isneg, float 42.000000, float -42.000000
  ret float %r
}
=>
define float @tgt(float %x) {
%0:
  %1 = fneg nsz float %x, exceptions=ignore
  %r = copysign float 42.000000, %1, exceptions=ignore
  ret float %r
}
Transformation doesn't verify!

ERROR: Value mismatch

Example:
float %x = #x00000000 (+0.0)

Source:
i32 %i = #x00000000 (0)
i1 %isneg = #x0 (0)
float %r = #xc2280000 (-42)

Target:
float %1 = #x00000000 (+0.0)
float %r = #x42280000 (42)
Source value: #xc2280000 (-42)
Target value: #x42280000 (42)

Dropping nsz from fneg makes it correct.
https://alive2.llvm.org/ce/z/tNATrd

cc @rotateright @LebedevRI

@RKSimon
Copy link
Collaborator

RKSimon commented Feb 25, 2022

FTR https://reviews.llvm.org/D72643 added the fold

@rotateright rotateright self-assigned this Feb 26, 2022
@rotateright
Copy link
Contributor

The transform in question also propagates FMF to the copysign call, and that's wrong too:
https://alive2.llvm.org/ce/z/VwcVzn

rotateright added a commit that referenced this issue Mar 1, 2022
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

3 participants