[PATCH] D107254: [VectorUtils] Teach findScalarElement to return splat value.
Sander de Smalen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 2 03:09:15 PDT 2021
sdesmalen updated this revision to Diff 363421.
sdesmalen added a comment.
Changed `undef` -> `poison` in test.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107254/new/
https://reviews.llvm.org/D107254
Files:
llvm/lib/Analysis/VectorUtils.cpp
llvm/test/Transforms/InstCombine/vscale_extractelement.ll
Index: llvm/test/Transforms/InstCombine/vscale_extractelement.ll
===================================================================
--- llvm/test/Transforms/InstCombine/vscale_extractelement.ll
+++ llvm/test/Transforms/InstCombine/vscale_extractelement.ll
@@ -243,6 +243,21 @@
ret i8 %1
}
+define i64* @ext_lane_from_bitcast_of_splat(i32* %v) {
+; CHECK-LABEL: @ext_lane_from_bitcast_of_splat(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[R:%.*]] = bitcast i32* [[V:%.*]] to i64*
+; CHECK-NEXT: ret i64* [[R]]
+;
+entry:
+ %in = insertelement <vscale x 4 x i32*> poison, i32* %v, i32 0
+ %splat = shufflevector <vscale x 4 x i32*> %in, <vscale x 4 x i32*> poison, <vscale x 4 x i32> zeroinitializer
+ %bc = bitcast <vscale x 4 x i32*> %splat to <vscale x 4 x i64*>
+ %r = extractelement <vscale x 4 x i64*> %bc, i32 3
+ ret i64* %r
+}
+
+
declare <vscale x 4 x i64> @llvm.experimental.stepvector.nxv4i64()
declare <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
declare <vscale x 512 x i8> @llvm.experimental.stepvector.nxv512i8()
Index: llvm/lib/Analysis/VectorUtils.cpp
===================================================================
--- llvm/lib/Analysis/VectorUtils.cpp
+++ llvm/lib/Analysis/VectorUtils.cpp
@@ -323,6 +323,12 @@
return findScalarElement(SVI->getOperand(1), InEl - LHSWidth);
}
+ // If the vector is a splat then we can trivially find the scalar element.
+ if (isa<ScalableVectorType>(VTy))
+ if (Value *Splat = getSplatValue(V))
+ if (EltNo < VTy->getElementCount().getKnownMinValue())
+ return Splat;
+
// Extract a value from a vector add operation with a constant zero.
// TODO: Use getBinOpIdentity() to generalize this.
Value *Val; Constant *C;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107254.363421.patch
Type: text/x-patch
Size: 1738 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210802/c81b6630/attachment.bin>
More information about the llvm-commits
mailing list