[llvm] [X86][CostModel] Add per-shape gather/scatter cost tables for AMD znver4+ (PR #199488)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 6 23:18:32 PDT 2026
================
@@ -0,0 +1,152 @@
+; RUN: opt < %s -S -mtriple=x86_64-unknown-linux-gnu \
+; RUN: -passes="print<cost-model>" -disable-output -cost-kind=throughput \
+; RUN: -mcpu=znver4 2>&1 | FileCheck %s --check-prefix=THROUGHPUT
+; RUN: opt < %s -S -mtriple=x86_64-unknown-linux-gnu \
+; RUN: -passes="print<cost-model>" -disable-output -cost-kind=code-size \
+; RUN: -mcpu=znver4 2>&1 | FileCheck %s --check-prefix=SIZE
+
+; Irregular widths are padded or split into the power-of-two gather shapes
+; emitted by CodeGen instead of falling back to the flat generic cost.
+
+define <3 x i32> @gather_v3i32(<3 x ptr> %ptrs, <3 x i1> %mask) {
+; THROUGHPUT-LABEL: 'gather_v3i32'
+; THROUGHPUT: Cost Model: Found an estimated cost of 12 for instruction: %v = call
+; SIZE-LABEL: 'gather_v3i32'
+; SIZE: Cost Model: Found an estimated cost of 1 for instruction: %v = call
+ %v = call <3 x i32> @llvm.masked.gather.v3i32.v3p0(<3 x ptr> %ptrs, i32 4, <3 x i1> %mask, <3 x i32> poison)
+ ret <3 x i32> %v
+}
+
+define <5 x i32> @gather_v5i32(<5 x ptr> %ptrs, <5 x i1> %mask) {
+; THROUGHPUT-LABEL: 'gather_v5i32'
+; THROUGHPUT: Cost Model: Found an estimated cost of 26 for instruction: %v = call
+; SIZE-LABEL: 'gather_v5i32'
+; SIZE: Cost Model: Found an estimated cost of 1 for instruction: %v = call
+ %v = call <5 x i32> @llvm.masked.gather.v5i32.v5p0(<5 x ptr> %ptrs, i32 4, <5 x i1> %mask, <5 x i32> poison)
+ ret <5 x i32> %v
+}
+
+define <6 x i32> @gather_v6i32(<6 x ptr> %ptrs, <6 x i1> %mask) {
+; THROUGHPUT-LABEL: 'gather_v6i32'
+; THROUGHPUT: Cost Model: Found an estimated cost of 26 for instruction: %v = call
+; SIZE-LABEL: 'gather_v6i32'
+; SIZE: Cost Model: Found an estimated cost of 1 for instruction: %v = call
+ %v = call <6 x i32> @llvm.masked.gather.v6i32.v6p0(<6 x ptr> %ptrs, i32 4, <6 x i1> %mask, <6 x i32> poison)
+ ret <6 x i32> %v
+}
+
+define <7 x i32> @gather_v7i32(<7 x ptr> %ptrs, <7 x i1> %mask) {
+; THROUGHPUT-LABEL: 'gather_v7i32'
+; THROUGHPUT: Cost Model: Found an estimated cost of 26 for instruction: %v = call
+; SIZE-LABEL: 'gather_v7i32'
+; SIZE: Cost Model: Found an estimated cost of 1 for instruction: %v = call
+ %v = call <7 x i32> @llvm.masked.gather.v7i32.v7p0(<7 x ptr> %ptrs, i32 4, <7 x i1> %mask, <7 x i32> poison)
+ ret <7 x i32> %v
+}
+
+define <12 x i32> @gather_v12i32(<12 x ptr> %ptrs, <12 x i1> %mask) {
+; THROUGHPUT-LABEL: 'gather_v12i32'
+; THROUGHPUT: Cost Model: Found an estimated cost of 52 for instruction: %v = call
+; SIZE-LABEL: 'gather_v12i32'
+; SIZE: Cost Model: Found an estimated cost of 2 for instruction: %v = call
+ %v = call <12 x i32> @llvm.masked.gather.v12i32.v12p0(<12 x ptr> %ptrs, i32 4, <12 x i1> %mask, <12 x i32> poison)
+ ret <12 x i32> %v
+}
+
+define <24 x i32> @gather_v24i32(<24 x ptr> %ptrs, <24 x i1> %mask) {
+; THROUGHPUT-LABEL: 'gather_v24i32'
+; THROUGHPUT: Cost Model: Found an estimated cost of 78 for instruction: %v = call
+; SIZE-LABEL: 'gather_v24i32'
+; SIZE: Cost Model: Found an estimated cost of 3 for instruction: %v = call
+ %v = call <24 x i32> @llvm.masked.gather.v24i32.v24p0(<24 x ptr> %ptrs, i32 4, <24 x i1> %mask, <24 x i32> poison)
+ ret <24 x i32> %v
+}
+
+define void @scatter_v24i32(<24 x i32> %src, <24 x ptr> %ptrs, <24 x i1> %mask) {
+; THROUGHPUT-LABEL: 'scatter_v24i32'
+; THROUGHPUT: Cost Model: Found an estimated cost of 75 for instruction: call void
+; SIZE-LABEL: 'scatter_v24i32'
+; SIZE: Cost Model: Found an estimated cost of 3 for instruction: call void
+ call void @llvm.masked.scatter.v24i32.v24p0(<24 x i32> %src, <24 x ptr> %ptrs, i32 4, <24 x i1> %mask)
+ ret void
+}
+
+; The schedule model distinguishes dword and qword indices. Ensure TTI selects
+; the encoding that matches the GEP rather than one based only on data width.
+
+define <8 x i32> @gather_v8i32_i32_index(ptr %base, <8 x i32> %index, <8 x i1> %mask) {
+; THROUGHPUT-LABEL: 'gather_v8i32_i32_index'
+; THROUGHPUT: Cost Model: Found an estimated cost of 25 for instruction: %v = call
+; SIZE-LABEL: 'gather_v8i32_i32_index'
+; SIZE: Cost Model: Found an estimated cost of 1 for instruction: %v = call
+ %ptrs = getelementptr i32, ptr %base, <8 x i32> %index
+ %v = call <8 x i32> @llvm.masked.gather.v8i32.v8p0(<8 x ptr> %ptrs, i32 4, <8 x i1> %mask, <8 x i32> poison)
+ ret <8 x i32> %v
+}
+
+define <8 x i32> @gather_v8i32_i64_index(ptr %base, <8 x i64> %index, <8 x i1> %mask) {
+; THROUGHPUT-LABEL: 'gather_v8i32_i64_index'
+; THROUGHPUT: Cost Model: Found an estimated cost of 26 for instruction: %v = call
+; SIZE-LABEL: 'gather_v8i32_i64_index'
+; SIZE: Cost Model: Found an estimated cost of 1 for instruction: %v = call
+ %ptrs = getelementptr i32, ptr %base, <8 x i64> %index
+ %v = call <8 x i32> @llvm.masked.gather.v8i32.v8p0(<8 x ptr> %ptrs, i32 4, <8 x i1> %mask, <8 x i32> poison)
+ ret <8 x i32> %v
+}
+
+define void @scatter_v8i64_i32_index(<8 x i64> %src, ptr %base, <8 x i32> %index, <8 x i1> %mask) {
+; THROUGHPUT-LABEL: 'scatter_v8i64_i32_index'
+; THROUGHPUT: Cost Model: Found an estimated cost of 32 for instruction: call void
+; SIZE-LABEL: 'scatter_v8i64_i32_index'
+; SIZE: Cost Model: Found an estimated cost of 1 for instruction: call void
+ %ptrs = getelementptr i64, ptr %base, <8 x i32> %index
+ call void @llvm.masked.scatter.v8i64.v8p0(<8 x i64> %src, <8 x ptr> %ptrs, i32 8, <8 x i1> %mask)
+ ret void
+}
+
+define void @scatter_v8i64_i64_index(<8 x i64> %src, ptr %base, <8 x i64> %index, <8 x i1> %mask) {
+; THROUGHPUT-LABEL: 'scatter_v8i64_i64_index'
+; THROUGHPUT: Cost Model: Found an estimated cost of 35 for instruction: call void
+; SIZE-LABEL: 'scatter_v8i64_i64_index'
+; SIZE: Cost Model: Found an estimated cost of 1 for instruction: call void
+ %ptrs = getelementptr i64, ptr %base, <8 x i64> %index
+ call void @llvm.masked.scatter.v8i64.v8p0(<8 x i64> %src, <8 x ptr> %ptrs, i32 8, <8 x i1> %mask)
+ ret void
+}
+
+; Exercise function-level vector-width attributes while checking that a native
----------------
MattPD wrote:
Confirmed: The test now distinguishes the attribute-driven decomposition from the attribute-free control.
https://github.com/llvm/llvm-project/pull/199488
More information about the llvm-commits
mailing list