-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[X86][Clang] Allow constexpr evaluation of F16C CVTPS2PH intrinsics #162295
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
Show all changes
7 commits
Select commit
Hold shift + click to select a range
88a8114
[X86][Clang] Allow constexpr evaluation of F16C CVTPS2PH intrinsics
ericxu233 0fcfb81
clang format
ericxu233 ba60293
Finished addressing review comments
ericxu233 4df1e69
Address review comments
ericxu233 21c8d5c
Added strict fp mode checking
ericxu233 53de5ae
git clang format
ericxu233 b3cce7d
Merge branch 'main' into constexpr-vcvtps2ph
RKSimon 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
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 |
|---|---|---|
|
|
@@ -13909,6 +13909,81 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) { | |
| return false; | ||
| return Success(R, E); | ||
| } | ||
|
|
||
| case clang::X86::BI__builtin_ia32_vcvtps2ph: | ||
| case clang::X86::BI__builtin_ia32_vcvtps2ph256: { | ||
| APValue SrcVec; | ||
| if (!EvaluateAsRValue(Info, E->getArg(0), SrcVec)) | ||
| return false; | ||
|
|
||
| APSInt Imm; | ||
| if (!EvaluateInteger(E->getArg(1), Imm, Info)) | ||
| return false; | ||
|
|
||
| const auto *SrcVTy = E->getArg(0)->getType()->castAs<VectorType>(); | ||
| unsigned SrcNumElems = SrcVTy->getNumElements(); | ||
| const auto *DstVTy = E->getType()->castAs<VectorType>(); | ||
| unsigned DstNumElems = DstVTy->getNumElements(); | ||
| QualType DstElemTy = DstVTy->getElementType(); | ||
|
|
||
| const llvm::fltSemantics &HalfSem = | ||
| Info.Ctx.getFloatTypeSemantics(Info.Ctx.HalfTy); | ||
|
|
||
| int ImmVal = Imm.getZExtValue(); | ||
| bool UseMXCSR = (ImmVal & 4) != 0; | ||
| bool IsFPConstrained = | ||
| E->getFPFeaturesInEffect(Info.Ctx.getLangOpts()).isFPConstrained(); | ||
|
|
||
| llvm::RoundingMode RM; | ||
| if (!UseMXCSR) { | ||
| switch (ImmVal & 3) { | ||
| case 0: | ||
| RM = llvm::RoundingMode::NearestTiesToEven; | ||
| break; | ||
| case 1: | ||
| RM = llvm::RoundingMode::TowardNegative; | ||
| break; | ||
| case 2: | ||
| RM = llvm::RoundingMode::TowardPositive; | ||
| break; | ||
| case 3: | ||
| RM = llvm::RoundingMode::TowardZero; | ||
| break; | ||
| default: | ||
| llvm_unreachable("Invalid immediate rounding mode"); | ||
| } | ||
| } else { | ||
|
Contributor
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 mean in this case, we need to check |
||
| RM = llvm::RoundingMode::NearestTiesToEven; | ||
| } | ||
|
|
||
| SmallVector<APValue, 8> ResultElements; | ||
| ResultElements.reserve(DstNumElems); | ||
|
|
||
| for (unsigned I = 0; I < SrcNumElems; ++I) { | ||
| APFloat SrcVal = SrcVec.getVectorElt(I).getFloat(); | ||
|
|
||
| bool LostInfo; | ||
| APFloat::opStatus St = SrcVal.convert(HalfSem, RM, &LostInfo); | ||
|
|
||
| if (UseMXCSR && IsFPConstrained && St != APFloat::opOK) { | ||
| Info.FFDiag(E, diag::note_constexpr_dynamic_rounding); | ||
| return false; | ||
| } | ||
|
|
||
| APSInt DstInt(SrcVal.bitcastToAPInt(), | ||
| DstElemTy->isUnsignedIntegerOrEnumerationType()); | ||
| ResultElements.push_back(APValue(DstInt)); | ||
| } | ||
|
|
||
| if (DstNumElems > SrcNumElems) { | ||
| APSInt Zero = Info.Ctx.MakeIntValue(0, DstElemTy); | ||
| for (unsigned I = SrcNumElems; I < DstNumElems; ++I) { | ||
| ResultElements.push_back(APValue(Zero)); | ||
| } | ||
| } | ||
|
|
||
| return Success(ResultElements, E); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.