-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy #120367
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 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 |
---|---|---|
|
@@ -1756,6 +1756,17 @@ static bool interp__builtin_vector_reduce(InterpState &S, CodePtr OpPC, | |
PrimType ElemT = *S.getContext().classify(ElemType); | ||
unsigned NumElems = Arg.getNumElems(); | ||
|
||
if (ElemType->isRealFloatingType()) { | ||
if (ID != Builtin::BI__builtin_reduce_add && | ||
ID != Builtin::BI__builtin_reduce_mul) | ||
llvm_unreachable("Only reduce_add and reduce_mul are supported for " | ||
"floating-point types."); | ||
// Floating-point arithmetic is not valid for constant expression | ||
// initialization. Returning false defers checks to integral constant | ||
// expression validation, preventing a bad deref of Floating as an integer. | ||
return false; | ||
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 wanted to do something like this: if(ElemType->isRealFloatingType()) {
FPOptions FPO = Call->getFPFeaturesInEffect(S.getASTContext().getLangOpts());
llvm::RoundingMode RM = getRoundingMode(FPO);
Floating Result = Arg.atIndex(0).deref<Floating>();
APFloat currResult = Result.getAPFloat();
for (unsigned I = 1; I != NumElems; ++I) {
Floating Elem = Arg.atIndex(I).deref<Floating>();
if (ID == Builtin::BI__builtin_reduce_add) {
if(APFloat::opStatus::opOK != currResult.add(Elem.getAPFloat(),RM))
return false;
} else if (ID == Builtin::BI__builtin_reduce_mul) {
if(APFloat::opStatus::opOK != currResult.multiply(Elem.getAPFloat(),RM))
return false;
} else
llvm_unreachable("Only reduce_add and reduce_mul are supported for floating-point types.");
}
S.Stk.push<Floating>(Floating(currResult));
return true;
} However there are checks further for |
||
} | ||
|
||
INT_TYPE_SWITCH_NO_BOOL(ElemT, { | ||
T Result = Arg.atIndex(0).deref<T>(); | ||
unsigned BitWidth = Result.bitWidth(); | ||
|
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
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
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.
Is this actually unreachable? You have a mix of both real error handling code and an unreachable. Code after an unreachable (like the return) can be removed by a compiler, which would cause some bad behavior here if this ever got hit.
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.
Context the float case was exposed by the changes in
SemaChecking.cpp
which allowedreduce_add
andreduce_mul
to operate on floating point vectors. The remaining reduce builtinsBuiltin::BI__builtin_reduce_xor
,Builtin::BI__builtin_reduce_or
, andBuiltin::BI__builtin_reduce_and
are not reachable here because the integer checks inSemaChecking.cpp
still apply to them. So yes this branch should be unreachable for all nonreduce_add
andreduce_mul
reduction cases.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.
@llvm-beanz I don't understand how this code could be removed by the compiler. The code after the unreachable is in a different block. The unreachable is gated by the builtin check.