Skip to content

Commit bbcb5f4

Browse files
Shuffle patterns to vdeal + vpack (llvm#159464)
Lowering shuffle patterns to vdeal + vpack caused an assertion because the vdeal parameter value is negative but an unsigned one was expected.
1 parent 0ade346 commit bbcb5f4

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,8 @@ namespace llvm {
958958
void select(SDNode *ISelN);
959959
void materialize(const ResultStack &Results);
960960

961-
SDValue getConst32(int Val, const SDLoc &dl);
961+
SDValue getConst32(unsigned Val, const SDLoc &dl);
962+
SDValue getSignedConst32(int Val, const SDLoc &dl);
962963
SDValue getVectorConstant(ArrayRef<uint8_t> Data, const SDLoc &dl);
963964

964965
enum : unsigned {
@@ -2145,7 +2146,8 @@ OpRef HvxSelector::contracting(ShuffleMask SM, OpRef Va, OpRef Vb,
21452146
for (int i = 0, e = std::size(Opcodes); i != e; ++i) {
21462147
auto [Size, Odd] = Packs[i];
21472148
if (same(SM.Mask, shuffles::mask(shuffles::vdeal, HwLen, Size, Odd))) {
2148-
Results.push(Hexagon::A2_tfrsi, MVT::i32, {getConst32(-2 * Size, dl)});
2149+
Results.push(Hexagon::A2_tfrsi, MVT::i32,
2150+
{getSignedConst32(-2 * Size, dl)});
21492151
Results.push(Hexagon::V6_vdealvdd, PairTy, {Vb, Va, OpRef::res(-1)});
21502152
auto vdeal = OpRef::res(Results.top());
21512153
Results.push(Opcodes[i], SingleTy,
@@ -2545,10 +2547,14 @@ OpRef HvxSelector::butterfly(ShuffleMask SM, OpRef Va, ResultStack &Results) {
25452547
return OpRef::fail();
25462548
}
25472549

2548-
SDValue HvxSelector::getConst32(int Val, const SDLoc &dl) {
2550+
SDValue HvxSelector::getConst32(unsigned Val, const SDLoc &dl) {
25492551
return DAG.getTargetConstant(Val, dl, MVT::i32);
25502552
}
25512553

2554+
SDValue HvxSelector::getSignedConst32(int Val, const SDLoc &dl) {
2555+
return DAG.getSignedTargetConstant(Val, dl, MVT::i32);
2556+
}
2557+
25522558
SDValue HvxSelector::getVectorConstant(ArrayRef<uint8_t> Data,
25532559
const SDLoc &dl) {
25542560
SmallVector<SDValue, 128> Elems;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; REQUIRES: asserts
2+
; RUN: llc -mtriple=hexagon -O2 < %s | FileCheck %s
3+
4+
;; Test that a vdeal + vpack can be lowered.
5+
6+
; CHECK: v[[#V1:]]:[[#V0:]] = vdeal(v[[#]],v[[#]],r[[#]])
7+
; CHECK: v[[#]].h = vpacke(v[[#V1]].w,v[[#V0]].w)
8+
9+
target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
10+
target triple = "hexagon"
11+
12+
define dso_local <64 x i16> @f(<128 x i16> noundef %index) local_unnamed_addr #1 {
13+
entry:
14+
%b = shufflevector <128 x i16> %index, <128 x i16> poison, <64 x i32> <i32 0, i32 4, i32 8, i32 12, i32 16, i32 20, i32 24, i32 28, i32 32, i32 36, i32 40, i32 44, i32 48, i32 52, i32 56, i32 60, i32 64, i32 68, i32 72, i32 76, i32 80, i32 84, i32 88, i32 92, i32 96, i32 100, i32 104, i32 108, i32 112, i32 116, i32 120, i32 124, i32 2, i32 6, i32 10, i32 14, i32 18, i32 22, i32 26, i32 30, i32 34, i32 38, i32 42, i32 46, i32 50, i32 54, i32 58, i32 62, i32 66, i32 70, i32 74, i32 78, i32 82, i32 86, i32 90, i32 94, i32 98, i32 102, i32 106, i32 110, i32 114, i32 118, i32 122, i32 126>
15+
ret <64 x i16> %b
16+
}
17+
18+
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn "target-cpu"="hexagonv75" "target-features"="+hvx-length128b,+hvx" }

0 commit comments

Comments
 (0)