[llvm] r218242 - Fix assert when decoding PSHUFB mask
Robert Lougher
rob.lougher at gmail.com
Mon Sep 22 04:54:38 PDT 2014
Author: rlougher
Date: Mon Sep 22 06:54:38 2014
New Revision: 218242
URL: http://llvm.org/viewvc/llvm-project?rev=218242&view=rev
Log:
Fix assert when decoding PSHUFB mask
The PSHUFB mask decode routine used to assert if the mask index was out of
range (<0 or greater than the size of the vector). The problem is, we can
legitimately have a PSHUFB with a large index using intrinsics. The
instruction only uses the least significant 4 bits. This change removes the
assert and masks the index to match the instruction behaviour.
Added:
llvm/trunk/test/CodeGen/X86/pshufb-mask-comments.ll
Modified:
llvm/trunk/lib/Target/X86/Utils/X86ShuffleDecode.cpp
Modified: llvm/trunk/lib/Target/X86/Utils/X86ShuffleDecode.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/Utils/X86ShuffleDecode.cpp?rev=218242&r1=218241&r2=218242&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/Utils/X86ShuffleDecode.cpp (original)
+++ llvm/trunk/lib/Target/X86/Utils/X86ShuffleDecode.cpp Mon Sep 22 06:54:38 2014
@@ -247,9 +247,8 @@ void DecodePSHUFBMask(const ConstantData
if (Element & (1 << 7))
ShuffleMask.push_back(SM_SentinelZero);
else {
- int Index = Base + Element;
- assert((Index >= 0 && Index < NumElements) &&
- "Out of bounds shuffle index for pshub instruction!");
+ // Only the least significant 4 bits of the byte are used.
+ int Index = Base + (Element & 0xf);
ShuffleMask.push_back(Index);
}
}
@@ -266,9 +265,8 @@ void DecodePSHUFBMask(ArrayRef<uint64_t>
if (M & (1 << 7))
ShuffleMask.push_back(SM_SentinelZero);
else {
- int Index = Base + M;
- assert((Index >= 0 && (unsigned)Index < RawMask.size()) &&
- "Out of bounds shuffle index for pshub instruction!");
+ // Only the least significant 4 bits of the byte are used.
+ int Index = Base + (M & 0xf);
ShuffleMask.push_back(Index);
}
}
Added: llvm/trunk/test/CodeGen/X86/pshufb-mask-comments.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pshufb-mask-comments.ll?rev=218242&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/pshufb-mask-comments.ll (added)
+++ llvm/trunk/test/CodeGen/X86/pshufb-mask-comments.ll Mon Sep 22 06:54:38 2014
@@ -0,0 +1,30 @@
+; RUN: llc < %s -march=x86-64 -mattr=+ssse3 | FileCheck %s
+
+; Test that the pshufb mask comment is correct.
+
+define <16 x i8> @test1(<16 x i8> %V) {
+; CHECK-LABEL: test1:
+; CHECK: pshufb {{.*}} # xmm0 = xmm0[1,0,0,0,0,2,0,0,0,0,3,0,0,0,0,4]
+ %1 = tail call <16 x i8> @llvm.x86.ssse3.pshuf.b.128(<16 x i8> %V, <16 x i8> <i8 1, i8 0, i8 0, i8 0, i8 0, i8 2, i8 0, i8 0, i8 0, i8 0, i8 3, i8 0, i8 0, i8 0, i8 0, i8 4>)
+ ret <16 x i8> %1
+}
+
+; Test that indexes larger than the size of the vector are shown masked (bottom 4 bits).
+
+define <16 x i8> @test2(<16 x i8> %V) {
+; CHECK-LABEL: test2:
+; CHECK: pshufb {{.*}} # xmm0 = xmm0[15,0,0,0,0,0,0,0,0,0,1,0,0,0,0,2]
+ %1 = tail call <16 x i8> @llvm.x86.ssse3.pshuf.b.128(<16 x i8> %V, <16 x i8> <i8 15, i8 0, i8 0, i8 0, i8 0, i8 16, i8 0, i8 0, i8 0, i8 0, i8 17, i8 0, i8 0, i8 0, i8 0, i8 50>)
+ ret <16 x i8> %1
+}
+
+; Test that indexes with bit seven set are shown as zero.
+
+define <16 x i8> @test3(<16 x i8> %V) {
+; CHECK-LABEL: test3:
+; CHECK: pshufb {{.*}} # xmm0 = xmm0[1,0,0,15,0,2,0,0],zero,xmm0[0,3,0,0],zero,xmm0[0,4]
+ %1 = tail call <16 x i8> @llvm.x86.ssse3.pshuf.b.128(<16 x i8> %V, <16 x i8> <i8 1, i8 0, i8 0, i8 127, i8 0, i8 2, i8 0, i8 0, i8 128, i8 0, i8 3, i8 0, i8 0, i8 255, i8 0, i8 4>)
+ ret <16 x i8> %1
+}
+
+declare <16 x i8> @llvm.x86.ssse3.pshuf.b.128(<16 x i8>, <16 x i8>) nounwind readnone
More information about the llvm-commits
mailing list