From d51b5f75d3c89ba56254e30eb488ba0bb9fa3db3 Mon Sep 17 00:00:00 2001 From: Alexey Karyakin Date: Mon, 9 Jun 2025 08:51:40 -0700 Subject: [PATCH] [Hexagon] Shuffle patterns to vdeal + vpack Lowering shuffle patterns to vdeal + vpack caused an assertion because the vdeal parameter value is negative but an unsigned one was expected. --- .../Target/Hexagon/HexagonISelDAGToDAGHVX.cpp | 12 +++++++++--- llvm/test/CodeGen/Hexagon/hvx-vdeal-vpack.ll | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 llvm/test/CodeGen/Hexagon/hvx-vdeal-vpack.ll diff --git a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp index 613048be52a2f..df2cfd07d8cc0 100644 --- a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp +++ b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp @@ -958,7 +958,8 @@ namespace llvm { void select(SDNode *ISelN); void materialize(const ResultStack &Results); - SDValue getConst32(int Val, const SDLoc &dl); + SDValue getConst32(unsigned Val, const SDLoc &dl); + SDValue getSignedConst32(int Val, const SDLoc &dl); SDValue getVectorConstant(ArrayRef Data, const SDLoc &dl); enum : unsigned { @@ -2145,7 +2146,8 @@ OpRef HvxSelector::contracting(ShuffleMask SM, OpRef Va, OpRef Vb, for (int i = 0, e = std::size(Opcodes); i != e; ++i) { auto [Size, Odd] = Packs[i]; if (same(SM.Mask, shuffles::mask(shuffles::vdeal, HwLen, Size, Odd))) { - Results.push(Hexagon::A2_tfrsi, MVT::i32, {getConst32(-2 * Size, dl)}); + Results.push(Hexagon::A2_tfrsi, MVT::i32, + {getSignedConst32(-2 * Size, dl)}); Results.push(Hexagon::V6_vdealvdd, PairTy, {Vb, Va, OpRef::res(-1)}); auto vdeal = OpRef::res(Results.top()); Results.push(Opcodes[i], SingleTy, @@ -2545,10 +2547,14 @@ OpRef HvxSelector::butterfly(ShuffleMask SM, OpRef Va, ResultStack &Results) { return OpRef::fail(); } -SDValue HvxSelector::getConst32(int Val, const SDLoc &dl) { +SDValue HvxSelector::getConst32(unsigned Val, const SDLoc &dl) { return DAG.getTargetConstant(Val, dl, MVT::i32); } +SDValue HvxSelector::getSignedConst32(int Val, const SDLoc &dl) { + return DAG.getSignedTargetConstant(Val, dl, MVT::i32); +} + SDValue HvxSelector::getVectorConstant(ArrayRef Data, const SDLoc &dl) { SmallVector Elems; diff --git a/llvm/test/CodeGen/Hexagon/hvx-vdeal-vpack.ll b/llvm/test/CodeGen/Hexagon/hvx-vdeal-vpack.ll new file mode 100644 index 0000000000000..e1f74d17141fb --- /dev/null +++ b/llvm/test/CodeGen/Hexagon/hvx-vdeal-vpack.ll @@ -0,0 +1,18 @@ +; REQUIRES: asserts +; RUN: llc -mtriple=hexagon -O2 < %s | FileCheck %s + +;; Test that a vdeal + vpack can be lowered. + +; CHECK: v[[#V1:]]:[[#V0:]] = vdeal(v[[#]],v[[#]],r[[#]]) +; CHECK: v[[#]].h = vpacke(v[[#V1]].w,v[[#V0]].w) + +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" +target triple = "hexagon" + +define dso_local <64 x i16> @f(<128 x i16> noundef %index) local_unnamed_addr #1 { +entry: + %b = shufflevector <128 x i16> %index, <128 x i16> poison, <64 x i32> + ret <64 x i16> %b +} + +attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn "target-cpu"="hexagonv75" "target-features"="+hvx-length128b,+hvx" }