-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[Scalarizer] Ensure valid VectorSplits for each struct element in visitExtractValueInst
#128538
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
Conversation
@llvm/pr-subscribers-llvm-transforms Author: Deric Cheung (Icohedron) ChangesFixes #127739 The Full diff: https://github.com/llvm/llvm-project/pull/128538.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/Scalarizer.cpp b/llvm/lib/Transforms/Scalar/Scalarizer.cpp
index 2b27150112ad8..820c8e12d2449 100644
--- a/llvm/lib/Transforms/Scalar/Scalarizer.cpp
+++ b/llvm/lib/Transforms/Scalar/Scalarizer.cpp
@@ -719,13 +719,12 @@ bool ScalarizerVisitor::splitCall(CallInst &CI) {
for (unsigned I = 1; I < CallType->getNumContainedTypes(); I++) {
std::optional<VectorSplit> CurrVS =
getVectorSplit(cast<FixedVectorType>(CallType->getContainedType(I)));
- // This case does not seem to happen, but it is possible for
- // VectorSplit.NumPacked >= NumElems. If that happens a VectorSplit
- // is not returned and we will bailout of handling this call.
- // The secondary bailout case is if NumPacked does not match.
- // This can happen if ScalarizeMinBits is not set to the default.
- // This means with certain ScalarizeMinBits intrinsics like frexp
- // will only scalarize when the struct elements have the same bitness.
+ // It is possible for VectorSplit.NumPacked >= NumElems. If that happens a
+ // VectorSplit is not returned and we will bailout of handling this call.
+ // The secondary bailout case is if NumPacked does not match. This can
+ // happen if ScalarizeMinBits is not set to the default. This means with
+ // certain ScalarizeMinBits intrinsics like frexp will only scalarize when
+ // the struct elements have the same bitness.
if (!CurrVS || CurrVS->NumPacked != VS->NumPacked)
return false;
if (isVectorIntrinsicWithStructReturnOverloadAtField(ID, I, TTI))
@@ -1083,6 +1082,18 @@ bool ScalarizerVisitor::visitExtractValueInst(ExtractValueInst &EVI) {
std::optional<VectorSplit> VS = getVectorSplit(VecType);
if (!VS)
return false;
+ for (unsigned I = 1; I < OpTy->getNumContainedTypes(); I++) {
+ std::optional<VectorSplit> CurrVS =
+ getVectorSplit(cast<FixedVectorType>(OpTy->getContainedType(I)));
+ // It is possible for VectorSplit.NumPacked >= NumElems. If that happens a
+ // VectorSplit is not returned and we will bailout of handling this call.
+ // The secondary bailout case is if NumPacked does not match. This can
+ // happen if ScalarizeMinBits is not set to the default. This means with
+ // certain ScalarizeMinBits intrinsics like frexp will only scalarize when
+ // the struct elements have the same bitness.
+ if (!CurrVS || CurrVS->NumPacked != VS->NumPacked)
+ return false;
+ }
IRBuilder<> Builder(&EVI);
Scatterer Op0 = scatter(&EVI, Op, *VS);
assert(!EVI.getIndices().empty() && "Make sure an index exists");
diff --git a/llvm/test/Transforms/Scalarizer/min-bits.ll b/llvm/test/Transforms/Scalarizer/min-bits.ll
index 97cc71626e208..377893ad7e6fd 100644
--- a/llvm/test/Transforms/Scalarizer/min-bits.ll
+++ b/llvm/test/Transforms/Scalarizer/min-bits.ll
@@ -1081,6 +1081,17 @@ define <4 x half> @call_v4f16(<4 x half> %a, <4 x half> %b) {
ret <4 x half> %r
}
+define <3 x i32> @call_v3i32(<3 x i32> %a, <3 x i32> %b) {
+; CHECK-LABEL: @call_v3i32(
+; CHECK-NEXT: [[T:%.*]] = call { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32> [[A:%.*]], <3 x i32> [[B:%.*]])
+; CHECK-NEXT: [[R:%.*]] = extractvalue { <3 x i32>, <3 x i1> } [[T]], 0
+; CHECK-NEXT: ret <3 x i32> [[R]]
+;
+ %t = call { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32> %a, <3 x i32> %b)
+ %r = extractvalue { <3 x i32>, <3 x i1> } %t, 0
+ ret <3 x i32> %r
+}
+
declare <2 x half> @llvm.minnum.v2f16(<2 x half>, <2 x half>)
declare <3 x half> @llvm.minnum.v3f16(<3 x half>, <3 x half>)
declare <4 x half> @llvm.minnum.v4f16(<4 x half>, <4 x half>)
|
005b51b
to
f488e44
Compare
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.
LGTM.
…sitExtractValueInst` (llvm#128538) Fixes llvm#127739 The `visitExtractValueInst` is missing a check that was present in `splitCall` / `visitCallInst`. This check ensures that each struct element has a VectorSplit, and that each VectorSplit contains the same number of elements packed per fragment. --------- Co-authored-by: Jay Foad <[email protected]>
Fixes #127739
The
visitExtractValueInst
is missing a check that was present insplitCall
/visitCallInst
.This check ensures that each struct element has a VectorSplit, and that each VectorSplit contains the same number of elements packed per fragment.