Skip to content

Commit a50d573

Browse files
committed
!fixup address comments, thanks!
1 parent 972bfc3 commit a50d573

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
@@ -1782,15 +1782,18 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
17821782
// Try to convert a vector zext feeding only extracts to a set of scalar (Src
17831783
// << ExtIdx *Size) & (Size -1), if profitable.
17841784
auto *Ext = cast<ZExtInst>(&I);
1785-
auto *SrcTy = cast<FixedVectorType>(Ext->getOperand(0)->getType());
1785+
auto *SrcTy = dyn_cast<FixedVectorType>(Ext->getOperand(0)->getType());
1786+
if (!SrcTy)
1787+
return false;
17861788
auto *DstTy = cast<FixedVectorType>(Ext->getType());
17871789

1788-
if (DL->getTypeSizeInBits(SrcTy) !=
1789-
DL->getTypeSizeInBits(DstTy->getElementType()))
1790+
Type *ScalarDstTy = DstTy->getElementType();
1791+
if (DL->getTypeSizeInBits(SrcTy) != DL->getTypeSizeInBits(ScalarDstTy))
17901792
return false;
17911793

1792-
InstructionCost VectorCost = TTI.getCastInstrCost(
1793-
Instruction::ZExt, DstTy, SrcTy, TTI::CastContextHint::None, CostKind);
1794+
InstructionCost VectorCost =
1795+
TTI.getCastInstrCost(Instruction::ZExt, DstTy, SrcTy,
1796+
TTI::CastContextHint::None, CostKind, Ext);
17941797
unsigned ExtCnt = 0;
17951798
bool ExtLane0 = false;
17961799
for (User *U : Ext->users()) {
@@ -1805,15 +1808,13 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
18051808
CostKind, Idx->getZExtValue(), U);
18061809
}
18071810

1808-
Type *ScalarDstTy = DstTy->getElementType();
18091811
InstructionCost ScalarCost =
18101812
ExtCnt * TTI.getArithmeticInstrCost(
18111813
Instruction::And, ScalarDstTy, CostKind,
18121814
{TTI::OK_AnyValue, TTI::OP_None},
18131815
{TTI::OK_NonUniformConstantValue, TTI::OP_None}) +
18141816
(ExtCnt - ExtLane0) *
18151817
TTI.getArithmeticInstrCost(
1816-
18171818
Instruction::LShr, ScalarDstTy, CostKind,
18181819
{TTI::OK_AnyValue, TTI::OP_None},
18191820
{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)