From 8c44cdee9578eb7f6090c7f4be60c32ceea8b251 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Wed, 30 May 2018 13:45:34 +0000 Subject: [PATCH] [Hexagon] Use vector align-left when shift amount fits in 3 bits This saves an instruction because for align-right the shift amount would need to be put in a register first. llvm-svn: 333543 --- lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp | 17 +++++++++------ test/CodeGen/Hexagon/autohvx/align-128b.ll | 21 +++++++------------ test/CodeGen/Hexagon/autohvx/align-64b.ll | 21 +++++++------------ test/CodeGen/Hexagon/autohvx/align2-128b.ll | 21 +++++++------------ test/CodeGen/Hexagon/autohvx/align2-64b.ll | 21 +++++++------------ 5 files changed, 39 insertions(+), 62 deletions(-) diff --git a/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp b/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp index 31515788d2b..8aef9b4560d 100644 --- a/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp +++ b/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp @@ -1054,7 +1054,7 @@ OpRef HvxSelector::packs(ShuffleMask SM, OpRef Va, OpRef Vb, int VecLen = SM.Mask.size(); MVT Ty = getSingleVT(MVT::i8); - auto IsSubvector = [] (ShuffleMask M) { + auto IsExtSubvector = [] (ShuffleMask M) { assert(M.MinSrc >= 0 && M.MaxSrc >= 0); for (int I = 0, E = M.Mask.size(); I != E; ++I) { if (M.Mask[I] >= 0 && M.Mask[I]-I != M.MinSrc) @@ -1064,11 +1064,11 @@ OpRef HvxSelector::packs(ShuffleMask SM, OpRef Va, OpRef Vb, }; if (SM.MaxSrc - SM.MinSrc < int(HwLen)) { - if (SM.MinSrc == 0 || SM.MinSrc == int(HwLen) || !IsSubvector(SM)) { + if (SM.MinSrc == 0 || SM.MinSrc == int(HwLen) || !IsExtSubvector(SM)) { // If the mask picks elements from only one of the operands, return // that operand, and update the mask to use index 0 to refer to the // first element of that operand. - // If the mask selects a subvector, it will be handled below, so + // If the mask extracts a subvector, it will be handled below, so // skip it here. if (SM.MaxSrc < int(HwLen)) { memcpy(NewMask.data(), SM.Mask.data(), sizeof(int)*VecLen); @@ -1092,10 +1092,15 @@ OpRef HvxSelector::packs(ShuffleMask SM, OpRef Va, OpRef Vb, MinSrc = SM.MinSrc - HwLen; } const SDLoc &dl(Results.InpNode); - SDValue S = DAG.getTargetConstant(MinSrc, dl, MVT::i32); - if (isUInt<3>(MinSrc)) { - Results.push(Hexagon::V6_valignbi, Ty, {Vb, Va, S}); + if (isUInt<3>(MinSrc) || isUInt<3>(HwLen-MinSrc)) { + bool IsRight = isUInt<3>(MinSrc); // Right align. + SDValue S = DAG.getTargetConstant(IsRight ? MinSrc : HwLen-MinSrc, + dl, MVT::i32); + unsigned Opc = IsRight ? Hexagon::V6_valignbi + : Hexagon::V6_vlalignbi; + Results.push(Opc, Ty, {Vb, Va, S}); } else { + SDValue S = DAG.getTargetConstant(MinSrc, dl, MVT::i32); Results.push(Hexagon::A2_tfrsi, MVT::i32, {S}); unsigned Top = Results.top(); Results.push(Hexagon::V6_valignb, Ty, {Vb, Va, OpRef::res(Top)}); diff --git a/test/CodeGen/Hexagon/autohvx/align-128b.ll b/test/CodeGen/Hexagon/autohvx/align-128b.ll index 8048dc43404..e360fc6ef42 100644 --- a/test/CodeGen/Hexagon/autohvx/align-128b.ll +++ b/test/CodeGen/Hexagon/autohvx/align-128b.ll @@ -961,56 +961,49 @@ define <256 x i8> @test_0078(<256 x i8> %v0) #0 { } ; CHECK-LABEL: test_0079 -; CHECK: [[R0079:r[0-9]+]] = #121 -; CHECK: valign(v1,v0,[[R0079]]) +; CHECK: vlalign(v1,v0,#7) define <256 x i8> @test_0079(<256 x i8> %v0) #0 { %p = shufflevector <256 x i8> %v0, <256 x i8> undef, <256 x i32> ret <256 x i8> %p } ; CHECK-LABEL: test_007a -; CHECK: [[R007a:r[0-9]+]] = #122 -; CHECK: valign(v1,v0,[[R007a]]) +; CHECK: vlalign(v1,v0,#6) define <256 x i8> @test_007a(<256 x i8> %v0) #0 { %p = shufflevector <256 x i8> %v0, <256 x i8> undef, <256 x i32> ret <256 x i8> %p } ; CHECK-LABEL: test_007b -; CHECK: [[R007b:r[0-9]+]] = #123 -; CHECK: valign(v1,v0,[[R007b]]) +; CHECK: vlalign(v1,v0,#5) define <256 x i8> @test_007b(<256 x i8> %v0) #0 { %p = shufflevector <256 x i8> %v0, <256 x i8> undef, <256 x i32> ret <256 x i8> %p } ; CHECK-LABEL: test_007c -; CHECK: [[R007c:r[0-9]+]] = #124 -; CHECK: valign(v1,v0,[[R007c]]) +; CHECK: vlalign(v1,v0,#4) define <256 x i8> @test_007c(<256 x i8> %v0) #0 { %p = shufflevector <256 x i8> %v0, <256 x i8> undef, <256 x i32> ret <256 x i8> %p } ; CHECK-LABEL: test_007d -; CHECK: [[R007d:r[0-9]+]] = #125 -; CHECK: valign(v1,v0,[[R007d]]) +; CHECK: vlalign(v1,v0,#3) define <256 x i8> @test_007d(<256 x i8> %v0) #0 { %p = shufflevector <256 x i8> %v0, <256 x i8> undef, <256 x i32> ret <256 x i8> %p } ; CHECK-LABEL: test_007e -; CHECK: [[R007e:r[0-9]+]] = #126 -; CHECK: valign(v1,v0,[[R007e]]) +; CHECK: vlalign(v1,v0,#2) define <256 x i8> @test_007e(<256 x i8> %v0) #0 { %p = shufflevector <256 x i8> %v0, <256 x i8> undef, <256 x i32> ret <256 x i8> %p } ; CHECK-LABEL: test_007f -; CHECK: [[R007f:r[0-9]+]] = #127 -; CHECK: valign(v1,v0,[[R007f]]) +; CHECK: vlalign(v1,v0,#1) define <256 x i8> @test_007f(<256 x i8> %v0) #0 { %p = shufflevector <256 x i8> %v0, <256 x i8> undef, <256 x i32> ret <256 x i8> %p diff --git a/test/CodeGen/Hexagon/autohvx/align-64b.ll b/test/CodeGen/Hexagon/autohvx/align-64b.ll index 26dd4e36bed..bfc05b6860e 100644 --- a/test/CodeGen/Hexagon/autohvx/align-64b.ll +++ b/test/CodeGen/Hexagon/autohvx/align-64b.ll @@ -449,56 +449,49 @@ define <128 x i8> @test_0038(<128 x i8> %v0) #0 { } ; CHECK-LABEL: test_0039 -; CHECK: [[R0039:r[0-9]+]] = #57 -; CHECK: valign(v1,v0,[[R0039]]) +; CHECK: vlalign(v1,v0,#7) define <128 x i8> @test_0039(<128 x i8> %v0) #0 { %p = shufflevector <128 x i8> %v0, <128 x i8> undef, <128 x i32> ret <128 x i8> %p } ; CHECK-LABEL: test_003a -; CHECK: [[R003a:r[0-9]+]] = #58 -; CHECK: valign(v1,v0,[[R003a]]) +; CHECK: vlalign(v1,v0,#6) define <128 x i8> @test_003a(<128 x i8> %v0) #0 { %p = shufflevector <128 x i8> %v0, <128 x i8> undef, <128 x i32> ret <128 x i8> %p } ; CHECK-LABEL: test_003b -; CHECK: [[R003b:r[0-9]+]] = #59 -; CHECK: valign(v1,v0,[[R003b]]) +; CHECK: vlalign(v1,v0,#5) define <128 x i8> @test_003b(<128 x i8> %v0) #0 { %p = shufflevector <128 x i8> %v0, <128 x i8> undef, <128 x i32> ret <128 x i8> %p } ; CHECK-LABEL: test_003c -; CHECK: [[R003c:r[0-9]+]] = #60 -; CHECK: valign(v1,v0,[[R003c]]) +; CHECK: vlalign(v1,v0,#4) define <128 x i8> @test_003c(<128 x i8> %v0) #0 { %p = shufflevector <128 x i8> %v0, <128 x i8> undef, <128 x i32> ret <128 x i8> %p } ; CHECK-LABEL: test_003d -; CHECK: [[R003d:r[0-9]+]] = #61 -; CHECK: valign(v1,v0,[[R003d]]) +; CHECK: vlalign(v1,v0,#3) define <128 x i8> @test_003d(<128 x i8> %v0) #0 { %p = shufflevector <128 x i8> %v0, <128 x i8> undef, <128 x i32> ret <128 x i8> %p } ; CHECK-LABEL: test_003e -; CHECK: [[R003e:r[0-9]+]] = #62 -; CHECK: valign(v1,v0,[[R003e]]) +; CHECK: vlalign(v1,v0,#2) define <128 x i8> @test_003e(<128 x i8> %v0) #0 { %p = shufflevector <128 x i8> %v0, <128 x i8> undef, <128 x i32> ret <128 x i8> %p } ; CHECK-LABEL: test_003f -; CHECK: [[R003f:r[0-9]+]] = #63 -; CHECK: valign(v1,v0,[[R003f]]) +; CHECK: vlalign(v1,v0,#1) define <128 x i8> @test_003f(<128 x i8> %v0) #0 { %p = shufflevector <128 x i8> %v0, <128 x i8> undef, <128 x i32> ret <128 x i8> %p diff --git a/test/CodeGen/Hexagon/autohvx/align2-128b.ll b/test/CodeGen/Hexagon/autohvx/align2-128b.ll index 204fc2d6d70..e2f7e9cca13 100644 --- a/test/CodeGen/Hexagon/autohvx/align2-128b.ll +++ b/test/CodeGen/Hexagon/autohvx/align2-128b.ll @@ -1082,8 +1082,7 @@ define <128 x i8> @test_120(<128 x i8> %v0, <128 x i8> %v1) #0 { } ; CHECK-LABEL: test_121: -; CHECK: r[[REG121:[0-9]+]] = #121 -; CHECK: v0 = valign(v1,v0,r[[REG121]]) +; CHECK: v0 = vlalign(v1,v0,#7) ; CHECK: jumpr r31 define <128 x i8> @test_121(<128 x i8> %v0, <128 x i8> %v1) #0 { %t0 = shufflevector <128 x i8> %v0, <128 x i8> %v1, <128 x i32> @@ -1091,8 +1090,7 @@ define <128 x i8> @test_121(<128 x i8> %v0, <128 x i8> %v1) #0 { } ; CHECK-LABEL: test_122: -; CHECK: r[[REG122:[0-9]+]] = #122 -; CHECK: v0 = valign(v1,v0,r[[REG122]]) +; CHECK: v0 = vlalign(v1,v0,#6) ; CHECK: jumpr r31 define <128 x i8> @test_122(<128 x i8> %v0, <128 x i8> %v1) #0 { %t0 = shufflevector <128 x i8> %v0, <128 x i8> %v1, <128 x i32> @@ -1100,8 +1098,7 @@ define <128 x i8> @test_122(<128 x i8> %v0, <128 x i8> %v1) #0 { } ; CHECK-LABEL: test_123: -; CHECK: r[[REG123:[0-9]+]] = #123 -; CHECK: v0 = valign(v1,v0,r[[REG123]]) +; CHECK: v0 = vlalign(v1,v0,#5) ; CHECK: jumpr r31 define <128 x i8> @test_123(<128 x i8> %v0, <128 x i8> %v1) #0 { %t0 = shufflevector <128 x i8> %v0, <128 x i8> %v1, <128 x i32> @@ -1109,8 +1106,7 @@ define <128 x i8> @test_123(<128 x i8> %v0, <128 x i8> %v1) #0 { } ; CHECK-LABEL: test_124: -; CHECK: r[[REG124:[0-9]+]] = #124 -; CHECK: v0 = valign(v1,v0,r[[REG124]]) +; CHECK: v0 = vlalign(v1,v0,#4) ; CHECK: jumpr r31 define <128 x i8> @test_124(<128 x i8> %v0, <128 x i8> %v1) #0 { %t0 = shufflevector <128 x i8> %v0, <128 x i8> %v1, <128 x i32> @@ -1118,8 +1114,7 @@ define <128 x i8> @test_124(<128 x i8> %v0, <128 x i8> %v1) #0 { } ; CHECK-LABEL: test_125: -; CHECK: r[[REG125:[0-9]+]] = #125 -; CHECK: v0 = valign(v1,v0,r[[REG125]]) +; CHECK: v0 = vlalign(v1,v0,#3) ; CHECK: jumpr r31 define <128 x i8> @test_125(<128 x i8> %v0, <128 x i8> %v1) #0 { %t0 = shufflevector <128 x i8> %v0, <128 x i8> %v1, <128 x i32> @@ -1127,8 +1122,7 @@ define <128 x i8> @test_125(<128 x i8> %v0, <128 x i8> %v1) #0 { } ; CHECK-LABEL: test_126: -; CHECK: r[[REG126:[0-9]+]] = #126 -; CHECK: v0 = valign(v1,v0,r[[REG126]]) +; CHECK: v0 = vlalign(v1,v0,#2) ; CHECK: jumpr r31 define <128 x i8> @test_126(<128 x i8> %v0, <128 x i8> %v1) #0 { %t0 = shufflevector <128 x i8> %v0, <128 x i8> %v1, <128 x i32> @@ -1136,8 +1130,7 @@ define <128 x i8> @test_126(<128 x i8> %v0, <128 x i8> %v1) #0 { } ; CHECK-LABEL: test_127: -; CHECK: r[[REG127:[0-9]+]] = #127 -; CHECK: v0 = valign(v1,v0,r[[REG127]]) +; CHECK: v0 = vlalign(v1,v0,#1) ; CHECK: jumpr r31 define <128 x i8> @test_127(<128 x i8> %v0, <128 x i8> %v1) #0 { %t0 = shufflevector <128 x i8> %v0, <128 x i8> %v1, <128 x i32> diff --git a/test/CodeGen/Hexagon/autohvx/align2-64b.ll b/test/CodeGen/Hexagon/autohvx/align2-64b.ll index 91b54cb08c2..51697d34cc1 100644 --- a/test/CodeGen/Hexagon/autohvx/align2-64b.ll +++ b/test/CodeGen/Hexagon/autohvx/align2-64b.ll @@ -506,8 +506,7 @@ define <64 x i8> @test_56(<64 x i8> %v0, <64 x i8> %v1) #0 { } ; CHECK-LABEL: test_57: -; CHECK: r[[REG57:[0-9]+]] = #57 -; CHECK: v0 = valign(v1,v0,r[[REG57]]) +; CHECK: v0 = vlalign(v1,v0,#7) ; CHECK: jumpr r31 define <64 x i8> @test_57(<64 x i8> %v0, <64 x i8> %v1) #0 { %t0 = shufflevector <64 x i8> %v0, <64 x i8> %v1, <64 x i32> @@ -515,8 +514,7 @@ define <64 x i8> @test_57(<64 x i8> %v0, <64 x i8> %v1) #0 { } ; CHECK-LABEL: test_58: -; CHECK: r[[REG58:[0-9]+]] = #58 -; CHECK: v0 = valign(v1,v0,r[[REG58]]) +; CHECK: v0 = vlalign(v1,v0,#6) ; CHECK: jumpr r31 define <64 x i8> @test_58(<64 x i8> %v0, <64 x i8> %v1) #0 { %t0 = shufflevector <64 x i8> %v0, <64 x i8> %v1, <64 x i32> @@ -524,8 +522,7 @@ define <64 x i8> @test_58(<64 x i8> %v0, <64 x i8> %v1) #0 { } ; CHECK-LABEL: test_59: -; CHECK: r[[REG59:[0-9]+]] = #59 -; CHECK: v0 = valign(v1,v0,r[[REG59]]) +; CHECK: v0 = vlalign(v1,v0,#5) ; CHECK: jumpr r31 define <64 x i8> @test_59(<64 x i8> %v0, <64 x i8> %v1) #0 { %t0 = shufflevector <64 x i8> %v0, <64 x i8> %v1, <64 x i32> @@ -533,8 +530,7 @@ define <64 x i8> @test_59(<64 x i8> %v0, <64 x i8> %v1) #0 { } ; CHECK-LABEL: test_60: -; CHECK: r[[REG60:[0-9]+]] = #60 -; CHECK: v0 = valign(v1,v0,r[[REG60]]) +; CHECK: v0 = vlalign(v1,v0,#4) ; CHECK: jumpr r31 define <64 x i8> @test_60(<64 x i8> %v0, <64 x i8> %v1) #0 { %t0 = shufflevector <64 x i8> %v0, <64 x i8> %v1, <64 x i32> @@ -542,8 +538,7 @@ define <64 x i8> @test_60(<64 x i8> %v0, <64 x i8> %v1) #0 { } ; CHECK-LABEL: test_61: -; CHECK: r[[REG61:[0-9]+]] = #61 -; CHECK: v0 = valign(v1,v0,r[[REG61]]) +; CHECK: v0 = vlalign(v1,v0,#3) ; CHECK: jumpr r31 define <64 x i8> @test_61(<64 x i8> %v0, <64 x i8> %v1) #0 { %t0 = shufflevector <64 x i8> %v0, <64 x i8> %v1, <64 x i32> @@ -551,8 +546,7 @@ define <64 x i8> @test_61(<64 x i8> %v0, <64 x i8> %v1) #0 { } ; CHECK-LABEL: test_62: -; CHECK: r[[REG62:[0-9]+]] = #62 -; CHECK: v0 = valign(v1,v0,r[[REG62]]) +; CHECK: v0 = vlalign(v1,v0,#2) ; CHECK: jumpr r31 define <64 x i8> @test_62(<64 x i8> %v0, <64 x i8> %v1) #0 { %t0 = shufflevector <64 x i8> %v0, <64 x i8> %v1, <64 x i32> @@ -560,8 +554,7 @@ define <64 x i8> @test_62(<64 x i8> %v0, <64 x i8> %v1) #0 { } ; CHECK-LABEL: test_63: -; CHECK: r[[REG63:[0-9]+]] = #63 -; CHECK: v0 = valign(v1,v0,r[[REG63]]) +; CHECK: v0 = vlalign(v1,v0,#1) ; CHECK: jumpr r31 define <64 x i8> @test_63(<64 x i8> %v0, <64 x i8> %v1) #0 { %t0 = shufflevector <64 x i8> %v0, <64 x i8> %v1, <64 x i32>