160 lines · plain
1; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output | FileCheck %s -D#VBITS=1282; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -aarch64-sve-vector-bits-min=128 | FileCheck %s -D#VBITS=1283; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -aarch64-sve-vector-bits-min=256 | FileCheck %s -D#VBITS=2564; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -aarch64-sve-vector-bits-min=512 | FileCheck %s -D#VBITS=5125; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -aarch64-sve-vector-bits-min=1024 | FileCheck %s -D#VBITS=10246; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -aarch64-sve-vector-bits-min=2048 | FileCheck %s -D#VBITS=20487 8; VBITS represents the useful bit size of a vector register from the code9; generator's point of view. It is clamped to power-of-2 values because10; only power-of-2 vector lengths are considered legal, regardless of the11; user specified vector length.12 13target triple = "aarch64-unknown-linux-gnu"14target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"15 16; Ensure the cost of legalisation is removed as the vector length grows.17; NOTE: Assumes BaseCost_add=1, BaseCost_fadd=2.18define void @add() #0 {19; CHECK-LABEL: function 'add'20; CHECK: cost of [[#div(127,VBITS)+1]] for instruction: %add128 = add <4 x i32> undef, undef21; CHECK: cost of [[#div(255,VBITS)+1]] for instruction: %add256 = add <8 x i32> undef, undef22; CHECK: cost of [[#div(511,VBITS)+1]] for instruction: %add512 = add <16 x i32> undef, undef23; CHECK: cost of [[#div(1023,VBITS)+1]] for instruction: %add1024 = add <32 x i32> undef, undef24; CHECK: cost of [[#div(2047,VBITS)+1]] for instruction: %add2048 = add <64 x i32> undef, undef25 %add128 = add <4 x i32> undef, undef26 %add256 = add <8 x i32> undef, undef27 %add512 = add <16 x i32> undef, undef28 %add1024 = add <32 x i32> undef, undef29 %add2048 = add <64 x i32> undef, undef30 31; Using a single vector length, ensure all element types are recognised.32; CHECK: cost of [[#div(511,VBITS)+1]] for instruction: %add512.i8 = add <64 x i8> undef, undef33; CHECK: cost of [[#div(511,VBITS)+1]] for instruction: %add512.i16 = add <32 x i16> undef, undef34; CHECK: cost of [[#div(511,VBITS)+1]] for instruction: %add512.i32 = add <16 x i32> undef, undef35; CHECK: cost of [[#div(511,VBITS)+1]] for instruction: %add512.i64 = add <8 x i64> undef, undef36; CHECK: cost of [[#div(511,VBITS)+1]] for instruction: %add512.f16 = fadd <32 x half> undef, undef37; CHECK: cost of [[#div(511,VBITS)+1]] for instruction: %add512.f32 = fadd <16 x float> undef, undef38; CHECK: cost of [[#div(511,VBITS)+1]] for instruction: %add512.f64 = fadd <8 x double> undef, undef39 %add512.i8 = add <64 x i8> undef, undef40 %add512.i16 = add <32 x i16> undef, undef41 %add512.i32 = add <16 x i32> undef, undef42 %add512.i64 = add <8 x i64> undef, undef43 %add512.f16 = fadd <32 x half> undef, undef44 %add512.f32 = fadd <16 x float> undef, undef45 %add512.f64 = fadd <8 x double> undef, undef46 47 ret void48}49 50; Assuming base_cost = 251; Assuming legalization_cost = (vec_len-1/VBITS)+152; For fixed-length vectors >= 128, if element type is i8, multiply the cost by 8.53; For fixed-length vectors >= 128, if element type is i16, multiply the cost by 4.54define void @sdiv() #0 {55; CHECK-LABEL: function 'sdiv'56 57; CHECK: cost of 5 for instruction: %sdiv16.i8 = sdiv <2 x i8> undef, undef58 %sdiv16.i8 = sdiv <2 x i8> undef, undef59 60; CHECK: cost of 8 for instruction: %sdiv32.i8 = sdiv <4 x i8> undef, undef61 %sdiv32.i8 = sdiv <4 x i8> undef, undef62 63; CHECK: cost of 5 for instruction: %sdiv32.i16 = sdiv <2 x i16> undef, undef64 %sdiv32.i16 = sdiv <2 x i16> undef, undef65 66; CHECK: cost of 8 for instruction: %sdiv64.i8 = sdiv <8 x i8> undef, undef67 %sdiv64.i8 = sdiv <8 x i8> undef, undef68 69; CHECK: cost of 5 for instruction: %sdiv64.i16 = sdiv <4 x i16> undef, undef70 %sdiv64.i16 = sdiv <4 x i16> undef, undef71 72; CHECK: cost of 1 for instruction: %sdiv64.i32 = sdiv <2 x i32> undef, undef73 %sdiv64.i32 = sdiv <2 x i32> undef, undef74 75; CHECK: cost of [[#mul(mul(div(128-1, VBITS)+1, 2), 8)]] for instruction: %sdiv128.i8 = sdiv <16 x i8> undef, undef76 %sdiv128.i8 = sdiv <16 x i8> undef, undef77 78; CHECK: cost of [[#mul(mul(div(128-1, VBITS)+1, 2), 4)]] for instruction: %sdiv128.i16 = sdiv <8 x i16> undef, undef79 %sdiv128.i16 = sdiv <8 x i16> undef, undef80 81; CHECK: cost of [[#mul(div(128-1, VBITS)+1, 2)]] for instruction: %sdiv128.i64 = sdiv <2 x i64> undef, undef82 %sdiv128.i64 = sdiv <2 x i64> undef, undef83 84; CHECK: cost of [[#mul(mul(div(512-1, VBITS)+1, 2), 8)]] for instruction: %sdiv512.i8 = sdiv <64 x i8> undef, undef85 %sdiv512.i8 = sdiv <64 x i8> undef, undef86 87; CHECK: cost of [[#mul(mul(div(512-1, VBITS)+1, 2), 4)]] for instruction: %sdiv512.i16 = sdiv <32 x i16> undef, undef88 %sdiv512.i16 = sdiv <32 x i16> undef, undef89 90; CHECK: cost of [[#mul(div(512-1, VBITS)+1, 2)]] for instruction: %sdiv512.i32 = sdiv <16 x i32> undef, undef91 %sdiv512.i32 = sdiv <16 x i32> undef, undef92 93; CHECK: cost of [[#mul(div(512-1, VBITS)+1, 2)]] for instruction: %sdiv512.i64 = sdiv <8 x i64> undef, undef94 %sdiv512.i64 = sdiv <8 x i64> undef, undef95 96 ret void97}98 99; Assuming base_cost = 2100; Assuming legalization_cost = (vec_len-1/VBITS)+1101; For fixed-length vectors >= 128, if element type is i8, multiply the cost by 8.102; For fixed-length vectors >= 128, if element type is i16, multiply the cost by 4.103define void @udiv() #0 {104; CHECK-LABEL: function 'udiv'105 106; CHECK: cost of 5 for instruction: %udiv16.i8 = udiv <2 x i8> undef, undef107 %udiv16.i8 = udiv <2 x i8> undef, undef108 109; CHECK: cost of 8 for instruction: %udiv32.i8 = udiv <4 x i8> undef, undef110 %udiv32.i8 = udiv <4 x i8> undef, undef111 112; CHECK: cost of 5 for instruction: %udiv32.i16 = udiv <2 x i16> undef, undef113 %udiv32.i16 = udiv <2 x i16> undef, undef114 115; CHECK: cost of 8 for instruction: %udiv64.i8 = udiv <8 x i8> undef, undef116 %udiv64.i8 = udiv <8 x i8> undef, undef117 118; CHECK: cost of 5 for instruction: %udiv64.i16 = udiv <4 x i16> undef, undef119 %udiv64.i16 = udiv <4 x i16> undef, undef120 121; CHECK: cost of 1 for instruction: %udiv64.i32 = udiv <2 x i32> undef, undef122 %udiv64.i32 = udiv <2 x i32> undef, undef123 124; CHECK: cost of [[#mul(mul(div(128-1, VBITS)+1, 2), 8)]] for instruction: %udiv128.i8 = udiv <16 x i8> undef, undef125 %udiv128.i8 = udiv <16 x i8> undef, undef126 127; CHECK: cost of [[#mul(mul(div(128-1, VBITS)+1, 2), 4)]] for instruction: %udiv128.i16 = udiv <8 x i16> undef, undef128 %udiv128.i16 = udiv <8 x i16> undef, undef129 130; CHECK: cost of [[#mul(div(128-1, VBITS)+1, 2)]] for instruction: %udiv128.i64 = udiv <2 x i64> undef, undef131 %udiv128.i64 = udiv <2 x i64> undef, undef132 133; CHECK: cost of [[#mul(mul(div(512-1, VBITS)+1, 2), 8)]] for instruction: %udiv512.i8 = udiv <64 x i8> undef, undef134 %udiv512.i8 = udiv <64 x i8> undef, undef135 136; CHECK: cost of [[#mul(mul(div(512-1, VBITS)+1, 2), 4)]] for instruction: %udiv512.i16 = udiv <32 x i16> undef, undef137 %udiv512.i16 = udiv <32 x i16> undef, undef138 139; CHECK: cost of [[#mul(div(512-1, VBITS)+1, 2)]] for instruction: %udiv512.i32 = udiv <16 x i32> undef, undef140 %udiv512.i32 = udiv <16 x i32> undef, undef141 142; CHECK: cost of [[#mul(div(512-1, VBITS)+1, 2)]] for instruction: %udiv512.i64 = udiv <8 x i64> undef, undef143 %udiv512.i64 = udiv <8 x i64> undef, undef144 145 ret void146}147 148; The hard-coded expected cost is based on VBITS=128149define void @mul() #0 {150; CHECK: cost of [[#div(128-1, VBITS)+1]] for instruction: %mul128.i64 = mul <2 x i64> undef, undef151 %mul128.i64 = mul <2 x i64> undef, undef152 153; CHECK: cost of [[#div(512-1, VBITS)+1]] for instruction: %mul512.i64 = mul <8 x i64> undef, undef154 %mul512.i64 = mul <8 x i64> undef, undef155 156 ret void157 }158 159attributes #0 = { "target-features"="+sve" }160