-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[VectorCombine] Avoid inserting freeze when scalarizing extend-extract if all extracts would lead to UB on poison. #164683
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
Changes from 2 commits
553cfa8
b8b84d2
78259eb
4b931b5
610cc37
c197ff6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2017,8 +2017,24 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) { | |
|
|
||
| Value *ScalarV = Ext->getOperand(0); | ||
| if (!isGuaranteedNotToBePoison(ScalarV, &AC, dyn_cast<Instruction>(ScalarV), | ||
| &DT)) | ||
| ScalarV = Builder.CreateFreeze(ScalarV); | ||
| &DT)) { | ||
| // Check if all lanes are extracted and all extracts trigger UB on poison. | ||
| // If so, we do not need to insert a freeze. | ||
| SmallDenseSet<uint64_t, 8> ExtractedLanes; | ||
| bool AllExtractsHaveUB = true; | ||
| for (User *U : Ext->users()) { | ||
| auto *Extract = cast<ExtractElementInst>(U); | ||
| uint64_t Idx = | ||
| cast<ConstantInt>(Extract->getIndexOperand())->getZExtValue(); | ||
| ExtractedLanes.insert(Idx); | ||
| if (!programUndefinedIfPoison(Extract)) { | ||
| AllExtractsHaveUB = false; | ||
| break; | ||
| } | ||
| } | ||
|
||
| if (!AllExtractsHaveUB || ExtractedLanes.size() != SrcTy->getNumElements()) | ||
dtcxzyw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ScalarV = Builder.CreateFreeze(ScalarV); | ||
| } | ||
| ScalarV = Builder.CreateBitCast( | ||
| ScalarV, | ||
| IntegerType::get(SrcTy->getContext(), DL->getTypeSizeInBits(SrcTy))); | ||
|
|
||
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 is under the assumption that the extract will be executed. The extract might be conditionally executed in a different block. I think the rest of the code does not exclude that possibility?
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.
At least initially, it should probably be enough to restrict this to cases where the extracts are in the same block as the extend, and they are guaranteed to execute, if the extend executes
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.
Yes, thanks! I added checks that the extracts are in the same block as the extend and that they are executed, and tests showing the freeze will still be inserted if those checks fail.