14178e334SSimon Pilgrim; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -mtriple=systemz-unknown -mcpu=z13 \ 20f0a8b77SUlrich Weigand; RUN: | FileCheck %s -check-prefixes=CHECK,Z13 34178e334SSimon Pilgrim; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -mtriple=systemz-unknown -mcpu=z15 \ 4819c1651SUlrich Weigand; RUN: | FileCheck %s -check-prefixes=CHECK,Z15 596782c2cSJonas Paulsson 6*964565f4SJonas Paulssondefine void @bswap_i128(i128 %arg) { 7*964565f4SJonas Paulsson; CHECK: function 'bswap_i128' 8*964565f4SJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp = tail call i128 @llvm.bswap.i128(i128 %arg) 9*964565f4SJonas Paulsson %swp = tail call i128 @llvm.bswap.i128(i128 %arg) 10*964565f4SJonas Paulsson ret void 11*964565f4SJonas Paulsson} 12*964565f4SJonas Paulsson 1396782c2cSJonas Paulssondefine void @bswap_i64(i64 %arg, <2 x i64> %arg2) { 1415ba588dSArthur Eubanks; CHECK: function 'bswap_i64' 1596782c2cSJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp1 = tail call i64 1696782c2cSJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp2 = tail call <2 x i64> 1796782c2cSJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %swp4 = tail call <4 x i64> 1896782c2cSJonas Paulsson %swp1 = tail call i64 @llvm.bswap.i64(i64 %arg) 1996782c2cSJonas Paulsson %swp2 = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %arg2) 2096782c2cSJonas Paulsson %swp4 = tail call <4 x i64> @llvm.bswap.v4i64(<4 x i64> undef) 2196782c2cSJonas Paulsson ret void 2296782c2cSJonas Paulsson} 2396782c2cSJonas Paulsson 2496782c2cSJonas Paulssondefine void @bswap_i32(i32 %arg, <2 x i32> %arg2, <4 x i32> %arg4) { 2515ba588dSArthur Eubanks; CHECK: function 'bswap_i32' 2696782c2cSJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp1 = tail call i32 2796782c2cSJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp2 = tail call <2 x i32> 2896782c2cSJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp4 = tail call <4 x i32> 2996782c2cSJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %swp8 = tail call <8 x i32> 3096782c2cSJonas Paulsson %swp1 = tail call i32 @llvm.bswap.i32(i32 %arg) 3196782c2cSJonas Paulsson %swp2 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %arg2) 3296782c2cSJonas Paulsson %swp4 = tail call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %arg4) 3396782c2cSJonas Paulsson %swp8 = tail call <8 x i32> @llvm.bswap.v8i32(<8 x i32> undef) 3496782c2cSJonas Paulsson ret void 3596782c2cSJonas Paulsson} 3696782c2cSJonas Paulsson 3796782c2cSJonas Paulssondefine void @bswap_i16(i16 %arg, <2 x i16> %arg2, <4 x i16> %arg4, 3896782c2cSJonas Paulsson <8 x i16> %arg8) { 3915ba588dSArthur Eubanks; CHECK: function 'bswap_i16' 4096782c2cSJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp1 = tail call i16 @llvm.bswap.i16(i16 %arg) 4196782c2cSJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp2 = tail call <2 x i16> @llvm.bswap.v2i16(<2 x i16> %arg2) 4296782c2cSJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp4 = tail call <4 x i16> @llvm.bswap.v4i16(<4 x i16> %arg4) 4396782c2cSJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp8 = tail call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %arg8) 4496782c2cSJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %swp16 = tail call <16 x i16> @llvm.bswap.v16i16(<16 x i16> undef) 4596782c2cSJonas Paulsson %swp1 = tail call i16 @llvm.bswap.i16(i16 %arg) 4696782c2cSJonas Paulsson %swp2 = tail call <2 x i16> @llvm.bswap.v2i16(<2 x i16> %arg2) 4796782c2cSJonas Paulsson %swp4 = tail call <4 x i16> @llvm.bswap.v4i16(<4 x i16> %arg4) 4896782c2cSJonas Paulsson %swp8 = tail call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %arg8) 4996782c2cSJonas Paulsson %swp16 = tail call <16 x i16> @llvm.bswap.v16i16(<16 x i16> undef) 5096782c2cSJonas Paulsson ret void 5196782c2cSJonas Paulsson} 5296782c2cSJonas Paulsson 535da8e432SJonas Paulsson; Test that store/load reversed is reflected in costs. 5468c50b11SNikita Popovdefine void @bswap_i64_mem(ptr %src, i64 %arg, ptr %dst) { 5515ba588dSArthur Eubanks; CHECK: function 'bswap_i64_mem' 5668c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %Ld1 = load i64, ptr %src 575da8e432SJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp1 = tail call i64 @llvm.bswap.i64(i64 %Ld1) 585da8e432SJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp2 = tail call i64 @llvm.bswap.i64(i64 %arg) 5968c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 0 for instruction: store i64 %swp2, ptr %dst 6068c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %Ld2 = load i64, ptr %src 615da8e432SJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp3 = tail call i64 @llvm.bswap.i64(i64 %Ld2) 6268c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 0 for instruction: store i64 %swp3, ptr %dst 6368c50b11SNikita Popov %Ld1 = load i64, ptr %src 645da8e432SJonas Paulsson %swp1 = tail call i64 @llvm.bswap.i64(i64 %Ld1) 655da8e432SJonas Paulsson 665da8e432SJonas Paulsson %swp2 = tail call i64 @llvm.bswap.i64(i64 %arg) 6768c50b11SNikita Popov store i64 %swp2, ptr %dst 685da8e432SJonas Paulsson 6968c50b11SNikita Popov %Ld2 = load i64, ptr %src 705da8e432SJonas Paulsson %swp3 = tail call i64 @llvm.bswap.i64(i64 %Ld2) 7168c50b11SNikita Popov store i64 %swp3, ptr %dst 725da8e432SJonas Paulsson 735da8e432SJonas Paulsson ret void 745da8e432SJonas Paulsson} 755da8e432SJonas Paulsson 7668c50b11SNikita Popovdefine void @bswap_v2i64_mem(ptr %src, <2 x i64> %arg, ptr %dst) { 7715ba588dSArthur Eubanks; CHECK:function 'bswap_v2i64_mem' 7868c50b11SNikita Popov; Z13: Cost Model: Found an estimated cost of 1 for instruction: %Ld1 = load <2 x i64>, ptr %src 7968c50b11SNikita Popov; Z15: Cost Model: Found an estimated cost of 0 for instruction: %Ld1 = load <2 x i64>, ptr %src 800f0a8b77SUlrich Weigand; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp1 = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %Ld1) 810f0a8b77SUlrich Weigand; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp2 = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %arg) 8268c50b11SNikita Popov; Z13: Cost Model: Found an estimated cost of 1 for instruction: store <2 x i64> %swp2, ptr %dst 8368c50b11SNikita Popov; Z15: Cost Model: Found an estimated cost of 0 for instruction: store <2 x i64> %swp2, ptr %dst 8468c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %Ld2 = load <2 x i64>, ptr %src 850f0a8b77SUlrich Weigand; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp3 = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %Ld2) 8668c50b11SNikita Popov; Z13: Cost Model: Found an estimated cost of 1 for instruction: store <2 x i64> %swp3, ptr %dst 8768c50b11SNikita Popov; Z15: Cost Model: Found an estimated cost of 0 for instruction: store <2 x i64> %swp3, ptr %dst 880f0a8b77SUlrich Weigand 8968c50b11SNikita Popov %Ld1 = load <2 x i64>, ptr %src 900f0a8b77SUlrich Weigand %swp1 = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %Ld1) 910f0a8b77SUlrich Weigand 920f0a8b77SUlrich Weigand %swp2 = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %arg) 9368c50b11SNikita Popov store <2 x i64> %swp2, ptr %dst 940f0a8b77SUlrich Weigand 9568c50b11SNikita Popov %Ld2 = load <2 x i64>, ptr %src 960f0a8b77SUlrich Weigand %swp3 = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %Ld2) 9768c50b11SNikita Popov store <2 x i64> %swp3, ptr %dst 980f0a8b77SUlrich Weigand 990f0a8b77SUlrich Weigand ret void 1000f0a8b77SUlrich Weigand} 1010f0a8b77SUlrich Weigand 10268c50b11SNikita Popovdefine void @bswap_i32_mem(ptr %src, i32 %arg, ptr %dst) { 10315ba588dSArthur Eubanks; CHECK: function 'bswap_i32_mem' 10468c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %Ld1 = load i32, ptr %src 1055da8e432SJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp1 = tail call i32 @llvm.bswap.i32(i32 %Ld1) 1065da8e432SJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp2 = tail call i32 @llvm.bswap.i32(i32 %arg) 10768c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 0 for instruction: store i32 %swp2, ptr %dst 10868c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %Ld2 = load i32, ptr %src 1095da8e432SJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp3 = tail call i32 @llvm.bswap.i32(i32 %Ld2) 11068c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 0 for instruction: store i32 %swp3, ptr %dst 11168c50b11SNikita Popov %Ld1 = load i32, ptr %src 1125da8e432SJonas Paulsson %swp1 = tail call i32 @llvm.bswap.i32(i32 %Ld1) 1135da8e432SJonas Paulsson 1145da8e432SJonas Paulsson %swp2 = tail call i32 @llvm.bswap.i32(i32 %arg) 11568c50b11SNikita Popov store i32 %swp2, ptr %dst 1165da8e432SJonas Paulsson 11768c50b11SNikita Popov %Ld2 = load i32, ptr %src 1185da8e432SJonas Paulsson %swp3 = tail call i32 @llvm.bswap.i32(i32 %Ld2) 11968c50b11SNikita Popov store i32 %swp3, ptr %dst 1205da8e432SJonas Paulsson 1215da8e432SJonas Paulsson ret void 1225da8e432SJonas Paulsson} 1235da8e432SJonas Paulsson 12468c50b11SNikita Popovdefine void @bswap_v4i32_mem(ptr %src, <4 x i32> %arg, ptr %dst) { 12515ba588dSArthur Eubanks; CHECK: function 'bswap_v4i32_mem' 12668c50b11SNikita Popov; Z13: Cost Model: Found an estimated cost of 1 for instruction: %Ld1 = load <4 x i32>, ptr %src 12768c50b11SNikita Popov; Z15: Cost Model: Found an estimated cost of 0 for instruction: %Ld1 = load <4 x i32>, ptr %src 1280f0a8b77SUlrich Weigand; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp1 = tail call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %Ld1) 1290f0a8b77SUlrich Weigand; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp2 = tail call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %arg) 13068c50b11SNikita Popov; Z13: Cost Model: Found an estimated cost of 1 for instruction: store <4 x i32> %swp2, ptr %dst 13168c50b11SNikita Popov; Z15: Cost Model: Found an estimated cost of 0 for instruction: store <4 x i32> %swp2, ptr %dst 13268c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %Ld2 = load <4 x i32>, ptr %src 1330f0a8b77SUlrich Weigand; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp3 = tail call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %Ld2) 13468c50b11SNikita Popov; Z13: Cost Model: Found an estimated cost of 1 for instruction: store <4 x i32> %swp3, ptr %dst 13568c50b11SNikita Popov; Z15: Cost Model: Found an estimated cost of 0 for instruction: store <4 x i32> %swp3, ptr %dst 13668c50b11SNikita Popov%Ld1 = load <4 x i32>, ptr %src 1370f0a8b77SUlrich Weigand %swp1 = tail call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %Ld1) 1380f0a8b77SUlrich Weigand 1390f0a8b77SUlrich Weigand %swp2 = tail call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %arg) 14068c50b11SNikita Popov store <4 x i32> %swp2, ptr %dst 1410f0a8b77SUlrich Weigand 14268c50b11SNikita Popov %Ld2 = load <4 x i32>, ptr %src 1430f0a8b77SUlrich Weigand %swp3 = tail call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %Ld2) 14468c50b11SNikita Popov store <4 x i32> %swp3, ptr %dst 1450f0a8b77SUlrich Weigand 1460f0a8b77SUlrich Weigand ret void 1470f0a8b77SUlrich Weigand} 1480f0a8b77SUlrich Weigand 14968c50b11SNikita Popovdefine void @bswap_i16_mem(ptr %src, i16 %arg, ptr %dst) { 15015ba588dSArthur Eubanks; CHECK: function 'bswap_i16_mem' 15168c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 0 for instruction: %Ld1 = load i16, ptr %src 1525da8e432SJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp1 = tail call i16 @llvm.bswap.i16(i16 %Ld1) 1535da8e432SJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp2 = tail call i16 @llvm.bswap.i16(i16 %arg) 15468c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 0 for instruction: store i16 %swp2, ptr %dst 15568c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %Ld2 = load i16, ptr %src 1565da8e432SJonas Paulsson; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp3 = tail call i16 @llvm.bswap.i16(i16 %Ld2) 15768c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 0 for instruction: store i16 %swp3, ptr %dst 15868c50b11SNikita Popov %Ld1 = load i16, ptr %src 1595da8e432SJonas Paulsson %swp1 = tail call i16 @llvm.bswap.i16(i16 %Ld1) 1605da8e432SJonas Paulsson 1615da8e432SJonas Paulsson %swp2 = tail call i16 @llvm.bswap.i16(i16 %arg) 16268c50b11SNikita Popov store i16 %swp2, ptr %dst 1635da8e432SJonas Paulsson 16468c50b11SNikita Popov %Ld2 = load i16, ptr %src 1655da8e432SJonas Paulsson %swp3 = tail call i16 @llvm.bswap.i16(i16 %Ld2) 16668c50b11SNikita Popov store i16 %swp3, ptr %dst 1675da8e432SJonas Paulsson 1685da8e432SJonas Paulsson ret void 1695da8e432SJonas Paulsson} 1705da8e432SJonas Paulsson 17168c50b11SNikita Popovdefine void @bswap_v8i16_mem(ptr %src, <8 x i16> %arg, ptr %dst) { 17215ba588dSArthur Eubanks; CHECK: function 'bswap_v8i16_mem' 17368c50b11SNikita Popov; Z13: Cost Model: Found an estimated cost of 1 for instruction: %Ld1 = load <8 x i16>, ptr %src 17468c50b11SNikita Popov; Z15: Cost Model: Found an estimated cost of 0 for instruction: %Ld1 = load <8 x i16>, ptr %src 1750f0a8b77SUlrich Weigand; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp1 = tail call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %Ld1) 1760f0a8b77SUlrich Weigand; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp2 = tail call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %arg) 17768c50b11SNikita Popov; Z13: Cost Model: Found an estimated cost of 1 for instruction: store <8 x i16> %swp2, ptr %dst 17868c50b11SNikita Popov; Z15: Cost Model: Found an estimated cost of 0 for instruction: store <8 x i16> %swp2, ptr %dst 17968c50b11SNikita Popov; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %Ld2 = load <8 x i16>, ptr %src 1800f0a8b77SUlrich Weigand; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %swp3 = tail call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %Ld2) 18168c50b11SNikita Popov; Z13: Cost Model: Found an estimated cost of 1 for instruction: store <8 x i16> %swp3, ptr %dst 18268c50b11SNikita Popov; Z15: Cost Model: Found an estimated cost of 0 for instruction: store <8 x i16> %swp3, ptr %dst 18368c50b11SNikita Popov%Ld1 = load <8 x i16>, ptr %src 1840f0a8b77SUlrich Weigand %swp1 = tail call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %Ld1) 1850f0a8b77SUlrich Weigand 1860f0a8b77SUlrich Weigand %swp2 = tail call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %arg) 18768c50b11SNikita Popov store <8 x i16> %swp2, ptr %dst 1880f0a8b77SUlrich Weigand 18968c50b11SNikita Popov %Ld2 = load <8 x i16>, ptr %src 1900f0a8b77SUlrich Weigand %swp3 = tail call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %Ld2) 19168c50b11SNikita Popov store <8 x i16> %swp3, ptr %dst 1920f0a8b77SUlrich Weigand 1930f0a8b77SUlrich Weigand ret void 1940f0a8b77SUlrich Weigand} 19596782c2cSJonas Paulsson 196*964565f4SJonas Paulssondeclare i128 @llvm.bswap.i128(i128) 197*964565f4SJonas Paulsson 19896782c2cSJonas Paulssondeclare i64 @llvm.bswap.i64(i64) 19996782c2cSJonas Paulssondeclare <2 x i64> @llvm.bswap.v2i64(<2 x i64>) 20096782c2cSJonas Paulssondeclare <4 x i64> @llvm.bswap.v4i64(<4 x i64>) 20196782c2cSJonas Paulsson 20296782c2cSJonas Paulssondeclare i32 @llvm.bswap.i32(i32) 20396782c2cSJonas Paulssondeclare <2 x i32> @llvm.bswap.v2i32(<2 x i32>) 20496782c2cSJonas Paulssondeclare <4 x i32> @llvm.bswap.v4i32(<4 x i32>) 20596782c2cSJonas Paulssondeclare <8 x i32> @llvm.bswap.v8i32(<8 x i32>) 20696782c2cSJonas Paulsson 20796782c2cSJonas Paulssondeclare i16 @llvm.bswap.i16(i16) 20896782c2cSJonas Paulssondeclare <2 x i16> @llvm.bswap.v2i16(<2 x i16>) 20996782c2cSJonas Paulssondeclare <4 x i16> @llvm.bswap.v4i16(<4 x i16>) 21096782c2cSJonas Paulssondeclare <8 x i16> @llvm.bswap.v8i16(<8 x i16>) 21196782c2cSJonas Paulssondeclare <16 x i16> @llvm.bswap.v16i16(<16 x i16>) 212