-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[LoongArch] Fix fp_to_uint/fp_to_sint conversion errors for lasx #137129
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,9 @@ define void @fptoui_v4f64_v4i32(ptr %res, ptr %in){ | |
; CHECK-LABEL: fptoui_v4f64_v4i32: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: xvld $xr0, $a1, 0 | ||
; CHECK-NEXT: xvftintrz.lu.d $xr0, $xr0 | ||
; CHECK-NEXT: xvpermi.d $xr1, $xr0, 238 | ||
; CHECK-NEXT: xvfcvt.s.d $xr0, $xr1, $xr0 | ||
; CHECK-NEXT: xvftintrz.w.s $xr0, $xr0 | ||
; CHECK-NEXT: xvpickev.w $xr0, $xr1, $xr0 | ||
; CHECK-NEXT: vst $vr0, $a0, 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM.
|
||
; CHECK-NEXT: ret | ||
%v0 = load <4 x double>, ptr %in | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous impl appears to convert
f64
tof32
before performing the integer conversion, which introduces a loss of precision at thef64 -> f32
step.In the updated version, it seems the
f64
values are first converted toi64
and then truncated tou32
. This can produce incorrect results when the originalf64
values exceed the range representable by (signed)i32
.Would it make sense to go with a direct
f64 -> i32
conversion instead?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xvftintrz.w.d
orxvftintrz.l.d + xvpickev.w
which one is faster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to correct my earlier comment - it was inaccurate and has been deleted. :P
According to the LLVM IR
fptosi
spec:So unless overflow/invalid recording is required, using
xvftintrz.l.d + xvpickev.w
is also valid, and this sequence may offer better throughput.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref: https://reviews.llvm.org/D128900#3630052 LGTM.
Just a note: On the LoongArch target,
-ftrapping-math
and-fno-trapping-math
currently produce identical LLVM IR. This implies that floating-point exception behavior is not yet supported, which is a separate issue worth addressing.