[PATCH] D107966: [SLP]Do not emit extract elements for insertelements users, replace with shuffles directly.

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 26 05:37:57 PDT 2021


lebedev.ri added inline comments.


================
Comment at: llvm/test/Transforms/SLPVectorizer/X86/remark_extract_broadcast.ll:19-20
 ; CHECK-NEXT:    [[P7:%.*]] = getelementptr inbounds i16, i16* [[PTR]], i64 7
-; CHECK-NEXT:    [[TMP0:%.*]] = extractelement <8 x i16> [[LD]], i32 0
-; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <8 x i16> poison, i16 [[TMP0]], i32 0
-; CHECK-NEXT:    [[SHUFFLE:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 0, i32 undef, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>
-; CHECK-NEXT:    [[TMP2:%.*]] = add <8 x i16> [[LD]], [[SHUFFLE]]
-; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i16* [[P0]] to <8 x i16>*
-; CHECK-NEXT:    store <8 x i16> [[TMP2]], <8 x i16>* [[TMP3]], align 2
+; CHECK-NEXT:    [[TMP0:%.*]] = shufflevector <8 x i16> [[LD]], <8 x i16> poison, <8 x i32> <i32 0, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
+; CHECK-NEXT:    [[SHUFFLE:%.*]] = shufflevector <8 x i16> [[TMP0]], <8 x i16> poison, <8 x i32> <i32 0, i32 undef, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>
+; CHECK-NEXT:    [[TMP1:%.*]] = add <8 x i16> [[LD]], [[SHUFFLE]]
----------------
ABataev wrote:
> lebedev.ri wrote:
> > Thanks! This is clearly an improvement, but these two shuffles are still clearly redundant, 
> > because in either case, you end up with 0'th element of `LD` in some elements of output.
> > In this case you could simply drop the first shuffle, and do the second one directly.
> I think, in codegen the first shuffle will be simply dropped (this is an identity shuffle). But I'll check what can be improved here.
Ignoring more complicated cases, perhaps the key point **here**
is that the `TMP0` is an identity (=>single-source), non-width-changing shuffle,
so it can be naturally dropped. `ShuffleVectorInst::isIdentityMask()` might be relevant.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107966/new/

https://reviews.llvm.org/D107966



More information about the llvm-commits mailing list