Skip to content

Commit a693db9

Browse files
committed
!fixup address comments, thanks!
1 parent 0d3c067 commit a693db9

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,15 +1778,18 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
17781778
// Try to convert a vector zext feeding only extracts to a set of scalar (Src
17791779
// << ExtIdx *Size) & (Size -1), if profitable.
17801780
auto *Ext = cast<ZExtInst>(&I);
1781-
auto *SrcTy = cast<FixedVectorType>(Ext->getOperand(0)->getType());
1781+
auto *SrcTy = dyn_cast<FixedVectorType>(Ext->getOperand(0)->getType());
1782+
if (!SrcTy)
1783+
return false;
17821784
auto *DstTy = cast<FixedVectorType>(Ext->getType());
17831785

1784-
if (DL->getTypeSizeInBits(SrcTy) !=
1785-
DL->getTypeSizeInBits(DstTy->getElementType()))
1786+
Type *ScalarDstTy = DstTy->getElementType();
1787+
if (DL->getTypeSizeInBits(SrcTy) != DL->getTypeSizeInBits(ScalarDstTy))
17861788
return false;
17871789

1788-
InstructionCost VectorCost = TTI.getCastInstrCost(
1789-
Instruction::ZExt, DstTy, SrcTy, TTI::CastContextHint::None, CostKind);
1790+
InstructionCost VectorCost =
1791+
TTI.getCastInstrCost(Instruction::ZExt, DstTy, SrcTy,
1792+
TTI::CastContextHint::None, CostKind, Ext);
17901793
unsigned ExtCnt = 0;
17911794
bool ExtLane0 = false;
17921795
for (User *U : Ext->users()) {
@@ -1801,15 +1804,13 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
18011804
CostKind, Idx->getZExtValue(), U);
18021805
}
18031806

1804-
Type *ScalarDstTy = DstTy->getElementType();
18051807
InstructionCost ScalarCost =
18061808
ExtCnt * TTI.getArithmeticInstrCost(
18071809
Instruction::And, ScalarDstTy, CostKind,
18081810
{TTI::OK_AnyValue, TTI::OP_None},
18091811
{TTI::OK_NonUniformConstantValue, TTI::OP_None}) +
18101812
(ExtCnt - ExtLane0) *
18111813
TTI.getArithmeticInstrCost(
1812-
18131814
Instruction::LShr, ScalarDstTy, CostKind,
18141815
{TTI::OK_AnyValue, TTI::OP_None},
18151816
{TTI::OK_NonUniformConstantValue, TTI::OP_None});

llvm/test/Transforms/VectorCombine/AArch64/ext-extract.ll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,32 @@ entry:
329329
call void @use.i64(i64 %ext.1)
330330
ret void
331331
}
332+
333+
define void @zext_nv4i8_all_lanes_used(<vscale x 4 x i8> %src) {
334+
; CHECK-LABEL: define void @zext_nv4i8_all_lanes_used(
335+
; CHECK-SAME: <vscale x 4 x i8> [[SRC:%.*]]) {
336+
; CHECK-NEXT: [[ENTRY:.*:]]
337+
; CHECK-NEXT: [[EXT9:%.*]] = zext nneg <vscale x 4 x i8> [[SRC]] to <vscale x 4 x i32>
338+
; CHECK-NEXT: [[EXT_0:%.*]] = extractelement <vscale x 4 x i32> [[EXT9]], i64 0
339+
; CHECK-NEXT: [[EXT_1:%.*]] = extractelement <vscale x 4 x i32> [[EXT9]], i64 1
340+
; CHECK-NEXT: [[EXT_2:%.*]] = extractelement <vscale x 4 x i32> [[EXT9]], i64 2
341+
; CHECK-NEXT: [[EXT_3:%.*]] = extractelement <vscale x 4 x i32> [[EXT9]], i64 3
342+
; CHECK-NEXT: call void @use.i32(i32 [[EXT_0]])
343+
; CHECK-NEXT: call void @use.i32(i32 [[EXT_1]])
344+
; CHECK-NEXT: call void @use.i32(i32 [[EXT_2]])
345+
; CHECK-NEXT: call void @use.i32(i32 [[EXT_3]])
346+
; CHECK-NEXT: ret void
347+
;
348+
entry:
349+
%ext9 = zext nneg <vscale x 4 x i8> %src to <vscale x 4 x i32>
350+
%ext.0 = extractelement <vscale x 4 x i32> %ext9, i64 0
351+
%ext.1 = extractelement <vscale x 4 x i32> %ext9, i64 1
352+
%ext.2 = extractelement <vscale x 4 x i32> %ext9, i64 2
353+
%ext.3 = extractelement <vscale x 4 x i32> %ext9, i64 3
354+
355+
call void @use.i32(i32 %ext.0)
356+
call void @use.i32(i32 %ext.1)
357+
call void @use.i32(i32 %ext.2)
358+
call void @use.i32(i32 %ext.3)
359+
ret void
360+
}

0 commit comments

Comments
 (0)