Legalizer: Make bswap promotion safe for vectors.
authorBenjamin Kramer <benny.kra@googlemail.com>
Tue, 20 May 2014 09:42:31 +0000 (09:42 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Tue, 20 May 2014 09:42:31 +0000 (09:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209202 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
test/CodeGen/X86/bswap-vector.ll

index 1c5c9a2492b9accc514edc4c913682c7be60cb7a..2483184deedc0a94a9c59f2aa8b4160981685331 100644 (file)
@@ -268,9 +268,9 @@ SDValue DAGTypeLegalizer::PromoteIntRes_BSWAP(SDNode *N) {
   EVT NVT = Op.getValueType();
   SDLoc dl(N);
 
-  unsigned DiffBits = NVT.getSizeInBits() - OVT.getSizeInBits();
+  unsigned DiffBits = NVT.getScalarSizeInBits() - OVT.getScalarSizeInBits();
   return DAG.getNode(ISD::SRL, dl, NVT, DAG.getNode(ISD::BSWAP, dl, NVT, Op),
-                     DAG.getConstant(DiffBits, TLI.getPointerTy()));
+                     DAG.getConstant(DiffBits, TLI.getShiftAmountTy(NVT)));
 }
 
 SDValue DAGTypeLegalizer::PromoteIntRes_BUILD_PAIR(SDNode *N) {
index a18fd68865cc738a76026bdd705a83aa98ee376e..3c931db2e279c97ac36928a53fa40fa0d96553ee 100644 (file)
@@ -122,6 +122,23 @@ entry:
 ; CHECK-AVX2-NEXT: retq
 }
 
+declare <4 x i16> @llvm.bswap.v4i16(<4 x i16>)
+
+define <4 x i16> @test7(<4 x i16> %v) #0 {
+entry:
+  %r = call <4 x i16> @llvm.bswap.v4i16(<4 x i16> %v)
+  ret <4 x i16> %r
+
+; CHECK-SSSE3-LABEL: @test7
+; CHECK-SSSE3: pshufb
+; CHECK-SSSE3: psrld $16
+; CHECK-SSSE3-NEXT: retq
+
+; CHECK-AVX2-LABEL: @test7
+; CHECK-AVX2: vpshufb
+; CHECK-AVX2: vpsrld $16
+; CHECK-AVX2-NEXT: retq
+}
 
 attributes #0 = { nounwind uwtable }