-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[ConstantFold] Fold erf
and erff
when the input parameter is a constant value.
#113079
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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,221 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt < %s -passes=instcombine -mtriple x86_64-unknown-linux-gnu -S | FileCheck %s | ||
|
||
define float @erff_const() { | ||
; CHECK-LABEL: define float @erff_const() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @erff(float 5.000000e-01) | ||
; CHECK-NEXT: ret float 0x3FE0A7EF60000000 | ||
; | ||
%r = call float @erff(float 5.000000e-01) | ||
ret float %r | ||
} | ||
|
||
define double @erf_const() { | ||
; CHECK-LABEL: define double @erf_const() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @erf(double -5.000000e-01) | ||
; CHECK-NEXT: ret double 0xBFE0A7EF5C18EDD2 | ||
; | ||
%r = call double @erf(double -5.000000e-01) | ||
ret double %r | ||
} | ||
|
||
define float @erff_zero() { | ||
; CHECK-LABEL: define float @erff_zero() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @erff(float 0.000000e+00) | ||
; CHECK-NEXT: ret float 0.000000e+00 | ||
; | ||
%r = call float @erff(float 0.000000e+00) | ||
ret float %r | ||
} | ||
|
||
define double @erf_zero() { | ||
; CHECK-LABEL: define double @erf_zero() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @erf(double 0.000000e+00) | ||
; CHECK-NEXT: ret double 0.000000e+00 | ||
; | ||
%r = call double @erf(double 0.000000e+00) | ||
ret double %r | ||
} | ||
|
||
define float @erff_neg_zero() { | ||
; CHECK-LABEL: define float @erff_neg_zero() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @erff(float -0.000000e+00) | ||
; CHECK-NEXT: ret float -0.000000e+00 | ||
; | ||
%r = call float @erff(float -0.000000e+00) | ||
ret float %r | ||
} | ||
|
||
define double @erf_neg_zero() { | ||
; CHECK-LABEL: define double @erf_neg_zero() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @erf(double -0.000000e+00) | ||
; CHECK-NEXT: ret double -0.000000e+00 | ||
; | ||
%r = call double @erf(double -0.000000e+00) | ||
ret double %r | ||
} | ||
|
||
define float @erff_inf() { | ||
; CHECK-LABEL: define float @erff_inf() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @erff(float 0x7FF0000000000000) | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @erff(float 0x7FF0000000000000) | ||
ret float %r | ||
} | ||
|
||
define double @erf_inf() { | ||
; CHECK-LABEL: define double @erf_inf() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @erf(double 0x7FF0000000000000) | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @erf(double 0x7FF0000000000000) | ||
ret double %r | ||
} | ||
|
||
define float @erff_inf_memory_none() { | ||
; CHECK-LABEL: define float @erff_inf_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @erff(float 0x7FF0000000000000) #[[ATTR1:[0-9]+]] | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @erff(float 0x7FF0000000000000) readnone | ||
ret float %r | ||
} | ||
|
||
define double @erf_inf_memory_none() { | ||
; CHECK-LABEL: define double @erf_inf_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @erf(double 0x7FF0000000000000) #[[ATTR1]] | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @erf(double 0x7FF0000000000000) readnone | ||
ret double %r | ||
} | ||
|
||
define float @erff_neg_inf() { | ||
; CHECK-LABEL: define float @erff_neg_inf() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @erff(float 0xFFF0000000000000) | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @erff(float 0xFFF0000000000000) | ||
ret float %r | ||
} | ||
|
||
define double @erf_neg_inf() { | ||
; CHECK-LABEL: define double @erf_neg_inf() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @erf(double 0xFFF0000000000000) | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @erf(double 0xFFF0000000000000) | ||
ret double %r | ||
} | ||
|
||
define float @erff_neg_inf_memory_none() { | ||
; CHECK-LABEL: define float @erff_neg_inf_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @erff(float 0xFFF0000000000000) #[[ATTR1]] | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @erff(float 0xFFF0000000000000) readnone | ||
ret float %r | ||
} | ||
|
||
define double @erf_neg_inf_memory_none() { | ||
; CHECK-LABEL: define double @erf_neg_inf_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @erf(double 0xFFF0000000000000) #[[ATTR1]] | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @erf(double 0xFFF0000000000000) readnone | ||
ret double %r | ||
} | ||
|
||
define float @erff_nan() { | ||
; CHECK-LABEL: define float @erff_nan() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @erff(float 0x7FF8000000000000) | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @erff(float 0x7FF8000000000000) | ||
ret float %r | ||
} | ||
|
||
define double @erf_nan() { | ||
; CHECK-LABEL: define double @erf_nan() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @erf(double 0x7FF8000000000000) | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @erf(double 0x7FF8000000000000) | ||
ret double %r | ||
} | ||
|
||
define float @erff_nan_memory_none() { | ||
; CHECK-LABEL: define float @erff_nan_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @erff(float 0x7FF8000000000000) #[[ATTR1]] | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @erff(float 0x7FF8000000000000) readnone | ||
ret float %r | ||
} | ||
|
||
define double @erf_nan_memory_none() { | ||
; CHECK-LABEL: define double @erf_nan_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @erf(double 0x7FF8000000000000) #[[ATTR1]] | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @erf(double 0x7FF8000000000000) readnone | ||
ret double %r | ||
} | ||
|
||
define float @erff_poison() { | ||
; CHECK-LABEL: define float @erff_poison() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @erff(float poison) | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @erff(float poison) | ||
ret float %r | ||
} | ||
|
||
define double @erf_poison() { | ||
; CHECK-LABEL: define double @erf_poison() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @erf(double poison) | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @erf(double poison) | ||
ret double %r | ||
} | ||
|
||
c8ef marked this conversation as resolved.
Show resolved
Hide resolved
|
||
define float @erff_const_strictfp() { | ||
; CHECK-LABEL: define float @erff_const_strictfp() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @erff(float 5.000000e-01) #[[ATTR2:[0-9]+]] | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @erff(float 5.000000e-01) strictfp | ||
ret float %r | ||
} | ||
|
||
define double @erf_const_strictfp() { | ||
; CHECK-LABEL: define double @erf_const_strictfp() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @erf(double -5.000000e-01) #[[ATTR2]] | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @erf(double -5.000000e-01) strictfp | ||
ret double %r | ||
} | ||
|
||
define float @erff_nan_strictfp() { | ||
; CHECK-LABEL: define float @erff_nan_strictfp() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @erff(float 0x7FF8000000000000) #[[ATTR2]] | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @erff(float 0x7FF8000000000000) strictfp | ||
ret float %r | ||
} | ||
|
||
define double @erf_nan_strictfp() { | ||
; CHECK-LABEL: define double @erf_nan_strictfp() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @erf(double 0x7FF8000000000000) #[[ATTR2]] | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @erf(double 0x7FF8000000000000) strictfp | ||
ret double %r | ||
} | ||
|
||
declare float @erff(float) willreturn | ||
declare double @erf(double) willreturn |
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.
None of these cases folded?
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.
IIUC the only cases that are not folded are NaN and Inf; zero input will be folded as expected.
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 call wasn't deleted though.
Plus the linux docs suggest it doesn't ever set errno
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.
Other libcall test case exhibits similar behavior, but it does not seem to affect the final fold result. I believe the unused instruction will be deleted anyway?
Yes, it is still blocked by the previously discussed issue and will be addressed later.
llvm-project/llvm/lib/Analysis/ConstantFolding.cpp
Lines 2237 to 2241 in d6360d2
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.
Then those are also broken. This call needs to be immediately deleted
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.
Not sure why the calls are not being deleted. The problem might be at the callsite, specifically in
instsimplify
.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.
Hm, it does seem these are deleted later. I would still expect them to be immediately killed, but this seems to be a more widespread issue
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.
Done.
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.
There are two issues here:
willreturn
to ensure it is deleted from the worklist. This will be handled byInferFunctionAttrs
during compilation, but is not currently observed in testing.isMathLibCallNoop
should include the relevant library call.