[ConstantFolding] Fix nvvm_round folding on PPC#149837
Merged
LewisCrawford merged 1 commit intollvm:mainfrom Jul 21, 2025
Merged
[ConstantFolding] Fix nvvm_round folding on PPC#149837LewisCrawford merged 1 commit intollvm:mainfrom
LewisCrawford merged 1 commit intollvm:mainfrom
Conversation
Member
|
@llvm/pr-subscribers-llvm-analysis Author: Lewis Crawford (LewisCrawford) ChangesFix a failing test for constant-folding the nvvm_round intrinsic. The original implementation added in #141233 used a native libm call to the "round" function, but on PPC this produces +0.0 if the input is -0.0, which caused a test failure. This patch updates it to use APFloat functions instead of native libm calls to ensure cross-platform consistency. Full diff: https://github.com/llvm/llvm-project/pull/149837.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index f5a88b6e0368e..eb7369fcc7513 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2677,11 +2677,15 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
case Intrinsic::nvvm_round_ftz_f:
case Intrinsic::nvvm_round_f:
- case Intrinsic::nvvm_round_d:
- return ConstantFoldFP(
- round, APF, Ty,
- nvvm::GetNVVMDenromMode(
- nvvm::UnaryMathIntrinsicShouldFTZ(IntrinsicID)));
+ case Intrinsic::nvvm_round_d: {
+ // Use APFloat implementation instead of native libm call, as some
+ // implementations (e.g. on PPC) do not preserve the sign of negative 0.
+ APFloat Res = nvvm::UnaryMathIntrinsicShouldFTZ(IntrinsicID)
+ ? FTZPreserveSign(APF)
+ : APF;
+ Res.roundToIntegral(APFloat::rmNearestTiesToAway);
+ return ConstantFP::get(Ty->getContext(), U);
+ }
case Intrinsic::nvvm_saturate_ftz_f:
case Intrinsic::nvvm_saturate_d:
|
Contributor
Author
|
This should fix the test failure here: https://lab.llvm.org/buildbot/#/builders/64/builds/4929
|
Fix a failing test for constant-folding the nvvm_round intrinsic. The original implementation added in llvm#141233 used a native libm call to the "round" function, but on PPC this produces +0.0 if the input is -0.0, which caused a test failure. This patch updates it to use APFloat functions instead of native libm calls to ensure cross-platform consistency.
310d89d to
01e0309
Compare
jholewinski
approved these changes
Jul 21, 2025
Contributor
jholewinski
left a comment
There was a problem hiding this comment.
LGTM. Thanks for jumping on this!
mahesh-attarde
pushed a commit
to mahesh-attarde/llvm-project
that referenced
this pull request
Jul 28, 2025
Fix a failing test for constant-folding the nvvm_round intrinsic. The original implementation added in llvm#141233 used a native libm call to the "round" function, but on PPC this produces +0.0 if the input is -0.0, which caused a test failure. This patch updates it to use APFloat functions instead of native libm calls to ensure cross-platform consistency.
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
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.
Fix a failing test for constant-folding the nvvm_round intrinsic. The original implementation added in #141233 used a native libm call to the "round" function, but on PPC this produces +0.0 if the input is -0.0, which caused a test failure.
This patch updates it to use APFloat functions instead of native libm calls to ensure cross-platform consistency.