-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[IR] Add new CreateVectorInterleave interface #150931
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 1 commit
Commits
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2194,11 +2194,10 @@ Value *ComplexDeinterleavingGraph::replaceNode(IRBuilderBase &Builder, | |
| // Splats that are not constant are interleaved where they are located | ||
| Instruction *InsertPoint = (I->comesBefore(R) ? R : I)->getNextNode(); | ||
| IRBuilder<> IRB(InsertPoint); | ||
| ReplacementNode = IRB.CreateIntrinsic(Intrinsic::vector_interleave2, | ||
| NewTy, {Node->Real, Node->Imag}); | ||
|
Contributor
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. Looks like NewTy & NewMaskTy are unused now.
Contributor
Author
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. Yep. #151100 |
||
| ReplacementNode = IRB.CreateVectorInterleave({Node->Real, Node->Imag}); | ||
| } else { | ||
| ReplacementNode = Builder.CreateIntrinsic( | ||
| Intrinsic::vector_interleave2, NewTy, {Node->Real, Node->Imag}); | ||
| ReplacementNode = | ||
| Builder.CreateVectorInterleave({Node->Real, Node->Imag}); | ||
| } | ||
| break; | ||
| } | ||
|
|
@@ -2228,8 +2227,7 @@ Value *ComplexDeinterleavingGraph::replaceNode(IRBuilderBase &Builder, | |
| auto *B = replaceNode(Builder, Node->Operands[1]); | ||
| auto *NewMaskTy = VectorType::getDoubleElementsVectorType( | ||
| cast<VectorType>(MaskReal->getType())); | ||
| auto *NewMask = Builder.CreateIntrinsic(Intrinsic::vector_interleave2, | ||
| NewMaskTy, {MaskReal, MaskImag}); | ||
| auto *NewMask = Builder.CreateVectorInterleave({MaskReal, MaskImag}); | ||
| ReplacementNode = Builder.CreateSelect(NewMask, A, B); | ||
| break; | ||
| } | ||
|
|
@@ -2260,8 +2258,8 @@ void ComplexDeinterleavingGraph::processReductionSingle( | |
| } | ||
|
|
||
| if (!NewInit) | ||
| NewInit = Builder.CreateIntrinsic(Intrinsic::vector_interleave2, NewVTy, | ||
| {Init, Constant::getNullValue(VTy)}); | ||
| NewInit = | ||
| Builder.CreateVectorInterleave({Init, Constant::getNullValue(VTy)}); | ||
|
|
||
| NewPHI->addIncoming(NewInit, Incoming); | ||
| NewPHI->addIncoming(OperationReplacement, BackEdge); | ||
|
|
@@ -2289,8 +2287,7 @@ void ComplexDeinterleavingGraph::processReductionOperation( | |
| Value *InitImag = OldPHIImag->getIncomingValueForBlock(Incoming); | ||
|
|
||
| IRBuilder<> Builder(Incoming->getTerminator()); | ||
| auto *NewInit = Builder.CreateIntrinsic(Intrinsic::vector_interleave2, NewVTy, | ||
| {InitReal, InitImag}); | ||
| auto *NewInit = Builder.CreateVectorInterleave({InitReal, InitImag}); | ||
|
|
||
| NewPHI->addIncoming(NewInit, Incoming); | ||
| NewPHI->addIncoming(OperationReplacement, BackEdge); | ||
|
|
||
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.
This code should not be in IRBuilder folders, but rather part of the generic intrinsic ConstantFolding support.
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'm not sure I understand. Do you mean that I shouldn't be changing any of the folders whatsoever, or that I should be doing something like this in TargetFolder:
I thought the standard practice in IRBuilder was to apply folds using the folder, i.e. like we do here:
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 can't use the pre-existing
FoldBinaryIntrinsicorFoldUnaryIntrinsicfunctions either because the number of operands is variable, although I'm happy to add aFoldUnaryIntrinsic.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.
You probably want to replace FoldBinaryIntrinsic with FoldIntrinsic -- we shouldn't specialize to binary. This is going to need a small bit of refactoring in ConstantFolding to expose a ConstantFoldIntrinsic function instead of ConstantFoldBinaryIntrinsic.
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.
OK thanks for the pointer, I'll take a look!
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.
The places where I'd like to see these constant folds happening are where we're using a default version of IRBuilder, which uses ConstantFolder. However, the ConstantFolder.h version of FoldBinaryIntrinsic says the caller should be using TargetFolder or InstSimplifyFolder instead. So I could change FoldBinaryIntrinsic in llvm/Analysis/ConstantFolding.h (used by TargetFolder.h), but then I wouldn't see any improvements in generated code for IRBuilder instances using the default version.
To be honest, I'm not really sure the best way to proceed now. Would it be acceptable to add a variant of FoldIntrinsic to ConstantFolder.h as well, or is the preferred solution to just change all the IRBuilder instances I care about to use the TargetFolder instead?
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.
Using TargetFolder is generally preferred. (The whole TargetFolder vs ConstantFolder is an annoying legacy split, that's unfortunately not entirely straightforward to remove.)
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 guess we need a
llvm::ConstantFoldBinaryIntrinsicin ConstantFolding.cpp, and call that from both ConstantFolder.h and InstructionSimplify.cpp'sConstantFoldInstOperandsImpl? That would bring it inline with the other the other instruction types.And we probably need to rename that to just ConstantFoldIntrinsic?
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 can do that because llvm/include/llvm/IR/ConstantFolder.h only includes llvm/IR/ConstantFold.h, whereas I think what you're talking about is trying to reuse an intrinsic folding function in the Analysis directory.
I'll abandon the constant folds for now, because if I only add support in the TargetFolder the only way I could test it is via unit tests, since both the loop vectoriser and the complex interleaving pass use the default IRBuilder, which uses ConstantFolder. I care more about adding the CreateVectorInterleave interface - I just saw an opportunity to tidy up the IR but it turns out to be far too complicated to do all in one patch.