[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 01:57:33 PDT 2021
sdesmalen created this revision.
Herald added a subscriber: hiraditya.
sdesmalen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
If the vector is a splat of some scalar value, findScalarElement()
can simply return the scalar value if it knows the requested lane
is in the vector.
This is only needed for scalable vectors, because the InsertElement/ShuffleVector
case is already handled explicitly for the fixed-width case.
This helps to recognize an InstCombine fold like:
extractelt(bitcast(splat(%v))) -> bitcast(%v)
Repository:
rG LLVM Github Monorepo
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*> undef, i32* %v, i32 0
+ %splat = shufflevector <vscale x 4 x i32*> %in, <vscale x 4 x i32*> undef, <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.363402.patch
Type: text/x-patch
Size: 1736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210802/fc52fc2c/attachment.bin>
More information about the llvm-commits
mailing list