-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ConstantFold] Fold log1p
and log1pf
when the input parameter is a constant value.
#112113
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,275 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt < %s -passes=instcombine -S | FileCheck %s | ||
|
||
define float @log1pf_const() { | ||
; CHECK-LABEL: define float @log1pf_const() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float 7.000000e+00) | ||
; CHECK-NEXT: ret float 0x4000A2B240000000 | ||
; | ||
%r = call float @log1pf(float 7.000000e+00) | ||
ret float %r | ||
} | ||
|
||
define double @log1p_const() { | ||
; CHECK-LABEL: define double @log1p_const() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double 7.000000e+00) | ||
; CHECK-NEXT: ret double 0x4000A2B23F3BAB73 | ||
; | ||
%r = call double @log1p(double 7.000000e+00) | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_minus_one() { | ||
; CHECK-LABEL: define float @log1pf_minus_one() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float -1.000000e+00) | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @log1pf(float -1.000000e+00) | ||
ret float %r | ||
} | ||
|
||
define double @log1p_minus_one() { | ||
; CHECK-LABEL: define double @log1p_minus_one() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double -1.000000e+00) | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @log1p(double -1.000000e+00) | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_minus_one_memory_none() { | ||
; CHECK-LABEL: define float @log1pf_minus_one_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float -1.000000e+00) #[[ATTR0:[0-9]+]] | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @log1pf(float -1.000000e+00) readnone | ||
ret float %r | ||
} | ||
|
||
define double @log1p_minus_one_memory_none() { | ||
; CHECK-LABEL: define double @log1p_minus_one_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double -1.000000e+00) #[[ATTR0]] | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @log1p(double -1.000000e+00) readnone | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_zero() { | ||
; CHECK-LABEL: define float @log1pf_zero() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float 0.000000e+00) | ||
; CHECK-NEXT: ret float 0.000000e+00 | ||
; | ||
%r = call float @log1pf(float 0.000000e+00) | ||
ret float %r | ||
} | ||
|
||
define double @log1p_zero() { | ||
; CHECK-LABEL: define double @log1p_zero() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double 0.000000e+00) | ||
; CHECK-NEXT: ret double 0.000000e+00 | ||
; | ||
%r = call double @log1p(double 0.000000e+00) | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_neg_zero() { | ||
; CHECK-LABEL: define float @log1pf_neg_zero() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float -0.000000e+00) | ||
; CHECK-NEXT: ret float -0.000000e+00 | ||
; | ||
%r = call float @log1pf(float -0.000000e+00) | ||
ret float %r | ||
} | ||
|
||
define double @log1p_neg_zero() { | ||
; CHECK-LABEL: define double @log1p_neg_zero() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double -0.000000e+00) | ||
; CHECK-NEXT: ret double -0.000000e+00 | ||
; | ||
%r = call double @log1p(double -0.000000e+00) | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_neg1() { | ||
; CHECK-LABEL: define float @log1pf_neg1() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float -7.000000e+00) | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @log1pf(float -7.000000e+00) | ||
ret float %r | ||
} | ||
|
||
define double @log1p_neg1() { | ||
; CHECK-LABEL: define double @log1p_neg1() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double -7.000000e+00) | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @log1p(double -7.000000e+00) | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_neg1_memory_none() { | ||
; CHECK-LABEL: define float @log1pf_neg1_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float -7.000000e+00) #[[ATTR0]] | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @log1pf(float -7.000000e+00) readnone | ||
ret float %r | ||
} | ||
|
||
define double @log1p_neg1_memory_none() { | ||
; CHECK-LABEL: define double @log1p_neg1_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double -7.000000e+00) #[[ATTR0]] | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @log1p(double -7.000000e+00) readnone | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_neg2() { | ||
; CHECK-LABEL: define float @log1pf_neg2() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float -5.000000e-01) | ||
; CHECK-NEXT: ret float 0xBFE62E4300000000 | ||
; | ||
%r = call float @log1pf(float -5.000000e-01) | ||
ret float %r | ||
} | ||
|
||
define double @log1p_neg2() { | ||
; CHECK-LABEL: define double @log1p_neg2() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double -5.000000e-01) | ||
; CHECK-NEXT: ret double 0xBFE62E42FEFA39EF | ||
; | ||
%r = call double @log1p(double -5.000000e-01) | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_inf() { | ||
; CHECK-LABEL: define float @log1pf_inf() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float 0x7FF0000000000000) | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @log1pf(float 0x7FF0000000000000) | ||
ret float %r | ||
} | ||
|
||
define double @log1p_inf() { | ||
; CHECK-LABEL: define double @log1p_inf() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double 0x7FF0000000000000) | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @log1p(double 0x7FF0000000000000) | ||
c8ef marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ret double %r | ||
} | ||
|
||
define float @log1pf_inf_memory_none() { | ||
; CHECK-LABEL: define float @log1pf_inf_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float 0x7FF0000000000000) #[[ATTR0]] | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @log1pf(float 0x7FF0000000000000) readnone | ||
ret float %r | ||
} | ||
|
||
define double @log1p_inf_memory_none() { | ||
; CHECK-LABEL: define double @log1p_inf_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double 0x7FF0000000000000) #[[ATTR0]] | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @log1p(double 0x7FF0000000000000) readnone | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_neg_inf() { | ||
; CHECK-LABEL: define float @log1pf_neg_inf() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float 0xFFF0000000000000) | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @log1pf(float 0xFFF0000000000000) | ||
ret float %r | ||
} | ||
|
||
define double @log1p_neg_inf() { | ||
; CHECK-LABEL: define double @log1p_neg_inf() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double 0xFFF0000000000000) | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @log1p(double 0xFFF0000000000000) | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_neg_inf_memory_none() { | ||
; CHECK-LABEL: define float @log1pf_neg_inf_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float 0xFFF0000000000000) #[[ATTR0]] | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @log1pf(float 0xFFF0000000000000) readnone | ||
ret float %r | ||
} | ||
|
||
define double @log1p_neg_inf_memory_none() { | ||
; CHECK-LABEL: define double @log1p_neg_inf_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double 0xFFF0000000000000) #[[ATTR0]] | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @log1p(double 0xFFF0000000000000) readnone | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_nan() { | ||
; CHECK-LABEL: define float @log1pf_nan() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float 0x7FF8000000000000) | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @log1pf(float 0x7FF8000000000000) | ||
ret float %r | ||
} | ||
|
||
define double @log1p_nan() { | ||
; CHECK-LABEL: define double @log1p_nan() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double 0x7FF8000000000000) | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @log1p(double 0x7FF8000000000000) | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_nan_memory_none() { | ||
; CHECK-LABEL: define float @log1pf_nan_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float 0x7FF8000000000000) #[[ATTR0]] | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @log1pf(float 0x7FF8000000000000) readnone | ||
ret float %r | ||
} | ||
|
||
define double @log1p_nan_memory_none() { | ||
; CHECK-LABEL: define double @log1p_nan_memory_none() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double 0x7FF8000000000000) #[[ATTR0]] | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @log1p(double 0x7FF8000000000000) readnone | ||
ret double %r | ||
} | ||
|
||
define float @log1pf_poison() { | ||
; CHECK-LABEL: define float @log1pf_poison() { | ||
; CHECK-NEXT: [[R:%.*]] = call float @log1pf(float poison) | ||
; CHECK-NEXT: ret float [[R]] | ||
; | ||
%r = call float @log1pf(float poison) | ||
ret float %r | ||
} | ||
|
||
define double @log1p_poison() { | ||
; CHECK-LABEL: define double @log1p_poison() { | ||
; CHECK-NEXT: [[R:%.*]] = call double @log1p(double poison) | ||
; CHECK-NEXT: ret double [[R]] | ||
; | ||
%r = call double @log1p(double poison) | ||
ret double %r | ||
} | ||
|
||
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. Test memory none special cases 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. I have indeed considered handling Constant *ConstantFoldFP(double (*NativeFP)(double), const APFloat &V, Type *Ty,
CallBase *CB) {
llvm_fenv_clearexcept();
double Result = NativeFP(V.convertToDouble());
if (llvm_fenv_testexcept()) {
llvm_fenv_clearexcept();
if (CB->doesNotAccessMemory())
return GetConstantFoldFPValue(Result, Ty);
else
return nullptr;
}
return GetConstantFoldFPValue(Result, Ty);
} Handling 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. I don't think the consideration of doesNotAccessMemory belongs down in ConstantFoldFP. It should produce the constant folded value regardless of the side effects. The legality of ignoring the side effects is context dependent 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. Plus you can and should still add the tests for these cases here, even if they do not fold yet 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.
Done. 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.
But IIUC the current implementation of 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. I would consider that a defect of implementation. The separation of concerns should yield the result. If we wanted, we could produce a side piece of information for raised errors. Whether or not you care if an error occurred depend on the callsite (i.e we can ignore any exceptions in default FP environment, and memory(none) callsites can ignore errno writes) 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. I believe our ideas align. Even if the implementation of |
||
declare float @log1pf(float) | ||
declare double @log1p(double) |
Uh oh!
There was an error while loading. Please reload this page.