AVX-512 Loop Vectorizer: Cost calculation for interleave load/store patterns.

X86 target does not provide any target specific cost calculation for interleave patterns.It uses the common target-independent calculation, which gives very high numbers. As a result, the scalar version is chosen in many cases. The situation on AVX-512 is even worse, since we have 3-src shuffles that significantly reduce the cost.

In this patch I calculate the cost on AVX-512. It will allow to compare interleave pattern with gather/scatter and choose a better solution (PR31426).

* Shiffle-broadcast cost will be changed in Simon's upcoming patch.

Differential Revision: https://reviews.llvm.org/D28118

llvm-svn: 290810
diff --git a/llvm/test/Analysis/CostModel/X86/interleave-load-i32.ll b/llvm/test/Analysis/CostModel/X86/interleave-load-i32.ll
new file mode 100755
index 0000000..3c94d8c
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/X86/interleave-load-i32.ll
@@ -0,0 +1,85 @@
+; REQUIRES: asserts
+; RUN: opt -loop-vectorize -S -mcpu=skx --debug-only=loop-vectorize < %s 2>&1 | FileCheck %s 
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@A = global [10240 x i32] zeroinitializer, align 16
+@B = global [10240 x i32] zeroinitializer, align 16
+
+; Function Attrs: nounwind uwtable
+define void @load_i32_interleave4() {
+;CHECK-LABEL: load_i32_interleave4
+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %0 = load
+;CHECK: Found an estimated cost of 5 for VF 2 For instruction:   %0 = load
+;CHECK: Found an estimated cost of 5 for VF 4 For instruction:   %0 = load
+;CHECK: Found an estimated cost of 8 for VF 8 For instruction:   %0 = load
+;CHECK: Found an estimated cost of 22 for VF 16 For instruction:   %0 = load
+entry:
+  br label %for.body
+
+for.cond.cleanup:                                 ; preds = %for.body
+  ret void
+
+for.body:                                         ; preds = %entry, %for.body
+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+  %arrayidx = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %indvars.iv
+  %0 = load i32, i32* %arrayidx, align 16
+  %1 = or i64 %indvars.iv, 1
+  %arrayidx2 = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %1
+  %2 = load i32, i32* %arrayidx2, align 4
+  %add3 = add nsw i32 %2, %0
+  %3 = or i64 %indvars.iv, 2
+  %arrayidx6 = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %3
+  %4 = load i32, i32* %arrayidx6, align 8
+  %add7 = add nsw i32 %add3, %4
+  %5 = or i64 %indvars.iv, 3
+  %arrayidx10 = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %5
+  %6 = load i32, i32* %arrayidx10, align 4
+  %add11 = add nsw i32 %add7, %6
+  %arrayidx13 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %indvars.iv
+  store i32 %add11, i32* %arrayidx13, align 16
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 4
+  %cmp = icmp slt i64 %indvars.iv.next, 1024
+  br i1 %cmp, label %for.body, label %for.cond.cleanup
+}
+
+define void @load_i32_interleave5() {
+;CHECK-LABEL: load_i32_interleave5
+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %0 = load
+;CHECK: Found an estimated cost of 6 for VF 2 For instruction:   %0 = load
+;CHECK: Found an estimated cost of 9 for VF 4 For instruction:   %0 = load
+;CHECK: Found an estimated cost of 18 for VF 8 For instruction:   %0 = load
+;CHECK: Found an estimated cost of 35 for VF 16 For instruction:   %0 = load
+entry:
+  br label %for.body
+
+for.cond.cleanup:                                 ; preds = %for.body
+  ret void
+
+for.body:                                         ; preds = %entry, %for.body
+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+  %arrayidx = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %indvars.iv
+  %0 = load i32, i32* %arrayidx, align 4
+  %1 = add nuw nsw i64 %indvars.iv, 1
+  %arrayidx2 = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %1
+  %2 = load i32, i32* %arrayidx2, align 4
+  %add3 = add nsw i32 %2, %0
+  %3 = add nuw nsw i64 %indvars.iv, 2
+  %arrayidx6 = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %3
+  %4 = load i32, i32* %arrayidx6, align 4
+  %add7 = add nsw i32 %add3, %4
+  %5 = add nuw nsw i64 %indvars.iv, 3
+  %arrayidx10 = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %5
+  %6 = load i32, i32* %arrayidx10, align 4
+  %add11 = add nsw i32 %add7, %6
+  %7 = add nuw nsw i64 %indvars.iv, 4
+  %arrayidx14 = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %7
+  %8 = load i32, i32* %arrayidx14, align 4
+  %add15 = add nsw i32 %add11, %8
+  %arrayidx17 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %indvars.iv
+  store i32 %add15, i32* %arrayidx17, align 4
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 5
+  %cmp = icmp slt i64 %indvars.iv.next, 1024
+  br i1 %cmp, label %for.body, label %for.cond.cleanup
+}
diff --git a/llvm/test/Analysis/CostModel/X86/interleave-store-i32.ll b/llvm/test/Analysis/CostModel/X86/interleave-store-i32.ll
new file mode 100755
index 0000000..e3076bf
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/X86/interleave-store-i32.ll
@@ -0,0 +1,85 @@
+; REQUIRES: asserts
+; RUN: opt -loop-vectorize -S -mcpu=skx --debug-only=loop-vectorize < %s 2>&1| FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@A = global [10240 x i32] zeroinitializer, align 16
+@B = global [10240 x i32] zeroinitializer, align 16
+
+; Function Attrs: nounwind uwtable
+define void @store_i32_interleave4() {
+;CHECK-LABEL: store_i32_interleave4
+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   store i32 %add16
+;CHECK: Found an estimated cost of 5 for VF 2 For instruction:   store i32 %add16
+;CHECK: Found an estimated cost of 5 for VF 4 For instruction:   store i32 %add16
+;CHECK: Found an estimated cost of 11 for VF 8 For instruction:   store i32 %add16
+;CHECK: Found an estimated cost of 22 for VF 16 For instruction:   store i32 %add16
+entry:
+  br label %for.body
+
+for.cond.cleanup:                                 ; preds = %for.body
+  ret void
+
+for.body:                                         ; preds = %entry, %for.body
+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+  %arrayidx = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %indvars.iv
+  %0 = load i32, i32* %arrayidx, align 16
+  %arrayidx2 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %indvars.iv
+  store i32 %0, i32* %arrayidx2, align 16
+  %add = add nsw i32 %0, 1
+  %1 = or i64 %indvars.iv, 1
+  %arrayidx7 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %1
+  store i32 %add, i32* %arrayidx7, align 4
+  %add10 = add nsw i32 %0, 2
+  %2 = or i64 %indvars.iv, 2
+  %arrayidx13 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %2
+  store i32 %add10, i32* %arrayidx13, align 8
+  %add16 = add nsw i32 %0, 3
+  %3 = or i64 %indvars.iv, 3
+  %arrayidx19 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %3
+  store i32 %add16, i32* %arrayidx19, align 4
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 4
+  %cmp = icmp slt i64 %indvars.iv.next, 1024
+  br i1 %cmp, label %for.body, label %for.cond.cleanup
+}
+
+define void @store_i32_interleave5() {
+;CHECK-LABEL: store_i32_interleave5
+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   store i32 %add22
+;CHECK: Found an estimated cost of 7 for VF 2 For instruction:   store i32 %add22
+;CHECK: Found an estimated cost of 14 for VF 4 For instruction:   store i32 %add22
+;CHECK: Found an estimated cost of 21 for VF 8 For instruction:   store i32 %add22
+;CHECK: Found an estimated cost of 35 for VF 16 For instruction:   store i32 %add22
+entry:
+  br label %for.body
+
+for.cond.cleanup:                                 ; preds = %for.body
+  ret void
+
+for.body:                                         ; preds = %entry, %for.body
+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+  %arrayidx = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %indvars.iv
+  %0 = load i32, i32* %arrayidx, align 4
+  %arrayidx2 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %indvars.iv
+  store i32 %0, i32* %arrayidx2, align 4
+  %add = add nsw i32 %0, 1
+  %1 = add nuw nsw i64 %indvars.iv, 1
+  %arrayidx7 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %1
+  store i32 %add, i32* %arrayidx7, align 4
+  %add10 = add nsw i32 %0, 2
+  %2 = add nuw nsw i64 %indvars.iv, 2
+  %arrayidx13 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %2
+  store i32 %add10, i32* %arrayidx13, align 4
+  %add16 = add nsw i32 %0, 3
+  %3 = add nuw nsw i64 %indvars.iv, 3
+  %arrayidx19 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %3
+  store i32 %add16, i32* %arrayidx19, align 4
+  %add22 = add nsw i32 %0, 4
+  %4 = add nuw nsw i64 %indvars.iv, 4
+  %arrayidx25 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %4
+  store i32 %add22, i32* %arrayidx25, align 4
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 5
+  %cmp = icmp slt i64 %indvars.iv.next, 1024
+  br i1 %cmp, label %for.body, label %for.cond.cleanup
+}
diff --git a/llvm/test/Analysis/CostModel/X86/shuffle-broadcast.ll b/llvm/test/Analysis/CostModel/X86/shuffle-broadcast.ll
index 579c19e..a829a47 100644
--- a/llvm/test/Analysis/CostModel/X86/shuffle-broadcast.ll
+++ b/llvm/test/Analysis/CostModel/X86/shuffle-broadcast.ll
@@ -12,19 +12,19 @@
 
 ; CHECK-LABEL: 'test_vXf64'
 define void @test_vXf64(<2 x double> %src128, <4 x double> %src256, <8 x double> %src512) {
-  ; SSE: Unknown cost {{.*}} %V128 = shufflevector
-  ; AVX: Unknown cost {{.*}} %V128 = shufflevector
-  ; AVX512: Unknown cost {{.*}} %V128 = shufflevector
+  ; SSE: cost of 1 {{.*}} %V128 = shufflevector
+  ; AVX: cost of 1 {{.*}} %V128 = shufflevector
+  ; AVX512: cost of 1 {{.*}} %V128 = shufflevector
   %V128 = shufflevector <2 x double> %src128, <2 x double> undef, <2 x i32> zeroinitializer
 
-  ; SSE: Unknown cost {{.*}} %V256 = shufflevector
-  ; AVX: Unknown cost {{.*}} %V256 = shufflevector
-  ; AVX512: Unknown cost {{.*}} %V256 = shufflevector
+  ; SSE: cost of 1 {{.*}} %V256 = shufflevector
+  ; AVX: cost of 1 {{.*}} %V256 = shufflevector
+  ; AVX512: cost of 1 {{.*}} %V256 = shufflevector
   %V256 = shufflevector <4 x double> %src256, <4 x double> undef, <4 x i32> zeroinitializer
 
-  ; SSE: Unknown cost {{.*}} %V512 = shufflevector
-  ; AVX: Unknown cost {{.*}} %V512 = shufflevector
-  ; AVX512: Unknown cost {{.*}} %V512 = shufflevector
+  ; SSE: cost of 1 {{.*}} %V512 = shufflevector
+  ; AVX: cost of 1 {{.*}} %V512 = shufflevector
+  ; AVX512: cost of 1 {{.*}} %V512 = shufflevector
   %V512 = shufflevector <8 x double> %src512, <8 x double> undef, <8 x i32> zeroinitializer
 
   ret void
diff --git a/llvm/test/Analysis/CostModel/X86/shuffle-single-src.ll b/llvm/test/Analysis/CostModel/X86/shuffle-single-src.ll
new file mode 100644
index 0000000..a953ec1
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/X86/shuffle-single-src.ll
@@ -0,0 +1,94 @@
+; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mcpu=skylake-avx512 | FileCheck %s --check-prefix=SKX
+
+;
+; Verify the cost model for 1 src shuffles
+;
+
+; SKX-LABEL: 'test_vXf64'
+define void @test_vXf64(<4 x double> %src256, <8 x double> %src512, <16 x double> %src1024) {
+  ; SKX: cost of 1 {{.*}} %V256 = shufflevector
+  %V256 = shufflevector <4 x double> %src256, <4 x double> undef, <4 x i32> <i32 3, i32 3, i32 1, i32 0>
+
+  ; SKX: cost of 1 {{.*}} %V512 = shufflevector
+  %V512 = shufflevector <8 x double> %src512, <8 x double> undef, <8 x i32> <i32 7, i32 6, i32 6, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 2 {{.*}} %V1024 = shufflevector
+  %V1024 = shufflevector <16 x double> %src1024, <16 x double> undef, <16 x i32> <i32 15, i32 14, i32 13, i32 13, i32 11, i32 10, i32 8, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ret void
+}
+
+; SKX-LABEL: 'test_vXi64'
+define void @test_vXi64(<4 x i64> %src256, <8 x i64> %src512) {
+
+  ; SKX: cost of 1 {{.*}} %V256 = shufflevector
+  %V256 = shufflevector <4 x i64> %src256, <4 x i64> undef, <4 x i32> <i32 3, i32 3, i32 1, i32 0>
+
+  ; SKX: cost of 1 {{.*}} %V512 = shufflevector
+  %V512 = shufflevector <8 x i64> %src512, <8 x i64> undef, <8 x i32> <i32 7, i32 6, i32 6, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ret void
+}
+
+; CHECK-LABEL: 'test_vXf32'
+define void @test_vXf32(<4 x float> %src128, <8 x float> %src256, <16 x float> %src512) {
+
+  ; SKX: cost of 1 {{.*}} %V128 = shufflevector
+  %V128 = shufflevector <4 x float> %src128, <4 x float> undef, <4 x i32> <i32 3, i32 3, i32 1, i32 0>
+
+  ; SKX: cost of 1 {{.*}} %V256 = shufflevector
+  %V256 = shufflevector <8 x float> %src256, <8 x float> undef, <8 x i32> <i32 7, i32 6, i32 6, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 1 {{.*}} %V512 = shufflevector
+  %V512 = shufflevector <16 x float> %src512, <16 x float> undef, <16 x i32> <i32 15, i32 14, i32 13, i32 13, i32 11, i32 10, i32 8, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ret void
+}
+
+; CHECK-LABEL: 'test_vXi32'
+define void @test_vXi32(<4 x i32> %src128, <8 x i32> %src256, <16 x i32> %src512, <32 x i32> %src1024) {
+
+  ; SKX: cost of 1 {{.*}} %V128 = shufflevector
+  %V128 = shufflevector <4 x i32> %src128, <4 x i32> undef, <4 x i32> <i32 3, i32 3, i32 1, i32 0>
+
+  ; SKX: cost of 1 {{.*}} %V256 = shufflevector
+  %V256 = shufflevector <8 x i32> %src256, <8 x i32> undef, <8 x i32> <i32 7, i32 6, i32 5, i32 5, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 1 {{.*}} %V512 = shufflevector
+  %V512 = shufflevector <16 x i32> %src512, <16 x i32> undef, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 13, i32 10, i32 9, i32 8, i32 8, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 2 {{.*}} %V1024 = shufflevector
+  %V1024 = shufflevector <32 x i32> %src1024, <32 x i32> undef, <32 x i32> <i32 31, i32 30, i32 20, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 22, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 11, i32 9, i32 8, i32 7, i32 11, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+  ret void
+}
+
+; CHECK-LABEL: 'test_vXi16'
+define void @test_vXi16(<8 x i16> %src128, <16 x i16> %src256, <32 x i16> %src512, <64 x i16> %src1024) {
+
+  ; SKX: cost of 1 {{.*}} %V128 = shufflevector
+  %V128 = shufflevector <8 x i16> %src128, <8 x i16> undef, <8 x i32> <i32 7, i32 6, i32 6, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 1 {{.*}} %V256 = shufflevector
+  %V256 = shufflevector <16 x i16> %src256, <16 x i16> undef, <16 x i32> <i32 15, i32 14, i32 13, i32 13, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 1 {{.*}} %V512 = shufflevector
+  %V512 = shufflevector <32 x i16> %src512, <32 x i16> undef, <32 x i32> <i32 31, i32 30, i32 20, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 22, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 11, i32 9, i32 8, i32 7, i32 11, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 2 {{.*}} %V1024 = shufflevector
+  %V1024 = shufflevector <64 x i16> %src1024, <64 x i16> undef, <64 x i32> <i32 63, i32 62, i32 61, i32 60, i32 59, i32 58, i32 57, i32 56, i32 55, i32 54, i32 53, i32 52, i32 51, i32 50, i32 49, i32 48, i32 47, i32 46, i32 45, i32 44, i32 43, i32 42, i32 41, i32 40, i32 39, i32 38, i32 37, i32 36, i32 35, i32 34, i32 33, i32 32, i32 31, i32 30, i32 29, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 20, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+  ret void
+}
+
+; CHECK-LABEL: 'test_vXi8'
+define void @test_vXi8(<16 x i8> %src128, <32 x i8> %src256, <64 x i8> %src512) {
+  ; SKX: cost of 1 {{.*}} %V128 = shufflevector
+  %V128 = shufflevector <16 x i8> %src128, <16 x i8> undef, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 11, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 3 {{.*}} %V256 = shufflevector
+  %V256 = shufflevector <32 x i8> %src256, <32 x i8> undef, <32 x i32> <i32 31, i32 30, i32 29, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 22, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 8, i32 8, i32 7, i32 6, i32 8, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 8 {{.*}} %V512 = shufflevector
+  %V512 = shufflevector <64 x i8> %src512, <64 x i8> undef, <64 x i32> <i32 63, i32 62, i32 61, i32 60, i32 59, i32 58, i32 57, i32 56, i32 55, i32 54, i32 53, i32 52, i32 51, i32 50, i32 49, i32 48, i32 47, i32 46, i32 45, i32 44, i32 43, i32 42, i32 41, i32 40, i32 39, i32 38, i32 37, i32 36, i32 35, i32 34, i32 33, i32 32, i32 31, i32 30, i32 29, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 20, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ret void
+}
diff --git a/llvm/test/Analysis/CostModel/X86/shuffle-two-src.ll b/llvm/test/Analysis/CostModel/X86/shuffle-two-src.ll
new file mode 100644
index 0000000..de79a82
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/X86/shuffle-two-src.ll
@@ -0,0 +1,68 @@
+; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mcpu=skylake-avx512 | FileCheck %s --check-prefix=SKX
+
+;
+; Verify the cost model for 2 src shuffles
+;
+
+; SKX-LABEL: 'test_vXf64'
+define void @test_vXf64(<4 x double> %src256, <8 x double> %src512, <16 x double> %src1024, <4 x double> %src256_1, <8 x double> %src512_1, <16 x double> %src1024_1) {
+  ; SKX: cost of 1 {{.*}} %V256 = shufflevector
+  %V256 = shufflevector <4 x double> %src256, <4 x double> %src256_1, <4 x i32> <i32 3, i32 3, i32 7, i32 6>
+
+  ; SKX: cost of 1 {{.*}} %V512 = shufflevector
+  %V512 = shufflevector <8 x double> %src512, <8 x double> %src512_1, <8 x i32> <i32 7, i32 6, i32 12, i32 4, i32 3, i32 2, i32 1, i32 15>
+
+  ; SKX: cost of 6 {{.*}} %V1024 = shufflevector
+  %V1024 = shufflevector <16 x double> %src1024, <16 x double> %src1024_1, <16 x i32> <i32 30, i32 14, i32 13, i32 12, i32 13, i32 10, i32 18, i32 8, i32 8, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ret void
+}
+
+; CHECK-LABEL: 'test_vXf32'
+define void @test_vXf32(<4 x float> %src128, <8 x float> %src256, <16 x float> %src512, <32 x float> %src1024, <4 x float> %src128_1, <8 x float> %src256_1, <16 x float> %src512_1, <32 x float> %src1024_1) {
+
+  ; SKX: cost of 1 {{.*}} %V128 = shufflevector
+  %V128 = shufflevector <4 x float> %src128, <4 x float> %src128_1, <4 x i32> <i32 3, i32 6, i32 1, i32 5>
+
+  ; SKX: cost of 1 {{.*}} %V256 = shufflevector
+  %V256 = shufflevector <8 x float> %src256, <8 x float> %src256_1, <8 x i32> <i32 7, i32 6, i32 8, i32 4, i32 3, i32 2, i32 12, i32 0>
+
+  ; SKX: cost of 1 {{.*}} %V512 = shufflevector
+  %V512 = shufflevector <16 x float> %src512, <16 x float> %src512_1, <16 x i32> <i32 15, i32 17, i32 13, i32 20, i32 11, i32 10, i32 8, i32 8, i32 7, i32 22, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 6 {{.*}} %V1024 = shufflevector
+  %V1024 = shufflevector <32 x float> %src1024, <32 x float> %src1024_1, <32 x i32> <i32 31, i32 33, i32 20, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 22, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 48, i32 13, i32 12, i32 11, i32 11, i32 9, i32 45, i32 7, i32 11, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ret void
+}
+
+; CHECK-LABEL: 'test_vXi16'
+define void @test_vXi16(<8 x i16> %src128, <16 x i16> %src256, <32 x i16> %src512, <64 x i16> %src1024, <8 x i16> %src128_1, <16 x i16> %src256_1, <32 x i16> %src512_1, <64 x i16> %src1024_1) {
+
+  ; SKX: cost of 1 {{.*}} %V128 = shufflevector
+  %V128 = shufflevector <8 x i16> %src128, <8 x i16> %src128_1, <8 x i32> <i32 7, i32 6, i32 6, i32 8, i32 9, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 1 {{.*}} %V256 = shufflevector
+  %V256 = shufflevector <16 x i16> %src256, <16 x i16> %src256_1, <16 x i32> <i32 15, i32 14, i32 13, i32 20, i32 21, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 1 {{.*}} %V512 = shufflevector
+  %V512 = shufflevector <32 x i16> %src512, <32 x i16> %src512_1, <32 x i32> <i32 31, i32 30, i32 45, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 22, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 38, i32 11, i32 11, i32 9, i32 8, i32 7, i32 11, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 6 {{.*}} %V1024 = shufflevector
+  %V1024 = shufflevector <64 x i16> %src1024, <64 x i16> %src1024_1, <64 x i32> <i32 63, i32 62, i32 71, i32 60, i32 59, i32 58, i32 57, i32 56, i32 55, i32 54, i32 53, i32 52, i32 51, i32 50, i32 49, i32 48, i32 47, i32 46, i32 45, i32 44, i32 43, i32 42, i32 41, i32 40, i32 39, i32 38, i32 37, i32 36, i32 35, i32 34, i32 33, i32 32, i32 31, i32 30, i32 29, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 20, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 66, i32 2, i32 1, i32 0>
+  ret void
+}
+
+; CHECK-LABEL: 'test_vXi8'
+define void @test_vXi8(<16 x i8> %src128, <32 x i8> %src256, <64 x i8> %src512, <16 x i8> %src128_1, <32 x i8> %src256_1, <64 x i8> %src512_1) {
+  ; SKX: cost of 3 {{.*}} %V128 = shufflevector
+  %V128 = shufflevector <16 x i8> %src128, <16 x i8> %src128_1, <16 x i32> <i32 29, i32 14, i32 28, i32 12, i32 11, i32 10, i32 11, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 3 {{.*}} %V256 = shufflevector
+  %V256 = shufflevector <32 x i8> %src256, <32 x i8> %src256_1, <32 x i32> <i32 31, i32 30, i32 45, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 22, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 8, i32 8, i32 7, i32 6, i32 8, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ; SKX: cost of 19 {{.*}} %V512 = shufflevector
+  %V512 = shufflevector <64 x i8> %src512, <64 x i8> %src512_1, <64 x i32> <i32 63, i32 100, i32 61, i32 96, i32 59, i32 58, i32 57, i32 56, i32 55, i32 54, i32 53, i32 52, i32 51, i32 50, i32 49, i32 48, i32 47, i32 46, i32 45, i32 44, i32 43, i32 42, i32 41, i32 40, i32 39, i32 38, i32 37, i32 36, i32 35, i32 34, i32 33, i32 32, i32 31, i32 30, i32 29, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 20, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
+
+  ret void
+}
diff --git a/llvm/test/Analysis/CostModel/X86/strided-load-i16.ll b/llvm/test/Analysis/CostModel/X86/strided-load-i16.ll
new file mode 100755
index 0000000..2c2cf39
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/X86/strided-load-i16.ll
@@ -0,0 +1,113 @@
+; REQUIRES: asserts

+; RUN: opt -loop-vectorize -S -mcpu=skx --debug-only=loop-vectorize < %s 2>&1| FileCheck %s

+

+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

+target triple = "x86_64-unknown-linux-gnu"

+

+@A = global [10240 x i16] zeroinitializer, align 16

+@B = global [10240 x i16] zeroinitializer, align 16

+

+; Function Attrs: nounwind uwtable

+define void @load_i16_stride2() {

+;CHECK-LABEL: load_i16_stride2

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 8 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 16 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 2 for VF 32 For instruction:   %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = shl nsw i64 %indvars.iv, 1

+  %arrayidx = getelementptr inbounds [10240 x i16], [10240 x i16]* @A, i64 0, i64 %0

+  %1 = load i16, i16* %arrayidx, align 4

+  %arrayidx2 = getelementptr inbounds [10240 x i16], [10240 x i16]* @B, i64 0, i64 %indvars.iv

+  store i16 %1, i16* %arrayidx2, align 2

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

+

+define void @load_i16_stride3() {

+;CHECK-LABEL: load_i16_stride3

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 8 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 2 for VF 16 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 3 for VF 32 For instruction:   %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = mul nsw i64 %indvars.iv, 3

+  %arrayidx = getelementptr inbounds [10240 x i16], [10240 x i16]* @A, i64 0, i64 %0

+  %1 = load i16, i16* %arrayidx, align 4

+  %arrayidx2 = getelementptr inbounds [10240 x i16], [10240 x i16]* @B, i64 0, i64 %indvars.iv

+  store i16 %1, i16* %arrayidx2, align 2

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

+

+define void @load_i16_stride4() {

+;CHECK-LABEL: load_i16_stride4

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 8 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 2 for VF 16 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 5 for VF 32 For instruction:   %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = shl nsw i64 %indvars.iv, 2

+  %arrayidx = getelementptr inbounds [10240 x i16], [10240 x i16]* @A, i64 0, i64 %0

+  %1 = load i16, i16* %arrayidx, align 4

+  %arrayidx2 = getelementptr inbounds [10240 x i16], [10240 x i16]* @B, i64 0, i64 %indvars.iv

+  store i16 %1, i16* %arrayidx2, align 2

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

+

+define void @load_i16_stride5() {

+;CHECK-LABEL: load_i16_stride5

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 2 for VF 8 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 3 for VF 16 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 6 for VF 32 For instruction:   %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = mul nsw i64 %indvars.iv, 5

+  %arrayidx = getelementptr inbounds [10240 x i16], [10240 x i16]* @A, i64 0, i64 %0

+  %1 = load i16, i16* %arrayidx, align 4

+  %arrayidx2 = getelementptr inbounds [10240 x i16], [10240 x i16]* @B, i64 0, i64 %indvars.iv

+  store i16 %1, i16* %arrayidx2, align 2

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

diff --git a/llvm/test/Analysis/CostModel/X86/strided-load-i32.ll b/llvm/test/Analysis/CostModel/X86/strided-load-i32.ll
new file mode 100755
index 0000000..0dcd392
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/X86/strided-load-i32.ll
@@ -0,0 +1,110 @@
+; REQUIRES: asserts

+; RUN: opt -loop-vectorize -S -mcpu=skx --debug-only=loop-vectorize < %s 2>&1| FileCheck %s

+

+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

+target triple = "x86_64-unknown-linux-gnu"

+

+@A = global [10240 x i32] zeroinitializer, align 16

+@B = global [10240 x i32] zeroinitializer, align 16

+

+; Function Attrs: nounwind uwtable

+define void @load_int_stride2() {

+;CHECK-LABEL: load_int_stride2

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 8 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 2 for VF 16 For instruction:  %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = shl nsw i64 %indvars.iv, 1

+  %arrayidx = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %0

+  %1 = load i32, i32* %arrayidx, align 4

+  %arrayidx2 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %indvars.iv

+  store i32 %1, i32* %arrayidx2, align 2

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

+

+define void @load_int_stride3() {

+;CHECK-LABEL: load_int_stride3

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 2 for VF 8 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 3 for VF 16 For instruction:  %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = mul nsw i64 %indvars.iv, 3

+  %arrayidx = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %0

+  %1 = load i32, i32* %arrayidx, align 4

+  %arrayidx2 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %indvars.iv

+  store i32 %1, i32* %arrayidx2, align 2

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

+

+define void @load_int_stride4() {

+;CHECK-LABEL: load_int_stride4

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 2 for VF 8 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 5 for VF 16 For instruction:  %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = shl nsw i64 %indvars.iv, 2

+  %arrayidx = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %0

+  %1 = load i32, i32* %arrayidx, align 4

+  %arrayidx2 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %indvars.iv

+  store i32 %1, i32* %arrayidx2, align 2

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

+

+define void @load_int_stride5() {

+;CHECK-LABEL: load_int_stride5

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 2 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 3 for VF 8 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 6 for VF 16 For instruction:  %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = mul nsw i64 %indvars.iv, 5

+  %arrayidx = getelementptr inbounds [10240 x i32], [10240 x i32]* @A, i64 0, i64 %0

+  %1 = load i32, i32* %arrayidx, align 4

+  %arrayidx2 = getelementptr inbounds [10240 x i32], [10240 x i32]* @B, i64 0, i64 %indvars.iv

+  store i32 %1, i32* %arrayidx2, align 2

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

+

diff --git a/llvm/test/Analysis/CostModel/X86/strided-load-i64.ll b/llvm/test/Analysis/CostModel/X86/strided-load-i64.ll
new file mode 100755
index 0000000..0370b6f
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/X86/strided-load-i64.ll
@@ -0,0 +1,81 @@
+; REQUIRES: asserts

+; RUN: opt -loop-vectorize -S -mcpu=skx --debug-only=loop-vectorize < %s 2>&1| FileCheck %s

+

+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

+target triple = "x86_64-unknown-linux-gnu"

+

+@A = global [10240 x i64] zeroinitializer, align 16

+@B = global [10240 x i64] zeroinitializer, align 16

+

+; Function Attrs: nounwind uwtable

+define void @load_i64_stride2() {

+;CHECK-LABEL: load_i64_stride2

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 2 for VF 8 For instruction:   %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = shl nsw i64 %indvars.iv, 1

+  %arrayidx = getelementptr inbounds [10240 x i64], [10240 x i64]* @A, i64 0, i64 %0

+  %1 = load i64, i64* %arrayidx, align 16

+  %arrayidx2 = getelementptr inbounds [10240 x i64], [10240 x i64]* @B, i64 0, i64 %indvars.iv

+  store i64 %1, i64* %arrayidx2, align 8

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

+

+define void @load_i64_stride3() {

+;CHECK-LABEL: load_i64_stride3

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 2 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 3 for VF 8 For instruction:   %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = mul nsw i64 %indvars.iv, 3

+  %arrayidx = getelementptr inbounds [10240 x i64], [10240 x i64]* @A, i64 0, i64 %0

+  %1 = load i64, i64* %arrayidx, align 16

+  %arrayidx2 = getelementptr inbounds [10240 x i64], [10240 x i64]* @B, i64 0, i64 %indvars.iv

+  store i64 %1, i64* %arrayidx2, align 8

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

+

+define void @load_i64_stride4() {

+;CHECK-LABEL: load_i64_stride4

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 2 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 5 for VF 8 For instruction:   %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = mul nsw i64 %indvars.iv, 4

+  %arrayidx = getelementptr inbounds [10240 x i64], [10240 x i64]* @A, i64 0, i64 %0

+  %1 = load i64, i64* %arrayidx, align 16

+  %arrayidx2 = getelementptr inbounds [10240 x i64], [10240 x i64]* @B, i64 0, i64 %indvars.iv

+  store i64 %1, i64* %arrayidx2, align 8

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

diff --git a/llvm/test/Analysis/CostModel/X86/strided-load-i8.ll b/llvm/test/Analysis/CostModel/X86/strided-load-i8.ll
new file mode 100755
index 0000000..2a3a838
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/X86/strided-load-i8.ll
@@ -0,0 +1,117 @@
+; REQUIRES: asserts

+; RUN: opt -loop-vectorize -S -mcpu=skx --debug-only=loop-vectorize < %s 2>&1| FileCheck %s

+

+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

+target triple = "x86_64-unknown-linux-gnu"

+

+@A = global [10240 x i8] zeroinitializer, align 16

+@B = global [10240 x i8] zeroinitializer, align 16

+

+; Function Attrs: nounwind uwtable

+define void @load_i8_stride2() {

+;CHECK-LABEL: load_i8_stride2

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 8 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 3 for VF 16 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 8 for VF 32 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 20 for VF 64 For instruction:   %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = shl nsw i64 %indvars.iv, 1

+  %arrayidx = getelementptr inbounds [10240 x i8], [10240 x i8]* @A, i64 0, i64 %0

+  %1 = load i8, i8* %arrayidx, align 2

+  %arrayidx2 = getelementptr inbounds [10240 x i8], [10240 x i8]* @B, i64 0, i64 %indvars.iv

+  store i8 %1, i8* %arrayidx2, align 1

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

+

+define void @load_i8_stride3() {

+;CHECK-LABEL: load_i8_stride3

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 3 for VF 8 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 8 for VF 16 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 20 for VF 32 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 39 for VF 64 For instruction:   %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = mul nsw i64 %indvars.iv, 3

+  %arrayidx = getelementptr inbounds [10240 x i8], [10240 x i8]* @A, i64 0, i64 %0

+  %1 = load i8, i8* %arrayidx, align 2

+  %arrayidx2 = getelementptr inbounds [10240 x i8], [10240 x i8]* @B, i64 0, i64 %indvars.iv

+  store i8 %1, i8* %arrayidx2, align 1

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

+

+define void @load_i8_stride4() {

+;CHECK-LABEL: load_i8_stride4

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 3 for VF 8 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 8 for VF 16 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 20 for VF 32 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 59 for VF 64 For instruction:   %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = shl nsw i64 %indvars.iv, 2

+  %arrayidx = getelementptr inbounds [10240 x i8], [10240 x i8]* @A, i64 0, i64 %0

+  %1 = load i8, i8* %arrayidx, align 2

+  %arrayidx2 = getelementptr inbounds [10240 x i8], [10240 x i8]* @B, i64 0, i64 %indvars.iv

+  store i8 %1, i8* %arrayidx2, align 1

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}

+

+define void @load_i8_stride5() {

+;CHECK-LABEL: load_i8_stride5

+;CHECK: Found an estimated cost of 1 for VF 1 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 1 for VF 2 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 3 for VF 4 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 8 for VF 8 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 20 for VF 16 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 39 for VF 32 For instruction:   %1 = load

+;CHECK: Found an estimated cost of 78 for VF 64 For instruction:   %1 = load

+entry:

+  br label %for.body

+

+for.body:                                         ; preds = %for.body, %entry

+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]

+  %0 = mul nsw i64 %indvars.iv, 5

+  %arrayidx = getelementptr inbounds [10240 x i8], [10240 x i8]* @A, i64 0, i64 %0

+  %1 = load i8, i8* %arrayidx, align 2

+  %arrayidx2 = getelementptr inbounds [10240 x i8], [10240 x i8]* @B, i64 0, i64 %indvars.iv

+  store i8 %1, i8* %arrayidx2, align 1

+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1

+  %exitcond = icmp eq i64 %indvars.iv.next, 1024

+  br i1 %exitcond, label %for.end, label %for.body

+

+for.end:                                          ; preds = %for.body

+  ret void

+}