-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Add IRBuilder::CreateFMA #131112
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
Add IRBuilder::CreateFMA #131112
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
Contributor
frederik-h
commented
Mar 13, 2025
- Adjust some existing CreateIntrinsic uses appropriately
- Adjust IRBuilderTest.cpp and remove duplicate test case
- Adjust some existing CreateIntrinsic uses appropriately - Adjust IRBuilderTest.cpp and remove duplicate test case
@llvm/pr-subscribers-llvm-ir Author: Frederik Harwath (frederik-h) Changes
Full diff: https://github.com/llvm/llvm-project/pull/131112.diff 3 Files Affected:
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 67e357c600d3b..13665dcd992a8 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -1065,6 +1065,13 @@ class IRBuilderBase {
{Src, Exp}, FMFSource, Name);
}
+ /// Create call to the fma intrinsic.
+ Value *CreateFMA(Value *Factor1, Value *Factor2, Value *Summand,
+ FMFSource FMFSource = {}, const Twine &Name = "") {
+ return CreateIntrinsic(Intrinsic::fma, {Factor1->getType()},
+ {Factor1, Factor2, Summand}, FMFSource, Name);
+ }
+
/// Create a call to the arithmetic_fence intrinsic.
CallInst *CreateArithmeticFence(Value *Val, Type *DstType,
const Twine &Name = "") {
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index cb4ecc60aa473..ce3b2c90a41a1 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -3755,7 +3755,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = Intrinsic::x86_avx512_vfmadd_f32;
Rep = Builder.CreateIntrinsic(IID, {}, Ops);
} else {
- Rep = Builder.CreateIntrinsic(Intrinsic::fma, A->getType(), {A, B, C});
+ Rep = Builder.CreateFMA(A, B, C);
}
Value *PassThru = IsMaskZ ? Constant::getNullValue(Rep->getType())
@@ -3808,7 +3808,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Rep = Builder.CreateIntrinsic(IID, {}, {A, B, C, CI->getArgOperand(4)});
} else {
- Rep = Builder.CreateIntrinsic(Intrinsic::fma, A->getType(), {A, B, C});
+ Rep = Builder.CreateFMA(A, B, C);
}
Value *PassThru = IsMaskZ ? llvm::Constant::getNullValue(CI->getType())
diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp
index 3a55d88f03d49..2170524d6eb3c 100644
--- a/llvm/unittests/IR/IRBuilderTest.cpp
+++ b/llvm/unittests/IR/IRBuilderTest.cpp
@@ -109,21 +109,13 @@ TEST_F(IRBuilderTest, Intrinsics) {
EXPECT_TRUE(II->hasNoInfs());
EXPECT_FALSE(II->hasNoNaNs());
- Result = Builder.CreateIntrinsic(Intrinsic::fma, {V->getType()}, {V, V, V});
+ Result = Builder.CreateFMA(V, V, V);
II = cast<IntrinsicInst>(Result);
EXPECT_EQ(II->getIntrinsicID(), Intrinsic::fma);
EXPECT_FALSE(II->hasNoInfs());
EXPECT_FALSE(II->hasNoNaNs());
- Result =
- Builder.CreateIntrinsic(Intrinsic::fma, {V->getType()}, {V, V, V}, I);
- II = cast<IntrinsicInst>(Result);
- EXPECT_EQ(II->getIntrinsicID(), Intrinsic::fma);
- EXPECT_TRUE(II->hasNoInfs());
- EXPECT_FALSE(II->hasNoNaNs());
-
- Result =
- Builder.CreateIntrinsic(Intrinsic::fma, {V->getType()}, {V, V, V}, I);
+ Result = Builder.CreateFMA(V, V, V, I);
II = cast<IntrinsicInst>(Result);
EXPECT_EQ(II->getIntrinsicID(), Intrinsic::fma);
EXPECT_TRUE(II->hasNoInfs());
|
arsenm
reviewed
Mar 13, 2025
frederik-h
commented
Mar 13, 2025
This is derived from CreateConstrainedFPBinOp but supports arbitrary intrinsics.
arsenm
approved these changes
Mar 13, 2025
frederik-h
added a commit
to frederik-h/llvm-project
that referenced
this pull request
Mar 18, 2025
This commit adds a function for creating fma intrinsic calls to the IRBuilder. If the "IsFPConstrained" flag of the builder is set, the function creates a call to "experimental.constrained.fma" instead of "llvm.fma" . To support the creation of the constrained intrinsic, a function "CreateConstrainedFPIntrinsic" is introduced.
frederik-h
added a commit
to frederik-h/llvm-project
that referenced
this pull request
Mar 18, 2025
This commit adds a function for creating fma intrinsic calls to the IRBuilder. If the "IsFPConstrained" flag of the builder is set, the function creates a call to "experimental.constrained.fma" instead of "llvm.fma" . To support the creation of the constrained intrinsic, a function "CreateConstrainedFPIntrinsic" is introduced.
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.