[llvm] 833b33a - [NFC][X86][CostModel] Add tests for byteswap intrinsic

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed May 5 10:12:25 PDT 2021


Author: Roman Lebedev
Date: 2021-05-05T20:11:46+03:00
New Revision: 833b33a7f4dc1d1f1a75bb3e04dee7ce8ed22f06

URL: https://github.com/llvm/llvm-project/commit/833b33a7f4dc1d1f1a75bb3e04dee7ce8ed22f06
DIFF: https://github.com/llvm/llvm-project/commit/833b33a7f4dc1d1f1a75bb3e04dee7ce8ed22f06.diff

LOG: [NFC][X86][CostModel] Add tests for byteswap intrinsic

Added: 
    llvm/test/Analysis/CostModel/X86/bswap-store.ll
    llvm/test/Analysis/CostModel/X86/bswap-vec.ll
    llvm/test/Analysis/CostModel/X86/load-bswap.ll

Modified: 
    llvm/test/Analysis/CostModel/X86/bswap.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/CostModel/X86/bswap-store.ll b/llvm/test/Analysis/CostModel/X86/bswap-store.ll
new file mode 100644
index 000000000000..2cc21a721004
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/X86/bswap-store.ll
@@ -0,0 +1,147 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze | FileCheck %s --check-prefixes=ALL,NOMOVBE,X64
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+movbe | FileCheck %s --check-prefixes=ALL,MOVBE,X64
+; RUN: opt < %s -mtriple=i686-unknown-linux-gnu -cost-model -analyze | FileCheck %s --check-prefixes=ALL,NOMOVBE,X86
+; RUN: opt < %s -mtriple=i686-unknown-linux-gnu -cost-model -analyze -mattr=+movbe | FileCheck %s --check-prefixes=ALL,MOVBE,X86
+
+declare i16 @llvm.bswap.i16(i16)
+declare i32 @llvm.bswap.i32(i32)
+declare i64 @llvm.bswap.i64(i64)
+declare i128 @llvm.bswap.i128(i128)
+
+define void @var_bswap_store_i16(i16 %a, i16* %dst) {
+; NOMOVBE-LABEL: 'var_bswap_store_i16'
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 10 for instruction: %bswap = call i16 @llvm.bswap.i16(i16 %a)
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: store i16 %bswap, i16* %dst, align 1
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+; MOVBE-LABEL: 'var_bswap_store_i16'
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i16 @llvm.bswap.i16(i16 %a)
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: store i16 %bswap, i16* %dst, align 1
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  %bswap = call i16 @llvm.bswap.i16(i16 %a)
+  store i16 %bswap, i16* %dst, align 1
+
+  ret void
+}
+define void @var_bswap_store_i16_extrause(i16 %a, i16* %dst) {
+; NOMOVBE-LABEL: 'var_bswap_store_i16_extrause'
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 10 for instruction: %bswap = call i16 @llvm.bswap.i16(i16 %a)
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: store i16 %bswap, i16* %dst, align 1
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap2 = shl i16 %bswap, 2
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+; MOVBE-LABEL: 'var_bswap_store_i16_extrause'
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i16 @llvm.bswap.i16(i16 %a)
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: store i16 %bswap, i16* %dst, align 1
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap2 = shl i16 %bswap, 2
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  %bswap = call i16 @llvm.bswap.i16(i16 %a)
+  store i16 %bswap, i16* %dst, align 1
+
+  %bswap2 = shl i16 %bswap, 2 ; incur an extra use to the bswap
+
+  ret void
+}
+
+define void @var_bswap_store_i32(i32 %a, i32* %dst) {
+; ALL-LABEL: 'var_bswap_store_i32'
+; ALL-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i32 @llvm.bswap.i32(i32 %a)
+; ALL-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: store i32 %bswap, i32* %dst, align 1
+; ALL-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  %bswap = call i32 @llvm.bswap.i32(i32 %a)
+  store i32 %bswap, i32* %dst, align 1
+
+  ret void
+}
+define void @var_bswap_store_i32_extrause(i32 %a, i32* %dst) {
+; ALL-LABEL: 'var_bswap_store_i32_extrause'
+; ALL-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i32 @llvm.bswap.i32(i32 %a)
+; ALL-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: store i32 %bswap, i32* %dst, align 1
+; ALL-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap2 = shl i32 %bswap, 2
+; ALL-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  %bswap = call i32 @llvm.bswap.i32(i32 %a)
+  store i32 %bswap, i32* %dst, align 1
+
+  %bswap2 = shl i32 %bswap, 2 ; incur an extra use to the bswap
+
+  ret void
+}
+
+define void @var_bswap_store_i64(i64 %a, i64* %dst) {
+; X64-LABEL: 'var_bswap_store_i64'
+; X64-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i64 @llvm.bswap.i64(i64 %a)
+; X64-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: store i64 %bswap, i64* %dst, align 1
+; X64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+; X86-LABEL: 'var_bswap_store_i64'
+; X86-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call i64 @llvm.bswap.i64(i64 %a)
+; X86-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: store i64 %bswap, i64* %dst, align 1
+; X86-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  %bswap = call i64 @llvm.bswap.i64(i64 %a)
+  store i64 %bswap, i64* %dst, align 1
+
+  ret void
+}
+define void @var_bswap_store_i64_extrause(i64 %a, i64* %dst) {
+; X64-LABEL: 'var_bswap_store_i64_extrause'
+; X64-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i64 @llvm.bswap.i64(i64 %a)
+; X64-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: store i64 %bswap, i64* %dst, align 1
+; X64-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap2 = shl i64 %bswap, 2
+; X64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+; X86-LABEL: 'var_bswap_store_i64_extrause'
+; X86-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call i64 @llvm.bswap.i64(i64 %a)
+; X86-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: store i64 %bswap, i64* %dst, align 1
+; X86-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap2 = shl i64 %bswap, 2
+; X86-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  %bswap = call i64 @llvm.bswap.i64(i64 %a)
+  store i64 %bswap, i64* %dst, align 1
+
+  %bswap2 = shl i64 %bswap, 2 ; incur an extra use to the bswap
+
+  ret void
+}
+
+define void @var_bswap_store_i128(i128 %a, i128* %dst) {
+; X64-LABEL: 'var_bswap_store_i128'
+; X64-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call i128 @llvm.bswap.i128(i128 %a)
+; X64-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: store i128 %bswap, i128* %dst, align 1
+; X64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+; X86-LABEL: 'var_bswap_store_i128'
+; X86-NEXT:  Cost Model: Found an estimated cost of 8 for instruction: %bswap = call i128 @llvm.bswap.i128(i128 %a)
+; X86-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: store i128 %bswap, i128* %dst, align 1
+; X86-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  %bswap = call i128 @llvm.bswap.i128(i128 %a)
+  store i128 %bswap, i128* %dst, align 1
+
+  ret void
+}
+define void @var_bswap_store_i128_extrause(i128 %a, i128* %dst) {
+; X64-LABEL: 'var_bswap_store_i128_extrause'
+; X64-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call i128 @llvm.bswap.i128(i128 %a)
+; X64-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: store i128 %bswap, i128* %dst, align 1
+; X64-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap2 = shl i128 %bswap, 2
+; X64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+; X86-LABEL: 'var_bswap_store_i128_extrause'
+; X86-NEXT:  Cost Model: Found an estimated cost of 8 for instruction: %bswap = call i128 @llvm.bswap.i128(i128 %a)
+; X86-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: store i128 %bswap, i128* %dst, align 1
+; X86-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap2 = shl i128 %bswap, 2
+; X86-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  %bswap = call i128 @llvm.bswap.i128(i128 %a)
+  store i128 %bswap, i128* %dst, align 1
+
+  %bswap2 = shl i128 %bswap, 2 ; incur an extra use to the bswap
+
+  ret void
+}

diff  --git a/llvm/test/Analysis/CostModel/X86/bswap-vec.ll b/llvm/test/Analysis/CostModel/X86/bswap-vec.ll
new file mode 100644
index 000000000000..c8d1ddf656a7
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/X86/bswap-vec.ll
@@ -0,0 +1,131 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+sse2 | FileCheck %s -check-prefixes=SSE2
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+sse4.2 | FileCheck %s -check-prefixes=SSE42
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+avx | FileCheck %s -check-prefixes=AVX,AVX1
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+avx2 | FileCheck %s -check-prefixes=AVX,AVX2
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+xop,+avx | FileCheck %s -check-prefixes=AVX,AVX1
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+xop,+avx2 | FileCheck %s -check-prefixes=AVX,AVX2
+
+; Verify the cost of vector bswap instructions.
+
+declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
+declare <4 x i32> @llvm.bswap.v4i32(<4 x i32>)
+declare <8 x i16> @llvm.bswap.v8i16(<8 x i16>)
+
+declare <4 x i64> @llvm.bswap.v4i64(<4 x i64>)
+declare <8 x i32> @llvm.bswap.v8i32(<8 x i32>)
+declare <16 x i16> @llvm.bswap.v16i16(<16 x i16>)
+
+define <2 x i64> @var_bswap_v2i64(<2 x i64> %a) {
+; SSE2-LABEL: 'var_bswap_v2i64'
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 7 for instruction: %bswap = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %a)
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i64> %bswap
+;
+; SSE42-LABEL: 'var_bswap_v2i64'
+; SSE42-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %a)
+; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i64> %bswap
+;
+; AVX-LABEL: 'var_bswap_v2i64'
+; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %a)
+; AVX-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i64> %bswap
+;
+  %bswap = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %a)
+  ret <2 x i64> %bswap
+}
+
+define <4 x i64> @var_bswap_v4i64(<4 x i64> %a) {
+; SSE2-LABEL: 'var_bswap_v4i64'
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 14 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
+;
+; SSE42-LABEL: 'var_bswap_v4i64'
+; SSE42-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
+; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
+;
+; AVX1-LABEL: 'var_bswap_v4i64'
+; AVX1-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
+; AVX1-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
+;
+; AVX2-LABEL: 'var_bswap_v4i64'
+; AVX2-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
+; AVX2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
+;
+  %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
+  ret <4 x i64> %bswap
+}
+
+define <4 x i32> @var_bswap_v4i32(<4 x i32> %a) {
+; SSE2-LABEL: 'var_bswap_v4i32'
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 7 for instruction: %bswap = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i32> %bswap
+;
+; SSE42-LABEL: 'var_bswap_v4i32'
+; SSE42-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
+; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i32> %bswap
+;
+; AVX-LABEL: 'var_bswap_v4i32'
+; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
+; AVX-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i32> %bswap
+;
+  %bswap = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
+  ret <4 x i32> %bswap
+}
+
+define <8 x i32> @var_bswap_v8i32(<8 x i32> %a) {
+; SSE2-LABEL: 'var_bswap_v8i32'
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 14 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
+;
+; SSE42-LABEL: 'var_bswap_v8i32'
+; SSE42-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
+; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
+;
+; AVX1-LABEL: 'var_bswap_v8i32'
+; AVX1-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
+; AVX1-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
+;
+; AVX2-LABEL: 'var_bswap_v8i32'
+; AVX2-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
+; AVX2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
+;
+  %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
+  ret <8 x i32> %bswap
+}
+
+define <8 x i16> @var_bswap_v8i16(<8 x i16> %a) {
+; SSE2-LABEL: 'var_bswap_v8i16'
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 7 for instruction: %bswap = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %a)
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i16> %bswap
+;
+; SSE42-LABEL: 'var_bswap_v8i16'
+; SSE42-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %a)
+; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i16> %bswap
+;
+; AVX-LABEL: 'var_bswap_v8i16'
+; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %a)
+; AVX-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i16> %bswap
+;
+  %bswap = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %a)
+  ret <8 x i16> %bswap
+}
+
+define <16 x i16> @var_bswap_v16i16(<16 x i16> %a) {
+; SSE2-LABEL: 'var_bswap_v16i16'
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 14 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
+; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
+;
+; SSE42-LABEL: 'var_bswap_v16i16'
+; SSE42-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
+; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
+;
+; AVX1-LABEL: 'var_bswap_v16i16'
+; AVX1-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
+; AVX1-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
+;
+; AVX2-LABEL: 'var_bswap_v16i16'
+; AVX2-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
+; AVX2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
+;
+  %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
+  ret <16 x i16> %bswap
+}

diff  --git a/llvm/test/Analysis/CostModel/X86/bswap.ll b/llvm/test/Analysis/CostModel/X86/bswap.ll
index c8d1ddf656a7..940838d8fdc9 100644
--- a/llvm/test/Analysis/CostModel/X86/bswap.ll
+++ b/llvm/test/Analysis/CostModel/X86/bswap.ll
@@ -1,131 +1,60 @@
 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
-; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+sse2 | FileCheck %s -check-prefixes=SSE2
-; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+sse4.2 | FileCheck %s -check-prefixes=SSE42
-; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+avx | FileCheck %s -check-prefixes=AVX,AVX1
-; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+avx2 | FileCheck %s -check-prefixes=AVX,AVX2
-; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+xop,+avx | FileCheck %s -check-prefixes=AVX,AVX1
-; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+xop,+avx2 | FileCheck %s -check-prefixes=AVX,AVX2
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze | FileCheck %s --check-prefixes=ALL,NOMOVBE,X64
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+movbe | FileCheck %s --check-prefixes=ALL,MOVBE,X64
+; RUN: opt < %s -mtriple=i686-unknown-linux-gnu -cost-model -analyze | FileCheck %s --check-prefixes=ALL,NOMOVBE,X86
+; RUN: opt < %s -mtriple=i686-unknown-linux-gnu -cost-model -analyze -mattr=+movbe | FileCheck %s --check-prefixes=ALL,MOVBE,X86
 
-; Verify the cost of vector bswap instructions.
+declare i16 @llvm.bswap.i16(i16)
+declare i32 @llvm.bswap.i32(i32)
+declare i64 @llvm.bswap.i64(i64)
+declare i128 @llvm.bswap.i128(i128)
 
-declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
-declare <4 x i32> @llvm.bswap.v4i32(<4 x i32>)
-declare <8 x i16> @llvm.bswap.v8i16(<8 x i16>)
+; Verify the cost of scalar bswap instructions.
 
-declare <4 x i64> @llvm.bswap.v4i64(<4 x i64>)
-declare <8 x i32> @llvm.bswap.v8i32(<8 x i32>)
-declare <16 x i16> @llvm.bswap.v16i16(<16 x i16>)
-
-define <2 x i64> @var_bswap_v2i64(<2 x i64> %a) {
-; SSE2-LABEL: 'var_bswap_v2i64'
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 7 for instruction: %bswap = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %a)
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i64> %bswap
-;
-; SSE42-LABEL: 'var_bswap_v2i64'
-; SSE42-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %a)
-; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i64> %bswap
+define i16 @var_bswap_i16(i16 %a) {
+; NOMOVBE-LABEL: 'var_bswap_i16'
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 10 for instruction: %bswap = call i16 @llvm.bswap.i16(i16 %a)
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i16 %bswap
 ;
-; AVX-LABEL: 'var_bswap_v2i64'
-; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %a)
-; AVX-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i64> %bswap
+; MOVBE-LABEL: 'var_bswap_i16'
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i16 @llvm.bswap.i16(i16 %a)
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i16 %bswap
 ;
-  %bswap = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %a)
-  ret <2 x i64> %bswap
+  %bswap = call i16 @llvm.bswap.i16(i16 %a)
+  ret i16 %bswap
 }
 
-define <4 x i64> @var_bswap_v4i64(<4 x i64> %a) {
-; SSE2-LABEL: 'var_bswap_v4i64'
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 14 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
-;
-; SSE42-LABEL: 'var_bswap_v4i64'
-; SSE42-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
-; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
-;
-; AVX1-LABEL: 'var_bswap_v4i64'
-; AVX1-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
-; AVX1-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
-;
-; AVX2-LABEL: 'var_bswap_v4i64'
-; AVX2-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
-; AVX2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %bswap
+define i32 @var_bswap_i32(i32 %a) {
+; ALL-LABEL: 'var_bswap_i32'
+; ALL-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i32 @llvm.bswap.i32(i32 %a)
+; ALL-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i32 %bswap
 ;
-  %bswap = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> %a)
-  ret <4 x i64> %bswap
+  %bswap = call i32 @llvm.bswap.i32(i32 %a)
+  ret i32 %bswap
 }
 
-define <4 x i32> @var_bswap_v4i32(<4 x i32> %a) {
-; SSE2-LABEL: 'var_bswap_v4i32'
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 7 for instruction: %bswap = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i32> %bswap
+define i64 @var_bswap_i64(i64 %a) {
+; X64-LABEL: 'var_bswap_i64'
+; X64-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i64 @llvm.bswap.i64(i64 %a)
+; X64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i64 %bswap
 ;
-; SSE42-LABEL: 'var_bswap_v4i32'
-; SSE42-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
-; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i32> %bswap
+; X86-LABEL: 'var_bswap_i64'
+; X86-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call i64 @llvm.bswap.i64(i64 %a)
+; X86-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i64 %bswap
 ;
-; AVX-LABEL: 'var_bswap_v4i32'
-; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
-; AVX-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i32> %bswap
-;
-  %bswap = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %a)
-  ret <4 x i32> %bswap
+  %bswap = call i64 @llvm.bswap.i64(i64 %a)
+  ret i64 %bswap
 }
 
-define <8 x i32> @var_bswap_v8i32(<8 x i32> %a) {
-; SSE2-LABEL: 'var_bswap_v8i32'
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 14 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
-;
-; SSE42-LABEL: 'var_bswap_v8i32'
-; SSE42-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
-; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
-;
-; AVX1-LABEL: 'var_bswap_v8i32'
-; AVX1-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
-; AVX1-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
-;
-; AVX2-LABEL: 'var_bswap_v8i32'
-; AVX2-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
-; AVX2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i32> %bswap
-;
-  %bswap = call <8 x i32> @llvm.bswap.v8i32(<8 x i32> %a)
-  ret <8 x i32> %bswap
-}
-
-define <8 x i16> @var_bswap_v8i16(<8 x i16> %a) {
-; SSE2-LABEL: 'var_bswap_v8i16'
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 7 for instruction: %bswap = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %a)
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i16> %bswap
-;
-; SSE42-LABEL: 'var_bswap_v8i16'
-; SSE42-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %a)
-; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i16> %bswap
-;
-; AVX-LABEL: 'var_bswap_v8i16'
-; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %a)
-; AVX-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i16> %bswap
-;
-  %bswap = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %a)
-  ret <8 x i16> %bswap
-}
-
-define <16 x i16> @var_bswap_v16i16(<16 x i16> %a) {
-; SSE2-LABEL: 'var_bswap_v16i16'
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 14 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
-; SSE2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
-;
-; SSE42-LABEL: 'var_bswap_v16i16'
-; SSE42-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
-; SSE42-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
-;
-; AVX1-LABEL: 'var_bswap_v16i16'
-; AVX1-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
-; AVX1-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
+define i128 @var_bswap_i128(i128 %a) {
+; X64-LABEL: 'var_bswap_i128'
+; X64-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call i128 @llvm.bswap.i128(i128 %a)
+; X64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i128 %bswap
 ;
-; AVX2-LABEL: 'var_bswap_v16i16'
-; AVX2-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
-; AVX2-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i16> %bswap
+; X86-LABEL: 'var_bswap_i128'
+; X86-NEXT:  Cost Model: Found an estimated cost of 8 for instruction: %bswap = call i128 @llvm.bswap.i128(i128 %a)
+; X86-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i128 %bswap
 ;
-  %bswap = call <16 x i16> @llvm.bswap.v16i16(<16 x i16> %a)
-  ret <16 x i16> %bswap
+  %bswap = call i128 @llvm.bswap.i128(i128 %a)
+  ret i128 %bswap
 }

diff  --git a/llvm/test/Analysis/CostModel/X86/load-bswap.ll b/llvm/test/Analysis/CostModel/X86/load-bswap.ll
new file mode 100644
index 000000000000..8f524b649410
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/X86/load-bswap.ll
@@ -0,0 +1,158 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze | FileCheck %s --check-prefixes=ALL,NOMOVBE,X64
+; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+movbe | FileCheck %s --check-prefixes=ALL,MOVBE,X64
+; RUN: opt < %s -mtriple=i686-unknown-linux-gnu -cost-model -analyze | FileCheck %s --check-prefixes=ALL,NOMOVBE,X86
+; RUN: opt < %s -mtriple=i686-unknown-linux-gnu -cost-model -analyze -mattr=+movbe | FileCheck %s --check-prefixes=ALL,MOVBE,X86
+
+declare i16 @llvm.bswap.i16(i16)
+declare i32 @llvm.bswap.i32(i32)
+declare i64 @llvm.bswap.i64(i64)
+declare i128 @llvm.bswap.i128(i128)
+
+define i16 @var_load_bswap_i16(i16* %src) {
+; NOMOVBE-LABEL: 'var_load_bswap_i16'
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %a = load i16, i16* %src, align 1
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 10 for instruction: %bswap = call i16 @llvm.bswap.i16(i16 %a)
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i16 %bswap
+;
+; MOVBE-LABEL: 'var_load_bswap_i16'
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %a = load i16, i16* %src, align 1
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i16 @llvm.bswap.i16(i16 %a)
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i16 %bswap
+;
+  %a = load i16, i16* %src, align 1
+  %bswap = call i16 @llvm.bswap.i16(i16 %a)
+
+  ret i16 %bswap
+}
+define i16 @var_load_bswap_i16_extrause(i16* %src, i16* %clobberdst) {
+; NOMOVBE-LABEL: 'var_load_bswap_i16_extrause'
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %a = load i16, i16* %src, align 1
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 10 for instruction: %bswap = call i16 @llvm.bswap.i16(i16 %a)
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %a2 = shl i16 %a, 2
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: store i16 %a2, i16* %clobberdst, align 1
+; NOMOVBE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i16 %bswap
+;
+; MOVBE-LABEL: 'var_load_bswap_i16_extrause'
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %a = load i16, i16* %src, align 1
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i16 @llvm.bswap.i16(i16 %a)
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %a2 = shl i16 %a, 2
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: store i16 %a2, i16* %clobberdst, align 1
+; MOVBE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i16 %bswap
+;
+  %a = load i16, i16* %src, align 1
+  %bswap = call i16 @llvm.bswap.i16(i16 %a)
+
+  %a2 = shl i16 %a, 2 ; incur an extra use to the load
+  store i16 %a2, i16* %clobberdst, align 1
+
+  ret i16 %bswap
+}
+
+define i32 @var_load_bswap_i32(i32* %src) {
+; ALL-LABEL: 'var_load_bswap_i32'
+; ALL-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %a = load i32, i32* %src, align 1
+; ALL-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i32 @llvm.bswap.i32(i32 %a)
+; ALL-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i32 %bswap
+;
+  %a = load i32, i32* %src, align 1
+  %bswap = call i32 @llvm.bswap.i32(i32 %a)
+
+  ret i32 %bswap
+}
+define i32 @var_load_bswap_i32_extrause(i32* %src, i32* %clobberdst) {
+; ALL-LABEL: 'var_load_bswap_i32_extrause'
+; ALL-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %a = load i32, i32* %src, align 1
+; ALL-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i32 @llvm.bswap.i32(i32 %a)
+; ALL-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %a2 = shl i32 %a, 2
+; ALL-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: store i32 %a2, i32* %clobberdst, align 1
+; ALL-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i32 %bswap
+;
+  %a = load i32, i32* %src, align 1
+  %bswap = call i32 @llvm.bswap.i32(i32 %a)
+
+  %a2 = shl i32 %a, 2 ; incur an extra use to the load
+  store i32 %a2, i32* %clobberdst, align 1
+
+  ret i32 %bswap
+}
+
+define i64 @var_load_bswap_i64(i64* %src) {
+; X64-LABEL: 'var_load_bswap_i64'
+; X64-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %a = load i64, i64* %src, align 1
+; X64-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i64 @llvm.bswap.i64(i64 %a)
+; X64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i64 %bswap
+;
+; X86-LABEL: 'var_load_bswap_i64'
+; X86-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %a = load i64, i64* %src, align 1
+; X86-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call i64 @llvm.bswap.i64(i64 %a)
+; X86-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i64 %bswap
+;
+  %a = load i64, i64* %src, align 1
+  %bswap = call i64 @llvm.bswap.i64(i64 %a)
+
+  ret i64 %bswap
+}
+define i64 @var_load_bswap_i64_extrause(i64* %src, i64* %clobberdst) {
+; X64-LABEL: 'var_load_bswap_i64_extrause'
+; X64-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %a = load i64, i64* %src, align 1
+; X64-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %bswap = call i64 @llvm.bswap.i64(i64 %a)
+; X64-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %a2 = shl i64 %a, 2
+; X64-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: store i64 %a2, i64* %clobberdst, align 1
+; X64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i64 %bswap
+;
+; X86-LABEL: 'var_load_bswap_i64_extrause'
+; X86-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %a = load i64, i64* %src, align 1
+; X86-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call i64 @llvm.bswap.i64(i64 %a)
+; X86-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %a2 = shl i64 %a, 2
+; X86-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: store i64 %a2, i64* %clobberdst, align 1
+; X86-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i64 %bswap
+;
+  %a = load i64, i64* %src, align 1
+  %bswap = call i64 @llvm.bswap.i64(i64 %a)
+
+  %a2 = shl i64 %a, 2 ; incur an extra use to the load
+  store i64 %a2, i64* %clobberdst, align 1
+
+  ret i64 %bswap
+}
+
+define i128 @var_load_bswap_i128(i128* %src) {
+; X64-LABEL: 'var_load_bswap_i128'
+; X64-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %a = load i128, i128* %src, align 1
+; X64-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call i128 @llvm.bswap.i128(i128 %a)
+; X64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i128 %bswap
+;
+; X86-LABEL: 'var_load_bswap_i128'
+; X86-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %a = load i128, i128* %src, align 1
+; X86-NEXT:  Cost Model: Found an estimated cost of 8 for instruction: %bswap = call i128 @llvm.bswap.i128(i128 %a)
+; X86-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i128 %bswap
+;
+  %a = load i128, i128* %src, align 1
+  %bswap = call i128 @llvm.bswap.i128(i128 %a)
+
+  ret i128 %bswap
+}
+define i128 @var_load_bswap_i128_extrause(i128* %src, i128* %clobberdst) {
+; X64-LABEL: 'var_load_bswap_i128_extrause'
+; X64-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %a = load i128, i128* %src, align 1
+; X64-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %bswap = call i128 @llvm.bswap.i128(i128 %a)
+; X64-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: %a2 = shl i128 %a, 2
+; X64-NEXT:  Cost Model: Found an estimated cost of 2 for instruction: store i128 %a2, i128* %clobberdst, align 1
+; X64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i128 %bswap
+;
+; X86-LABEL: 'var_load_bswap_i128_extrause'
+; X86-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %a = load i128, i128* %src, align 1
+; X86-NEXT:  Cost Model: Found an estimated cost of 8 for instruction: %bswap = call i128 @llvm.bswap.i128(i128 %a)
+; X86-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: %a2 = shl i128 %a, 2
+; X86-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: store i128 %a2, i128* %clobberdst, align 1
+; X86-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret i128 %bswap
+;
+  %a = load i128, i128* %src, align 1
+  %bswap = call i128 @llvm.bswap.i128(i128 %a)
+
+  %a2 = shl i128 %a, 2 ; incur an extra use to the load
+  store i128 %a2, i128* %clobberdst, align 1
+
+  ret i128 %bswap
+}


        


More information about the llvm-commits mailing list