-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[InstCombine] Resolve TODO: nnan nsz X / -0.0 -> copysign(inf, X) #79766
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
Conversation
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
@llvm/pr-subscribers-llvm-transforms Author: AtariDreams (AtariDreams) ChangesFull diff: https://github.com/llvm/llvm-project/pull/79766.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 6c3adf00c189a8e..3f2ec4eb6e94bec 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1600,7 +1600,17 @@ Instruction *InstCombinerImpl::foldFDivConstantDivisor(BinaryOperator &I) {
// nnan X / +0.0 -> copysign(inf, X)
if (I.hasNoNaNs() && match(I.getOperand(1), m_Zero())) {
IRBuilder<> B(&I);
- // TODO: nnan nsz X / -0.0 -> copysign(inf, X)
+ CallInst *CopySign = B.CreateIntrinsic(
+ Intrinsic::copysign, {C->getType()},
+ {ConstantFP::getInfinity(I.getType()), I.getOperand(0)}, &I);
+ CopySign->takeName(&I);
+ return replaceInstUsesWith(I, CopySign);
+ } else if (I.hasNoNaNs() && I.hasNoSignedZeros() &&
+ match(I.getOperand(1),
+ m_Specific(ConstantFP::get(Type::getDoubleTy(I.getContext()),
+ -0.0)))) {
+ // Handle nnan nsz X / -0.0 -> copysign(inf, X)
+ IRBuilder<> B(&I);
CallInst *CopySign = B.CreateIntrinsic(
Intrinsic::copysign, {C->getType()},
{ConstantFP::getInfinity(I.getType()), I.getOperand(0)}, &I);
diff --git a/llvm/test/Transforms/InstCombine/fdiv.ll b/llvm/test/Transforms/InstCombine/fdiv.ll
index c81a9ba6d4215d9..e0aeb6840223337 100644
--- a/llvm/test/Transforms/InstCombine/fdiv.ll
+++ b/llvm/test/Transforms/InstCombine/fdiv.ll
@@ -992,3 +992,22 @@ define float @fdiv_nnan_neg_zero_f32(float %x) {
%fdiv = fdiv nnan float %x, -0.0
ret float %fdiv
}
+
+define double @test_positive_zero(double %X) {
+; CHECK-LABEL: @test_positive_zero(
+; CHECK-NEXT: [[TMP1:%.*]] = call nnan nsz double @llvm.copysign.f64(double 0x7FF0000000000000, double [[X:%.*]])
+; CHECK-NEXT: ret double [[TMP1]]
+;
+ %1 = fdiv nnan nsz double %X, 0.0
+ ret double %1
+}
+
+define double @test_negative_zero(double %X) {
+; CHECK-LABEL: @test_negative_zero(
+; CHECK-NEXT: [[TMP1:%.*]] = call nnan nsz double @llvm.copysign.f64(double 0x7FF0000000000000, double [[X:%.*]])
+; CHECK-NEXT: ret double [[TMP1]]
+;
+ %1 = fdiv nnan nsz double %X, -0.0
+ ret double %1
+}
+
|
arsenm
reviewed
Jan 29, 2024
bc2784f
to
ecf97ed
Compare
arsenm
reviewed
Feb 6, 2024
@arsenm All issues addressed! |
arsenm
reviewed
Feb 6, 2024
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.
lgtm with some additional edge case handling
arsenm
reviewed
Feb 6, 2024
dtcxzyw
reviewed
Feb 6, 2024
llvm/test/CodeGen/PowerPC/aix-small-local-exec-tls-largeaccess.ll
Outdated
Show resolved
Hide resolved
@dtcxzyw Fixed! |
arsenm
approved these changes
Feb 7, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.