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: fold of shuffle into fadd changes NaN payload #74326

Open
nunoplopes opened this issue Dec 4, 2023 · 2 comments
Open

InstCombine: fold of shuffle into fadd changes NaN payload #74326

nunoplopes opened this issue Dec 4, 2023 · 2 comments

Comments

@nunoplopes
Copy link
Member

This optimization changes the NaN payload. Originally it was a pass-through for the last 2 elements, while the optimized code can produce more NaN payloads.

; llvm/test/Transforms/InstCombine/shuffle_select-inseltpoison.ll

define <4 x float> @fadd(<4 x float> %v) {
  %b = fadd <4 x float> %v, { 41.000000, 42.000000, 43.000000, 44.000000 }
  %s = shufflevector <4 x float> %b, <4 x float> %v, 0, 1, 6, 7
  ret <4 x float> %s
}
=>
define <4 x float> @fadd(<4 x float> %v) {
  %s = fadd <4 x float> %v, { 41.000000, 42.000000, -0.000000, -0.000000 }
  ret <4 x float> %s
}
Transformation doesn't verify!

ERROR: Value mismatch

Example:
<4 x float> %v = < #xff800400 (SNaN), #x00000000 (+0.0), #x7f804000 (SNaN), #x00000000 (+0.0) >

Source:
<4 x float> %b = < #x7f800400 (SNaN), #x42280000 (42), #x7f804000 (SNaN), #x42300000 (44) >
<4 x float> %s = < #x7f800400 (SNaN), #x42280000 (42), #x7f804000 (SNaN), #x00000000 (+0.0) >

Target:
<4 x float> %s = < #xff800400 (SNaN), #x42280000 (42), #xff804000 (SNaN), #x00000000 (+0.0) >
Source value: < #x7f800400 (SNaN), #x42280000 (42), #x7f804000 (SNaN), #x00000000 (+0.0) >
Target value: < #xff800400 (SNaN), #x42280000 (42), #xff804000 (SNaN), #x00000000 (+0.0) >
@nunoplopes
Copy link
Member Author

fixed.

@nunoplopes
Copy link
Member Author

Actually, not fixed yet:

; Transforms/InstCombine/shuffle_select-inseltpoison.ll

define <4 x float> @fmul(<4 x float> nofpclass(3) %v) {
  %b = fmul nnan ninf <4 x float> nofpclass(3) %v, { 41.000000, 42.000000, 43.000000, 44.000000 }
  %s = shufflevector <4 x float> %b, <4 x float> nofpclass(3) %v, 0, 5, 6, 7
  ret <4 x float> %s
}
=>
define <4 x float> @fmul(<4 x float> nofpclass(3) %v) {
  %s = fmul nnan ninf <4 x float> nofpclass(3) %v, { 41.000000, 1.000000, 1.000000, 1.000000 }
  ret <4 x float> %s
}
Transformation doesn't verify! (unsound)
ERROR: Target is more poisonous than source

Example:
<4 x float> nofpclass(3) %v = < poison, poison, #xff800000 (-oo), poison >

Source:
<4 x float> %b = < poison, poison, poison, poison >
<4 x float> %s = < poison, poison, #xff800000 (-oo), poison >

Target:
<4 x float> %s = < poison, poison, poison, poison >
Source value: < poison, poison, #xff800000 (-oo), poison >
Target value: < poison, poison, poison, poison >

@nunoplopes nunoplopes reopened this Apr 29, 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

1 participant