Skip to content

Commit 08f074a

Browse files
authored
[TTI] getInstructionCost - consistently treat all undef/poison shuffle masks as free (#146039)
#145920 exposed an issue where we were treating undef/poison shuffles as SK_Select kinds
1 parent 5f2b9dd commit 08f074a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,10 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
15341534
ArrayRef<int> Mask = Shuffle->getShuffleMask();
15351535
int NumSubElts, SubIndex;
15361536

1537+
// Treat undef/poison mask as free (no matter the length).
1538+
if (all_of(Mask, [](int M) { return M < 0; }))
1539+
return TTI::TCC_Free;
1540+
15371541
// TODO: move more of this inside improveShuffleKindFromMask.
15381542
if (Shuffle->changesLength()) {
15391543
// Treat a 'subvector widening' as a free shuffle.

llvm/test/Analysis/CostModel/X86/alternate-shuffle-cost.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,3 +758,22 @@ define <32 x i8> @test_v32i8_3(<32 x i8> %a, <32 x i8> %b) {
758758
%1 = shufflevector <32 x i8> %a, <32 x i8> %b, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 36, i32 5, i32 38, i32 7, i32 40, i32 9, i32 42, i32 11, i32 44, i32 13, i32 46, i32 15, i32 48, i32 17, i32 50, i32 19, i32 52, i32 21, i32 54, i32 23, i32 56, i32 25, i32 58, i32 27, i32 60, i32 61, i32 62, i32 63>
759759
ret <32 x i8> %1
760760
}
761+
762+
; Treat all undef/poison shuffle masks as free.
763+
define <2 x i32> @test_v2i32_poison(<2 x i32> %a0, <2 x i32> %a1) {
764+
; CHECK-LABEL: 'test_v2i32_poison'
765+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %s = shufflevector <2 x i32> %a0, <2 x i32> %a1, <2 x i32> poison
766+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %s
767+
;
768+
%s = shufflevector <2 x i32> %a0, <2 x i32> %a1, <2 x i32> poison
769+
ret <2 x i32> %s
770+
}
771+
772+
define <4 x float> @test_v4f32_v2f32_poison(<2 x float> %a0, <2 x float> %a1) {
773+
; CHECK-LABEL: 'test_v4f32_v2f32_poison'
774+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %s = shufflevector <2 x float> %a0, <2 x float> %a1, <4 x i32> poison
775+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <4 x float> %s
776+
;
777+
%s = shufflevector <2 x float> %a0, <2 x float> %a1, <4 x i32> poison
778+
ret <4 x float> %s
779+
}

0 commit comments

Comments
 (0)