[llvm] r289811 - [CostModel] Fix long standing bug with reverse shuffle mask detection

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 15 04:12:45 PST 2016


Author: rksimon
Date: Thu Dec 15 06:12:45 2016
New Revision: 289811

URL: http://llvm.org/viewvc/llvm-project?rev=289811&view=rev
Log:
[CostModel] Fix long standing bug with reverse shuffle mask detection

Incorrect 'undef' mask index matching meant that broadcast shuffles could be detected as reverse shuffles

Added:
    llvm/trunk/test/Analysis/CostModel/X86/shuffle-broadcast.ll
Modified:
    llvm/trunk/lib/Analysis/CostModel.cpp

Modified: llvm/trunk/lib/Analysis/CostModel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CostModel.cpp?rev=289811&r1=289810&r2=289811&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CostModel.cpp (original)
+++ llvm/trunk/lib/Analysis/CostModel.cpp Thu Dec 15 06:12:45 2016
@@ -92,7 +92,7 @@ CostModelAnalysis::runOnFunction(Functio
 
 static bool isReverseVectorMask(SmallVectorImpl<int> &Mask) {
   for (unsigned i = 0, MaskSize = Mask.size(); i < MaskSize; ++i)
-    if (Mask[i] > 0 && Mask[i] != (int)(MaskSize - 1 - i))
+    if (Mask[i] >= 0 && Mask[i] != (int)(MaskSize - 1 - i))
       return false;
   return true;
 }

Added: llvm/trunk/test/Analysis/CostModel/X86/shuffle-broadcast.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/X86/shuffle-broadcast.ll?rev=289811&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/CostModel/X86/shuffle-broadcast.ll (added)
+++ llvm/trunk/test/Analysis/CostModel/X86/shuffle-broadcast.ll Thu Dec 15 06:12:45 2016
@@ -0,0 +1,31 @@
+; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+sse2 | FileCheck %s -check-prefix=CHECK -check-prefix=SSE -check-prefix=SSE2
+; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+ssse3 | FileCheck %s -check-prefix=CHECK -check-prefix=SSE -check-prefix=SSSE3
+; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+sse4.2 | FileCheck %s -check-prefix=CHECK -check-prefix=SSE -check-prefix=SSE42
+; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+avx | FileCheck %s -check-prefix=CHECK -check-prefix=AVX -check-prefix=AVX1
+; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 | FileCheck %s -check-prefix=CHECK -check-prefix=AVX -check-prefix=AVX2
+; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512f | FileCheck %s --check-prefix=CHECK --check-prefix=AVX512 --check-prefix=AVX512F
+; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512f,+avx512bw | FileCheck %s --check-prefix=CHECK --check-prefix=AVX512 --check-prefix=AVX512BW
+
+;
+; Verify the cost model for broadcast shuffles.
+;
+
+; 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
+  %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
+  %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
+  %V512 = shufflevector <8 x double> %src512, <8 x double> undef, <8 x i32> zeroinitializer
+
+  ret void
+}




More information about the llvm-commits mailing list