Skip to content

Commit 6662e45

Browse files
committed
Include shuffle arguments to improve cost analysis; remove undef tests
1 parent 647bfbd commit 6662e45

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,11 +2999,11 @@ bool VectorCombine::foldPermuteOfIntrinsic(Instruction &I) {
29992999
InstructionCost OldCost =
30003000
TTI.getIntrinsicInstrCost(IntrinsicCostAttributes(IID, *II0), CostKind) +
30013001
TTI.getShuffleCost(TargetTransformInfo::SK_PermuteSingleSrc, ShuffleDstTy,
3002-
IntrinsicSrcTy, Mask, CostKind);
3002+
IntrinsicSrcTy, Mask, CostKind, 0, nullptr, {V0, V1},
3003+
&I);
30033004

30043005
SmallVector<Type *> NewArgsTy;
30053006
InstructionCost NewCost = 0;
3006-
30073007
for (unsigned I = 0, E = II0->arg_size(); I != E; ++I) {
30083008
if (isVectorIntrinsicWithScalarOpAtArg(IID, I, &TTI)) {
30093009
NewArgsTy.push_back(II0->getArgOperand(I)->getType());
@@ -3013,7 +3013,8 @@ bool VectorCombine::foldPermuteOfIntrinsic(Instruction &I) {
30133013
ShuffleDstTy->getNumElements());
30143014
NewArgsTy.push_back(ArgTy);
30153015
NewCost += TTI.getShuffleCost(TargetTransformInfo::SK_PermuteSingleSrc,
3016-
ArgTy, VecTy, Mask, CostKind);
3016+
ArgTy, VecTy, Mask, CostKind, 0, nullptr,
3017+
{II0->getArgOperand(I)});
30173018
}
30183019
}
30193020
IntrinsicCostAttributes NewAttr(IID, ShuffleDstTy, NewArgsTy);

llvm/test/Transforms/VectorCombine/AArch64/shuffle-of-intrinsic-permute.ll

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; RUN: opt -passes=vector-combine -S -mtriple=aarch64 %s | FileCheck %s
33

44
; This file tests the foldPermuteOfIntrinsic optimization which transforms:
5-
; shuffle(intrinsic(args), poison/undef) -> intrinsic(shuffle(args))
5+
; shuffle(intrinsic(args), poison) -> intrinsic(shuffle(args))
66
; when the shuffle is a permute (operates on single vector) and cost model
77
; determines the transformation is beneficial.
88

@@ -82,18 +82,6 @@ define <8 x i16> @extract_lower_i16(<16 x i16> %v1, <16 x i16> %v2) {
8282
ret <8 x i16> %result
8383
}
8484

85-
define <4 x i32> @extract_lower_with_undef(<8 x i32> %v1, <8 x i32> %v2) {
86-
; CHECK-LABEL: @extract_lower_with_undef(
87-
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[V1:%.*]], <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
88-
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x i32> [[V2:%.*]], <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
89-
; CHECK-NEXT: [[RESULT:%.*]] = call <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> [[TMP1]], <4 x i32> [[TMP2]])
90-
; CHECK-NEXT: ret <4 x i32> [[RESULT]]
91-
;
92-
%sat = call <8 x i32> @llvm.sadd.sat.v8i32(<8 x i32> %v1, <8 x i32> %v2)
93-
%result = shufflevector <8 x i32> %sat, <8 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
94-
ret <4 x i32> %result
95-
}
96-
9785
;; ============================================================================
9886
;; Negative Tests - Should NOT Optimize
9987
;; ============================================================================

0 commit comments

Comments
 (0)