-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[HLSL][DXIL][SPIRV] Create llvm dot intrinsic and use for HLSL #102872
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
+780
−282
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6fde4bc
Create llvm dot intrinsic
pow2clk 7ca6bc5
Update DX intrinsic expansion for new llvm intrinsics
pow2clk edbb80c
Add SPIRV generation for HLSL dot
pow2clk c08c015
Respond to feedback
pow2clk 0e05f01
refactor DXIL intrinsic expansion to move erase and replace to the ca…
pow2clk ad527a7
Fix legalization of dotprod generic opcodes
pow2clk 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18470,22 +18470,14 @@ llvm::Value *CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned ICEArguments, | |
return Arg; | ||
} | ||
|
||
Intrinsic::ID getDotProductIntrinsic(QualType QT, int elementCount) { | ||
if (QT->hasFloatingRepresentation()) { | ||
switch (elementCount) { | ||
case 2: | ||
return Intrinsic::dx_dot2; | ||
case 3: | ||
return Intrinsic::dx_dot3; | ||
case 4: | ||
return Intrinsic::dx_dot4; | ||
} | ||
} | ||
if (QT->hasSignedIntegerRepresentation()) | ||
return Intrinsic::dx_sdot; | ||
|
||
assert(QT->hasUnsignedIntegerRepresentation()); | ||
return Intrinsic::dx_udot; | ||
// Return dot product intrinsic that corresponds to the QT scalar type | ||
Intrinsic::ID getDotProductIntrinsic(QualType QT) { | ||
if (QT->isFloatingType()) | ||
return Intrinsic::fdot; | ||
if (QT->isSignedIntegerType()) | ||
return Intrinsic::sdot; | ||
assert(QT->isUnsignedIntegerType()); | ||
return Intrinsic::udot; | ||
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.
|
||
} | ||
|
||
Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, | ||
|
@@ -18528,37 +18520,38 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, | |
Value *Op1 = EmitScalarExpr(E->getArg(1)); | ||
llvm::Type *T0 = Op0->getType(); | ||
llvm::Type *T1 = Op1->getType(); | ||
|
||
// If the arguments are scalars, just emit a multiply | ||
if (!T0->isVectorTy() && !T1->isVectorTy()) { | ||
if (T0->isFloatingPointTy()) | ||
return Builder.CreateFMul(Op0, Op1, "dx.dot"); | ||
return Builder.CreateFMul(Op0, Op1, "hlsl.dot"); | ||
|
||
if (T0->isIntegerTy()) | ||
return Builder.CreateMul(Op0, Op1, "dx.dot"); | ||
return Builder.CreateMul(Op0, Op1, "hlsl.dot"); | ||
|
||
// Bools should have been promoted | ||
llvm_unreachable( | ||
"Scalar dot product is only supported on ints and floats."); | ||
} | ||
// For vectors, validate types and emit the appropriate intrinsic | ||
|
||
// A VectorSplat should have happened | ||
assert(T0->isVectorTy() && T1->isVectorTy() && | ||
"Dot product of vector and scalar is not supported."); | ||
|
||
// A vector sext or sitofp should have happened | ||
assert(T0->getScalarType() == T1->getScalarType() && | ||
"Dot product of vectors need the same element types."); | ||
|
||
auto *VecTy0 = E->getArg(0)->getType()->getAs<VectorType>(); | ||
[[maybe_unused]] auto *VecTy1 = | ||
E->getArg(1)->getType()->getAs<VectorType>(); | ||
// A HLSLVectorTruncation should have happend | ||
|
||
assert(VecTy0->getElementType() == VecTy1->getElementType() && | ||
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. Switched to clang types to match signedness of integers |
||
"Dot product of vectors need the same element types."); | ||
|
||
assert(VecTy0->getNumElements() == VecTy1->getNumElements() && | ||
"Dot product requires vectors to be of the same size."); | ||
|
||
return Builder.CreateIntrinsic( | ||
/*ReturnType=*/T0->getScalarType(), | ||
getDotProductIntrinsic(E->getArg(0)->getType(), | ||
VecTy0->getNumElements()), | ||
ArrayRef<Value *>{Op0, Op1}, nullptr, "dx.dot"); | ||
getDotProductIntrinsic(VecTy0->getElementType()), | ||
ArrayRef<Value *>{Op0, Op1}, nullptr, "hlsl.dot"); | ||
} break; | ||
case Builtin::BI__builtin_hlsl_lerp: { | ||
Value *X = EmitScalarExpr(E->getArg(0)); | ||
|
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.
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.
I don't think we want to do an llvm dot intrinsic for integers. I'm pretty sure the RFC just covered the float case. I would instead do
CGM.getHLSLRuntime().getSDotIntrinsic()
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.
hmm rereading kparzysz posts in the rfc and seeing aarch64 wants integer dot seems like my comment here isn't correct. I still feel weird about it because our usages of it don't lower to a specific opcode in either the SPIRV or DXIL backends.
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.
Justin's proposal didn't say explicitly, but linked to the HLSL documentation , which explicitly includes integers. In the discussion, there was an explicit request for integer versions that no one disapproved of there.