Skip to content

Commit 09c6867

Browse files
committed
!fixup address comments, thanks!
1 parent c7b6b71 commit 09c6867

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
@@ -1718,15 +1718,18 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
17181718
// Try to convert a vector zext feeding only extracts to a set of scalar (Src
17191719
// << ExtIdx *Size) & (Size -1), if profitable.
17201720
auto *Ext = cast<ZExtInst>(&I);
1721-
auto *SrcTy = cast<FixedVectorType>(Ext->getOperand(0)->getType());
1721+
auto *SrcTy = dyn_cast<FixedVectorType>(Ext->getOperand(0)->getType());
1722+
if (!SrcTy)
1723+
return false;
17221724
auto *DstTy = cast<FixedVectorType>(Ext->getType());
17231725

1724-
if (DL->getTypeSizeInBits(SrcTy) !=
1725-
DL->getTypeSizeInBits(DstTy->getElementType()))
1726+
Type *ScalarDstTy = DstTy->getElementType();
1727+
if (DL->getTypeSizeInBits(SrcTy) != DL->getTypeSizeInBits(ScalarDstTy))
17261728
return false;
17271729

1728-
InstructionCost VectorCost = TTI.getCastInstrCost(
1729-
Instruction::ZExt, DstTy, SrcTy, TTI::CastContextHint::None, CostKind);
1730+
InstructionCost VectorCost =
1731+
TTI.getCastInstrCost(Instruction::ZExt, DstTy, SrcTy,
1732+
TTI::CastContextHint::None, CostKind, Ext);
17301733
unsigned ExtCnt = 0;
17311734
bool ExtLane0 = false;
17321735
for (User *U : Ext->users()) {
@@ -1741,15 +1744,13 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
17411744
CostKind, Idx->getZExtValue(), U);
17421745
}
17431746

1744-
Type *ScalarDstTy = DstTy->getElementType();
17451747
InstructionCost ScalarCost =
17461748
ExtCnt * TTI.getArithmeticInstrCost(
17471749
Instruction::And, ScalarDstTy, CostKind,
17481750
{TTI::OK_AnyValue, TTI::OP_None},
17491751
{TTI::OK_NonUniformConstantValue, TTI::OP_None}) +
17501752
(ExtCnt - ExtLane0) *
17511753
TTI.getArithmeticInstrCost(
1752-
17531754
Instruction::LShr, ScalarDstTy, CostKind,
17541755
{TTI::OK_AnyValue, TTI::OP_None},
17551756
{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)