-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[NVPTX] Constant-folding for f2i, d2ui, f2ll etc. #118965
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
e520c47
[NVPTX] Constant-folding for f2i, d2ui, f2ll etc.
LewisCrawford 54524d3
Move internal case statements into helper funcs
LewisCrawford 108265f
Move helper functions into separate file
LewisCrawford 623215d
Minor tidying
LewisCrawford 216709f
Add back <stdint.h> include to NVVMIntrinsicUtils
LewisCrawford 0a51bdd
Mark helper functions as inline
LewisCrawford b72c862
Merge branch 'main' into fold_f2i_d2i
LewisCrawford 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,176 @@ | ||
//===--- NVVMIntrinsicUtils.h -----------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
/// \file | ||
/// This file contains the definitions of the enumerations and flags | ||
/// associated with NVVM Intrinsics, along with some helper functions. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_IR_NVVMINTRINSICUTILS_H | ||
#define LLVM_IR_NVVMINTRINSICUTILS_H | ||
|
||
#include <stdint.h> | ||
|
||
#include "llvm/ADT/APFloat.h" | ||
#include "llvm/IR/Intrinsics.h" | ||
#include "llvm/IR/IntrinsicsNVPTX.h" | ||
|
||
namespace llvm { | ||
namespace nvvm { | ||
|
||
// Reduction Ops supported with TMA Copy from Shared | ||
// to Global Memory for the "cp.reduce.async.bulk.tensor.*" | ||
// family of PTX instructions. | ||
enum class TMAReductionOp : uint8_t { | ||
ADD = 0, | ||
MIN = 1, | ||
MAX = 2, | ||
INC = 3, | ||
DEC = 4, | ||
AND = 5, | ||
OR = 6, | ||
XOR = 7, | ||
}; | ||
|
||
inline bool IntrinsicShouldFTZ(Intrinsic::ID IntrinsicID) { | ||
switch (IntrinsicID) { | ||
// Float to i32 / i64 conversion intrinsics: | ||
case Intrinsic::nvvm_f2i_rm_ftz: | ||
case Intrinsic::nvvm_f2i_rn_ftz: | ||
case Intrinsic::nvvm_f2i_rp_ftz: | ||
case Intrinsic::nvvm_f2i_rz_ftz: | ||
|
||
case Intrinsic::nvvm_f2ui_rm_ftz: | ||
case Intrinsic::nvvm_f2ui_rn_ftz: | ||
case Intrinsic::nvvm_f2ui_rp_ftz: | ||
case Intrinsic::nvvm_f2ui_rz_ftz: | ||
|
||
case Intrinsic::nvvm_f2ll_rm_ftz: | ||
case Intrinsic::nvvm_f2ll_rn_ftz: | ||
case Intrinsic::nvvm_f2ll_rp_ftz: | ||
case Intrinsic::nvvm_f2ll_rz_ftz: | ||
|
||
case Intrinsic::nvvm_f2ull_rm_ftz: | ||
case Intrinsic::nvvm_f2ull_rn_ftz: | ||
case Intrinsic::nvvm_f2ull_rp_ftz: | ||
case Intrinsic::nvvm_f2ull_rz_ftz: | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
inline bool IntrinsicConvertsToSignedInteger(Intrinsic::ID IntrinsicID) { | ||
switch (IntrinsicID) { | ||
// f2i | ||
case Intrinsic::nvvm_f2i_rm: | ||
case Intrinsic::nvvm_f2i_rm_ftz: | ||
case Intrinsic::nvvm_f2i_rn: | ||
case Intrinsic::nvvm_f2i_rn_ftz: | ||
case Intrinsic::nvvm_f2i_rp: | ||
case Intrinsic::nvvm_f2i_rp_ftz: | ||
case Intrinsic::nvvm_f2i_rz: | ||
case Intrinsic::nvvm_f2i_rz_ftz: | ||
// d2i | ||
case Intrinsic::nvvm_d2i_rm: | ||
case Intrinsic::nvvm_d2i_rn: | ||
case Intrinsic::nvvm_d2i_rp: | ||
case Intrinsic::nvvm_d2i_rz: | ||
// f2ll | ||
case Intrinsic::nvvm_f2ll_rm: | ||
case Intrinsic::nvvm_f2ll_rm_ftz: | ||
case Intrinsic::nvvm_f2ll_rn: | ||
case Intrinsic::nvvm_f2ll_rn_ftz: | ||
case Intrinsic::nvvm_f2ll_rp: | ||
case Intrinsic::nvvm_f2ll_rp_ftz: | ||
case Intrinsic::nvvm_f2ll_rz: | ||
case Intrinsic::nvvm_f2ll_rz_ftz: | ||
// d2ll | ||
case Intrinsic::nvvm_d2ll_rm: | ||
case Intrinsic::nvvm_d2ll_rn: | ||
case Intrinsic::nvvm_d2ll_rp: | ||
case Intrinsic::nvvm_d2ll_rz: | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
inline APFloat::roundingMode | ||
IntrinsicGetRoundingMode(Intrinsic::ID IntrinsicID) { | ||
switch (IntrinsicID) { | ||
// RM: | ||
case Intrinsic::nvvm_f2i_rm: | ||
case Intrinsic::nvvm_f2ui_rm: | ||
case Intrinsic::nvvm_f2i_rm_ftz: | ||
case Intrinsic::nvvm_f2ui_rm_ftz: | ||
case Intrinsic::nvvm_d2i_rm: | ||
case Intrinsic::nvvm_d2ui_rm: | ||
|
||
case Intrinsic::nvvm_f2ll_rm: | ||
case Intrinsic::nvvm_f2ull_rm: | ||
case Intrinsic::nvvm_f2ll_rm_ftz: | ||
case Intrinsic::nvvm_f2ull_rm_ftz: | ||
case Intrinsic::nvvm_d2ll_rm: | ||
case Intrinsic::nvvm_d2ull_rm: | ||
return APFloat::rmTowardNegative; | ||
|
||
// RN: | ||
case Intrinsic::nvvm_f2i_rn: | ||
case Intrinsic::nvvm_f2ui_rn: | ||
case Intrinsic::nvvm_f2i_rn_ftz: | ||
case Intrinsic::nvvm_f2ui_rn_ftz: | ||
case Intrinsic::nvvm_d2i_rn: | ||
case Intrinsic::nvvm_d2ui_rn: | ||
|
||
case Intrinsic::nvvm_f2ll_rn: | ||
case Intrinsic::nvvm_f2ull_rn: | ||
case Intrinsic::nvvm_f2ll_rn_ftz: | ||
case Intrinsic::nvvm_f2ull_rn_ftz: | ||
case Intrinsic::nvvm_d2ll_rn: | ||
case Intrinsic::nvvm_d2ull_rn: | ||
return APFloat::rmNearestTiesToEven; | ||
|
||
// RP: | ||
case Intrinsic::nvvm_f2i_rp: | ||
case Intrinsic::nvvm_f2ui_rp: | ||
case Intrinsic::nvvm_f2i_rp_ftz: | ||
case Intrinsic::nvvm_f2ui_rp_ftz: | ||
case Intrinsic::nvvm_d2i_rp: | ||
case Intrinsic::nvvm_d2ui_rp: | ||
|
||
case Intrinsic::nvvm_f2ll_rp: | ||
case Intrinsic::nvvm_f2ull_rp: | ||
case Intrinsic::nvvm_f2ll_rp_ftz: | ||
case Intrinsic::nvvm_f2ull_rp_ftz: | ||
case Intrinsic::nvvm_d2ll_rp: | ||
case Intrinsic::nvvm_d2ull_rp: | ||
return APFloat::rmTowardPositive; | ||
|
||
// RZ: | ||
case Intrinsic::nvvm_f2i_rz: | ||
case Intrinsic::nvvm_f2ui_rz: | ||
case Intrinsic::nvvm_f2i_rz_ftz: | ||
case Intrinsic::nvvm_f2ui_rz_ftz: | ||
case Intrinsic::nvvm_d2i_rz: | ||
case Intrinsic::nvvm_d2ui_rz: | ||
|
||
case Intrinsic::nvvm_f2ll_rz: | ||
case Intrinsic::nvvm_f2ull_rz: | ||
case Intrinsic::nvvm_f2ll_rz_ftz: | ||
case Intrinsic::nvvm_f2ull_rz_ftz: | ||
case Intrinsic::nvvm_d2ll_rz: | ||
case Intrinsic::nvvm_d2ull_rz: | ||
return APFloat::rmTowardZero; | ||
} | ||
llvm_unreachable("Invalid f2i/d2i rounding mode intrinsic"); | ||
return APFloat::roundingMode::Invalid; | ||
} | ||
|
||
} // namespace nvvm | ||
} // namespace llvm | ||
#endif // LLVM_IR_NVVMINTRINSICUTILS_H |
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.
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.
Makes me wonder if we can add these FTZ, signedness, and rounding mode, properties as some sort of flag on the intrinsic in tablegen, where we define them, so we don't have to play a whack-a-mole updating these switches every time we add/change a NVPTX intrinsic.
If that's too cumbersome, we could construct a static table/map of intrinsic->flags, populate it once, and then just lookup individual intrinsic flag where we need it. That may be less cumbersome to update in the future.