[PATCH] D112318: [InstCombine] Extend pattern to replace shuffle's insertelement operand
Piotr Sobczak via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 3 01:44:15 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG03961709edd1: [InstCombine] Extend pattern to replace shuffle's insertelement operand (authored by piotr).
Changed prior to commit:
https://reviews.llvm.org/D112318?vs=381555&id=384360#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112318/new/
https://reviews.llvm.org/D112318
Files:
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
Index: llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
===================================================================
--- llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
+++ llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
@@ -696,7 +696,7 @@
; CHECK-LABEL: @insert_undemanded_element_unequal_length_op0(
; CHECK-NEXT: [[INS:%.*]] = insertelement <4 x float> [[X:%.*]], float 4.200000e+01, i32 3
; CHECK-NEXT: call void @use(<4 x float> [[INS]])
-; CHECK-NEXT: [[S:%.*]] = shufflevector <4 x float> [[INS]], <4 x float> [[Y:%.*]], <5 x i32> <i32 undef, i32 0, i32 7, i32 1, i32 4>
+; CHECK-NEXT: [[S:%.*]] = shufflevector <4 x float> [[X]], <4 x float> [[Y:%.*]], <5 x i32> <i32 undef, i32 0, i32 7, i32 1, i32 4>
; CHECK-NEXT: ret <5 x float> [[S]]
;
%ins = insertelement <4 x float> %x, float 42.0, i32 3
@@ -709,7 +709,7 @@
; CHECK-LABEL: @insert_undemanded_element_unequal_length_op1(
; CHECK-NEXT: [[INS:%.*]] = insertelement <4 x float> [[X:%.*]], float 4.200000e+01, i32 3
; CHECK-NEXT: call void @use(<4 x float> [[INS]])
-; CHECK-NEXT: [[S:%.*]] = shufflevector <4 x float> [[Y:%.*]], <4 x float> [[INS]], <5 x i32> <i32 undef, i32 3, i32 2, i32 1, i32 4>
+; CHECK-NEXT: [[S:%.*]] = shufflevector <4 x float> [[Y:%.*]], <4 x float> [[X]], <5 x i32> <i32 undef, i32 3, i32 2, i32 1, i32 4>
; CHECK-NEXT: ret <5 x float> [[S]]
;
%ins = insertelement <4 x float> %x, float 42.0, i32 3
Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2268,12 +2268,8 @@
SmallVector<int, 16> Mask;
Shuf.getShuffleMask(Mask);
- // The shuffle must not change vector sizes.
- // TODO: This restriction could be removed if the insert has only one use
- // (because the transform would require a new length-changing shuffle).
int NumElts = Mask.size();
- if (NumElts != (int)(cast<FixedVectorType>(V0->getType())->getNumElements()))
- return nullptr;
+ int InpNumElts = cast<FixedVectorType>(V0->getType())->getNumElements();
// This is a specialization of a fold in SimplifyDemandedVectorElts. We may
// not be able to handle it there if the insertelement has >1 use.
@@ -2290,11 +2286,16 @@
if (match(V1, m_InsertElt(m_Value(X), m_Value(), m_ConstantInt(IdxC)))) {
// Offset the index constant by the vector width because we are checking for
// accesses to the 2nd vector input of the shuffle.
- IdxC += NumElts;
+ IdxC += InpNumElts;
// shuf ?, (inselt X, ?, IdxC), Mask --> shuf ?, X, Mask
if (!is_contained(Mask, (int)IdxC))
return IC.replaceOperand(Shuf, 1, X);
}
+ // For the rest of the transform, the shuffle must not change vector sizes.
+ // TODO: This restriction could be removed if the insert has only one use
+ // (because the transform would require a new length-changing shuffle).
+ if (NumElts != InpNumElts)
+ return nullptr;
// shuffle (insert ?, Scalar, IndexC), V1, Mask --> insert V1, Scalar, IndexC'
auto isShufflingScalarIntoOp1 = [&](Value *&Scalar, ConstantInt *&IndexC) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112318.384360.patch
Type: text/x-patch
Size: 3269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211103/ae56752b/attachment.bin>
More information about the llvm-commits
mailing list