-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[InstSimplify] Add basic constant folding for llvm.sincos
#114527
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
; RUN: opt -S -passes=instsimplify %s | FileCheck %s | ||
|
||
define { float, float } @sincos_zero() { | ||
; CHECK-LABEL: define { float, float } @sincos_zero() { | ||
; CHECK-NEXT: ret { float, float } { float 0.000000e+00, float 1.000000e+00 } | ||
; | ||
%ret = call { float, float } @llvm.sincos.f32(float zeroinitializer) | ||
ret { float, float } %ret | ||
} | ||
|
||
define { float, float } @sincos_neg_zero() { | ||
; CHECK-LABEL: define { float, float } @sincos_neg_zero() { | ||
; CHECK-NEXT: ret { float, float } { float -0.000000e+00, float 1.000000e+00 } | ||
; | ||
%ret = call { float, float } @llvm.sincos.f32(float -0.0) | ||
ret { float, float } %ret | ||
} | ||
|
||
define { float, float } @sincos_one() { | ||
; CHECK-LABEL: define { float, float } @sincos_one() { | ||
; CHECK-NEXT: ret { float, float } { float [[$SIN_ONE:.+]], float [[$COS_ONE:.+]] } | ||
; | ||
%ret = call { float, float } @llvm.sincos.f32(float 1.0) | ||
ret { float, float } %ret | ||
} | ||
|
||
define { float, float } @sincos_two() { | ||
; CHECK-LABEL: define { float, float } @sincos_two() { | ||
; CHECK-NEXT: ret { float, float } { float [[$SIN_TWO:.+]], float [[$COS_TWO:.+]] } | ||
; | ||
%ret = call { float, float } @llvm.sincos.f32(float 2.0) | ||
ret { float, float } %ret | ||
} | ||
|
||
define { <2 x float>, <2 x float> } @sincos_vector() { | ||
; CHECK-LABEL: define { <2 x float>, <2 x float> } @sincos_vector() { | ||
; CHECK-NEXT: ret { <2 x float>, <2 x float> } { <2 x float> <float [[$SIN_ONE]], float [[$SIN_TWO]]>, <2 x float> <float [[$COS_ONE]], float [[$COS_TWO]]> } | ||
; | ||
%ret = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> <float 1.0, float 2.0>) | ||
ret { <2 x float>, <2 x float> } %ret | ||
} | ||
|
||
define { <2 x float>, <2 x float> } @sincos_zero_vector() { | ||
; CHECK-LABEL: define { <2 x float>, <2 x float> } @sincos_zero_vector() { | ||
; CHECK-NEXT: ret { <2 x float>, <2 x float> } { <2 x float> zeroinitializer, <2 x float> <float 1.000000e+00, float 1.000000e+00> } | ||
; | ||
%ret = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> zeroinitializer) | ||
ret { <2 x float>, <2 x float> } %ret | ||
} | ||
|
||
define { float, float } @sincos_poison() { | ||
; CHECK-LABEL: define { float, float } @sincos_poison() { | ||
; CHECK-NEXT: [[RET:%.*]] = call { float, float } @llvm.sincos.f32(float poison) | ||
; CHECK-NEXT: ret { float, float } [[RET]] | ||
; | ||
%ret = call { float, float } @llvm.sincos.f32(float poison) | ||
ret { float, float } %ret | ||
} | ||
|
||
define { <2 x float>, <2 x float> } @sincos_poison_vector() { | ||
; CHECK-LABEL: define { <2 x float>, <2 x float> } @sincos_poison_vector() { | ||
; CHECK-NEXT: [[RET:%.*]] = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> poison) | ||
; CHECK-NEXT: ret { <2 x float>, <2 x float> } [[RET]] | ||
; | ||
%ret = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> poison) | ||
ret { <2 x float>, <2 x float> } %ret | ||
} | ||
|
||
define { <vscale x 2 x float>, <vscale x 2 x float> } @sincos_poison_scalable_vector() { | ||
; CHECK-LABEL: define { <vscale x 2 x float>, <vscale x 2 x float> } @sincos_poison_scalable_vector() { | ||
; CHECK-NEXT: [[RET:%.*]] = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.sincos.nxv2f32(<vscale x 2 x float> poison) | ||
; CHECK-NEXT: ret { <vscale x 2 x float>, <vscale x 2 x float> } [[RET]] | ||
; | ||
%ret = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.sincos.nxv2f32(<vscale x 2 x float> poison) | ||
ret { <vscale x 2 x float>, <vscale x 2 x float> } %ret | ||
} | ||
|
||
define { float, float } @sincos_undef() { | ||
; CHECK-LABEL: define { float, float } @sincos_undef() { | ||
; CHECK-NEXT: [[RET:%.*]] = call { float, float } @llvm.sincos.f32(float undef) | ||
; CHECK-NEXT: ret { float, float } [[RET]] | ||
; | ||
%ret = call { float, float } @llvm.sincos.f32(float undef) | ||
ret { float, float } %ret | ||
} | ||
|
||
define { <2 x float>, <2 x float> } @sincos_undef_vector() { | ||
; CHECK-LABEL: define { <2 x float>, <2 x float> } @sincos_undef_vector() { | ||
; CHECK-NEXT: [[RET:%.*]] = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> undef) | ||
; CHECK-NEXT: ret { <2 x float>, <2 x float> } [[RET]] | ||
; | ||
%ret = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> undef) | ||
ret { <2 x float>, <2 x float> } %ret | ||
} | ||
|
||
define { <vscale x 2 x float>, <vscale x 2 x float> } @sincos_undef_scalable_vector() { | ||
; CHECK-LABEL: define { <vscale x 2 x float>, <vscale x 2 x float> } @sincos_undef_scalable_vector() { | ||
; CHECK-NEXT: [[RET:%.*]] = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.sincos.nxv2f32(<vscale x 2 x float> undef) | ||
; CHECK-NEXT: ret { <vscale x 2 x float>, <vscale x 2 x float> } [[RET]] | ||
; | ||
%ret = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.sincos.nxv2f32(<vscale x 2 x float> undef) | ||
ret { <vscale x 2 x float>, <vscale x 2 x float> } %ret | ||
} | ||
|
||
define { <vscale x 2 x float>, <vscale x 2 x float> } @sincos_zero_scalable_vector() { | ||
; CHECK-LABEL: define { <vscale x 2 x float>, <vscale x 2 x float> } @sincos_zero_scalable_vector() { | ||
; CHECK-NEXT: [[RET:%.*]] = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.sincos.nxv2f32(<vscale x 2 x float> zeroinitializer) | ||
; CHECK-NEXT: ret { <vscale x 2 x float>, <vscale x 2 x float> } [[RET]] | ||
; | ||
%ret = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.sincos.nxv2f32(<vscale x 2 x float> zeroinitializer) | ||
ret { <vscale x 2 x float>, <vscale x 2 x float> } %ret | ||
} | ||
Comment on lines
+105
to
+112
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. In a follow up, should probably make sure the zero, undef, and splat cases work for scalable vectors |
||
|
||
define { float, float } @sincos_inf() { | ||
; CHECK-LABEL: define { float, float } @sincos_inf() { | ||
; CHECK-NEXT: [[RET:%.*]] = call { float, float } @llvm.sincos.f32(float 0x7FF0000000000000) | ||
; CHECK-NEXT: ret { float, float } [[RET]] | ||
; | ||
%ret = call { float, float } @llvm.sincos.f32(float 0x7FF0000000000000) | ||
ret { float, float } %ret | ||
} | ||
|
||
define { float, float } @sincos_neginf() { | ||
; CHECK-LABEL: define { float, float } @sincos_neginf() { | ||
; CHECK-NEXT: [[RET:%.*]] = call { float, float } @llvm.sincos.f32(float 0xFFF0000000000000) | ||
; CHECK-NEXT: ret { float, float } [[RET]] | ||
; | ||
%ret = call { float, float } @llvm.sincos.f32(float 0xFFF0000000000000) | ||
ret { float, float } %ret | ||
} | ||
|
||
define { float, float } @sincos_qnan() { | ||
; CHECK-LABEL: define { float, float } @sincos_qnan() { | ||
; CHECK-NEXT: [[RET:%.*]] = call { float, float } @llvm.sincos.f32(float 0x7FF8000000000000) | ||
; CHECK-NEXT: ret { float, float } [[RET]] | ||
; | ||
%ret = call { float, float } @llvm.sincos.f32(float 0x7FF8000000000000) | ||
ret { float, float } %ret | ||
} | ||
|
||
define { float, float } @sincos_snan() { | ||
; CHECK-LABEL: define { float, float } @sincos_snan() { | ||
; CHECK-NEXT: [[RET:%.*]] = call { float, float } @llvm.sincos.f32(float 0x7FF0000020000000) | ||
; CHECK-NEXT: ret { float, float } [[RET]] | ||
; | ||
%ret = call { float, float } @llvm.sincos.f32(float bitcast (i32 2139095041 to float)) | ||
ret { float, float } %ret | ||
} |
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.
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.
No tests for normal values?
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.
I've added some normal value tests using matching the result values (and checking they're used consistently). I avoided this initially as the result for most normal values is displayed in hexadecimal (like
0x3FED18F6E0000000
), which didn't seem that helpful.