-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[GlobalISel] Add build methods for FP environment intrinsics #96607
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
This change adds methods like buildGetFPEnv and similar for opcodes that represent manipulation on floating-point state.
Member
|
@llvm/pr-subscribers-llvm-globalisel Author: Serge Pavlov (spavloff) ChangesThis change adds methods like buildGetFPEnv and similar for opcodes that represent manipulation on floating-point state. 3 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
index 92e05ee858a75..a95ed3109feb8 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
@@ -2173,6 +2173,36 @@ class MachineIRBuilder {
return buildInstr(TargetOpcode::G_BITREVERSE, {Dst}, {Src});
}
+ /// Build and insert \p Dst = G_GET_FPENV
+ MachineInstrBuilder buildGetFPEnv(const DstOp &Dst) {
+ return buildInstr(TargetOpcode::G_GET_FPENV, {Dst}, {});
+ }
+
+ /// Build and insert G_SET_FPENV \p Src
+ MachineInstrBuilder buildSetFPEnv(const SrcOp &Src) {
+ return buildInstr(TargetOpcode::G_SET_FPENV, {}, {Src});
+ }
+
+ /// Build and insert G_RESET_FPENV
+ MachineInstrBuilder buildResetFPEnv() {
+ return buildInstr(TargetOpcode::G_RESET_FPENV, {}, {});
+ }
+
+ /// Build and insert \p Dst = G_GET_FPMODE
+ MachineInstrBuilder buildGetFPMode(const DstOp &Dst) {
+ return buildInstr(TargetOpcode::G_GET_FPMODE, {Dst}, {});
+ }
+
+ /// Build and insert G_SET_FPMODE \p Src
+ MachineInstrBuilder buildSetFPMode(const SrcOp &Src) {
+ return buildInstr(TargetOpcode::G_SET_FPMODE, {}, {Src});
+ }
+
+ /// Build and insert G_RESET_FPMODE
+ MachineInstrBuilder buildResetFPMode() {
+ return buildInstr(TargetOpcode::G_RESET_FPMODE, {}, {});
+ }
+
virtual MachineInstrBuilder
buildInstr(unsigned Opc, ArrayRef<DstOp> DstOps, ArrayRef<SrcOp> SrcOps,
std::optional<unsigned> Flags = std::nullopt);
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index c06b35a98e434..ddf6d3c20f022 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2541,24 +2541,20 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
}
case Intrinsic::set_fpenv: {
Value *FPEnv = CI.getOperand(0);
- MIRBuilder.buildInstr(TargetOpcode::G_SET_FPENV, {},
- {getOrCreateVReg(*FPEnv)});
+ MIRBuilder.buildSetFPEnv(getOrCreateVReg(*FPEnv));
return true;
}
- case Intrinsic::reset_fpenv: {
- MIRBuilder.buildInstr(TargetOpcode::G_RESET_FPENV, {}, {});
+ case Intrinsic::reset_fpenv:
+ MIRBuilder.buildResetFPEnv();
return true;
- }
case Intrinsic::set_fpmode: {
Value *FPState = CI.getOperand(0);
- MIRBuilder.buildInstr(TargetOpcode::G_SET_FPMODE, {},
- { getOrCreateVReg(*FPState) });
+ MIRBuilder.buildSetFPMode(getOrCreateVReg(*FPState));
return true;
}
- case Intrinsic::reset_fpmode: {
- MIRBuilder.buildInstr(TargetOpcode::G_RESET_FPMODE, {}, {});
+ case Intrinsic::reset_fpmode:
+ MIRBuilder.buildResetFPMode();
return true;
- }
case Intrinsic::vscale: {
MIRBuilder.buildVScale(getOrCreateVReg(CI), 1);
return true;
diff --git a/llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp b/llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
index 7b4a06fc8a98a..bd3c3e8dda229 100644
--- a/llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
@@ -449,3 +449,34 @@ TEST_F(AArch64GISelMITest, BuildBitfieldExtract) {
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
}
+
+TEST_F(AArch64GISelMITest, BuildFPEnv) {
+ setUp();
+ if (!TM)
+ GTEST_SKIP();
+
+ LLT S32 = LLT::scalar(32);
+ SmallVector<Register, 4> Copies;
+ collectCopies(Copies, MF);
+
+ B.buildGetFPEnv(Copies[0]);
+ B.buildSetFPEnv(Copies[1]);
+ B.buildResetFPEnv();
+ auto GetFPMode = B.buildGetFPMode(S32);
+ B.buildSetFPMode(GetFPMode);
+ B.buildResetFPMode();
+
+ auto CheckStr = R"(
+ ; CHECK: [[COPY0:%[0-9]+]]:_(s64) = COPY $x0
+ ; CHECK: [[COPY1:%[0-9]+]]:_(s64) = COPY $x1
+ ; CHECK: [[COPY2:%[0-9]+]]:_(s64) = COPY $x2
+ ; CHECK: [[COPY0]]:_(s64) = G_GET_FPENV
+ ; CHECK: G_SET_FPENV [[COPY1]]:_(s64)
+ ; CHECK: G_RESET_FPENV
+ ; CHECK: [[FPMODE:%[0-9]+]]:_(s32) = G_GET_FPMODE
+ ; CHECK: G_SET_FPMODE [[FPMODE]]:_(s32)
+ ; CHECK: G_RESET_FPMODE
+ )";
+
+ EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
+}
\ No newline at end of file
|
arsenm
approved these changes
Jun 25, 2024
| )"; | ||
|
|
||
| EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF; | ||
| } |
Contributor
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.
Missing newline EOF
|
Thanks. |
AlexisPerry
pushed a commit
to llvm-project-tlp/llvm-project
that referenced
this pull request
Jul 9, 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.
This change adds methods like buildGetFPEnv and similar for opcodes that represent manipulation on floating-point state.