-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ValueTracking] Implement computeKnownFPClass
for llvm.vector.reduce.{fmin,fmax,fmaximum,fminimum}
#88408
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
goldsteinn
wants to merge
2
commits into
llvm:main
from
goldsteinn:goldsteinn/known-fp-class-vector-reduce-ops
Closed
[ValueTracking] Implement computeKnownFPClass
for llvm.vector.reduce.{fmin,fmax,fmaximum,fminimum}
#88408
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
119 changes: 119 additions & 0 deletions
119
llvm/test/Transforms/InstCombine/known-fpclass-reduce-signbit.ll
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 |
---|---|---|
@@ -0,0 +1,119 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2 | ||
; RUN: opt < %s -S -passes=instcombine | FileCheck %s | ||
|
||
define i1 @vector_reduce_maximum_signbit(<4 x double> nofpclass(nan nzero) %x) { | ||
; CHECK-LABEL: define i1 @vector_reduce_maximum_signbit | ||
; CHECK-SAME: (<4 x double> nofpclass(nan nzero) [[X:%.*]]) { | ||
; CHECK-NEXT: ret i1 true | ||
; | ||
%x.abs = call <4 x double> @llvm.fabs.v4f64(<4 x double> %x) | ||
%op = call double @llvm.vector.reduce.fmaximum.v4f64(<4 x double> %x.abs) | ||
%cmp = fcmp oge double %op, 0.0 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @vector_reduce_maximum_signbit_fail_maybe_nan(<4 x double> nofpclass(nzero) %x) { | ||
; CHECK-LABEL: define i1 @vector_reduce_maximum_signbit_fail_maybe_nan | ||
; CHECK-SAME: (<4 x double> nofpclass(nzero) [[X:%.*]]) { | ||
; CHECK-NEXT: [[X_ABS:%.*]] = call <4 x double> @llvm.fabs.v4f64(<4 x double> [[X]]) | ||
; CHECK-NEXT: [[OP:%.*]] = call double @llvm.vector.reduce.fmaximum.v4f64(<4 x double> [[X_ABS]]) | ||
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge double [[OP]], 0.000000e+00 | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%x.abs = call <4 x double> @llvm.fabs.v4f64(<4 x double> %x) | ||
%op = call double @llvm.vector.reduce.fmaximum.v4f64(<4 x double> %x.abs) | ||
%cmp = fcmp oge double %op, 0.0 | ||
ret i1 %cmp | ||
} | ||
|
||
|
||
define i1 @vector_reduce_minimum_signbit(<4 x double> nofpclass(nan nzero) %x) { | ||
; CHECK-LABEL: define i1 @vector_reduce_minimum_signbit | ||
; CHECK-SAME: (<4 x double> nofpclass(nan nzero) [[X:%.*]]) { | ||
; CHECK-NEXT: ret i1 true | ||
; | ||
%x.abs = call <4 x double> @llvm.fabs.v4f64(<4 x double> %x) | ||
%op = call double @llvm.vector.reduce.fminimum.v4f64(<4 x double> %x.abs) | ||
%cmp = fcmp oge double %op, 0.0 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @vector_reduce_minimum_signbit_fail_maybe_nan(<4 x double> nofpclass(nzero) %x) { | ||
; CHECK-LABEL: define i1 @vector_reduce_minimum_signbit_fail_maybe_nan | ||
; CHECK-SAME: (<4 x double> nofpclass(nzero) [[X:%.*]]) { | ||
; CHECK-NEXT: [[X_ABS:%.*]] = call <4 x double> @llvm.fabs.v4f64(<4 x double> [[X]]) | ||
; CHECK-NEXT: [[OP:%.*]] = call double @llvm.vector.reduce.fminimum.v4f64(<4 x double> [[X_ABS]]) | ||
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge double [[OP]], 0.000000e+00 | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%x.abs = call <4 x double> @llvm.fabs.v4f64(<4 x double> %x) | ||
%op = call double @llvm.vector.reduce.fminimum.v4f64(<4 x double> %x.abs) | ||
%cmp = fcmp oge double %op, 0.0 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @vector_reduce_max_signbit(<4 x double> nofpclass(nan nzero) %x) { | ||
; CHECK-LABEL: define i1 @vector_reduce_max_signbit | ||
; CHECK-SAME: (<4 x double> nofpclass(nan nzero) [[X:%.*]]) { | ||
; CHECK-NEXT: ret i1 true | ||
; | ||
%x.abs = call <4 x double> @llvm.fabs.v4f64(<4 x double> %x) | ||
%op = call double @llvm.vector.reduce.fmax.v4f64(<4 x double> %x.abs) | ||
%cmp = fcmp oge double %op, 0.0 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @vector_reduce_max_signbit_fail_maybe_nan(<4 x double> nofpclass(nzero) %x) { | ||
; CHECK-LABEL: define i1 @vector_reduce_max_signbit_fail_maybe_nan | ||
; CHECK-SAME: (<4 x double> nofpclass(nzero) [[X:%.*]]) { | ||
; CHECK-NEXT: [[X_ABS:%.*]] = call <4 x double> @llvm.fabs.v4f64(<4 x double> [[X]]) | ||
; CHECK-NEXT: [[OP:%.*]] = call double @llvm.vector.reduce.fmax.v4f64(<4 x double> [[X_ABS]]) | ||
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge double [[OP]], 0.000000e+00 | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%x.abs = call <4 x double> @llvm.fabs.v4f64(<4 x double> %x) | ||
%op = call double @llvm.vector.reduce.fmax.v4f64(<4 x double> %x.abs) | ||
%cmp = fcmp oge double %op, 0.0 | ||
ret i1 %cmp | ||
} | ||
|
||
|
||
define i1 @vector_reduce_min_signbit(<4 x double> nofpclass(nan nzero) %x) { | ||
; CHECK-LABEL: define i1 @vector_reduce_min_signbit | ||
; CHECK-SAME: (<4 x double> nofpclass(nan nzero) [[X:%.*]]) { | ||
; CHECK-NEXT: ret i1 true | ||
; | ||
%x.abs = call <4 x double> @llvm.fabs.v4f64(<4 x double> %x) | ||
%op = call double @llvm.vector.reduce.fmin.v4f64(<4 x double> %x.abs) | ||
%cmp = fcmp oge double %op, 0.0 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @vector_reduce_min_signbit_fail_maybe_nan(<4 x double> nofpclass(nzero) %x) { | ||
; CHECK-LABEL: define i1 @vector_reduce_min_signbit_fail_maybe_nan | ||
; CHECK-SAME: (<4 x double> nofpclass(nzero) [[X:%.*]]) { | ||
; CHECK-NEXT: [[X_ABS:%.*]] = call <4 x double> @llvm.fabs.v4f64(<4 x double> [[X]]) | ||
; CHECK-NEXT: [[OP:%.*]] = call double @llvm.vector.reduce.fmin.v4f64(<4 x double> [[X_ABS]]) | ||
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge double [[OP]], 0.000000e+00 | ||
; CHECK-NEXT: ret i1 [[CMP]] | ||
; | ||
%x.abs = call <4 x double> @llvm.fabs.v4f64(<4 x double> %x) | ||
%op = call double @llvm.vector.reduce.fmin.v4f64(<4 x double> %x.abs) | ||
%cmp = fcmp oge double %op, 0.0 | ||
ret i1 %cmp | ||
} | ||
|
||
dtcxzyw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
define i1 @vector_reduce_min_signbit_nnan_from_fmf(<4 x double> nofpclass(nzero) %x) { | ||
; CHECK-LABEL: define i1 @vector_reduce_min_signbit_nnan_from_fmf | ||
; CHECK-SAME: (<4 x double> nofpclass(nzero) [[X:%.*]]) { | ||
; CHECK-NEXT: ret i1 true | ||
; | ||
%x.abs = call <4 x double> @llvm.fabs.v4f64(<4 x double> %x) | ||
%op = call nnan double @llvm.vector.reduce.fmin.v4f64(<4 x double> %x.abs) | ||
%cmp = fcmp oge double %op, 0.0 | ||
ret i1 %cmp | ||
} | ||
|
||
|
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
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.
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.
Please use
bitcast + icmp
instead.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.
Why?
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.
It is the canonical form of signbit idiom: https://godbolt.org/z/zMnPPq6o3. I prefer to use the canonical form, although in cases with nnan/nsz both forms are fine.
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.
That is more instructions, so it probably shouldn't be the canonical form
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.
Although I suppose it works even in the nan case
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.
bitcast + icmp
doesn't work. Needs forknownFPClass
->KnownBits
patch. My preference would be to just get this in, but I can wait if there are strong feelings.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.
For the purposes of this patch, I think it should just stay the fcmp. It's fewer operations and has the same effect for the test