Author: SiHuaN
Date: 2026-11-17T15:59:59+08:00
New Revision: 0855aa8e9f0681b53f9fe4a92ce682dbd8728d6e

URL: 
https://github.com/llvm/llvm-project/commit/0855aa8e9f0681b53f9fe4a92ce682dbd8728d6e
DIFF: 
https://github.com/llvm/llvm-project/commit/0855aa8e9f0681b53f9fe4a92ce682dbd8728d6e.diff

LOG: [RISCV][P-ext] Add scalar saturating and rounding shift intrinsics 
(#241730)

Added: 
    

Modified: 
    clang/include/clang/Basic/BuiltinsRISCV.td
    clang/lib/CodeGen/TargetBuiltins/RISCV.cpp
    clang/lib/Headers/riscv_packed_simd.h
    clang/test/CodeGen/RISCV/rvp-intrinsics.c
    cross-project-tests/intrinsic-header-tests/riscv_packed_simd.c
    llvm/include/llvm/IR/IntrinsicsRISCV.td
    llvm/lib/Target/RISCV/RISCVISelLowering.cpp
    llvm/lib/Target/RISCV/RISCVInstrInfoP.td
    llvm/test/CodeGen/RISCV/rvp-scalar-rv64.ll
    llvm/test/CodeGen/RISCV/rvp-scalar.ll

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/BuiltinsRISCV.td 
b/clang/include/clang/Basic/BuiltinsRISCV.td
index 1de428b1afd61..29b566ce2db6e 100644
--- a/clang/include/clang/Basic/BuiltinsRISCV.td
+++ b/clang/include/clang/Basic/BuiltinsRISCV.td
@@ -287,6 +287,18 @@ def sati_i64 : RISCVBuiltin<"int64_t(int64_t, _Constant 
unsigned int)">;
 def usati_u64 : RISCVBuiltin<"uint64_t(int64_t, _Constant unsigned int)">;
 } // Features = "experimental-p,64bit"
 
+// Scalar Saturating and Rounding Shift
+def ssha_i32 : RISCVBuiltin<"int32_t(int32_t, int)">;
+def sshar_i32 : RISCVBuiltin<"int32_t(int32_t, int)">;
+def sshl_u32 : RISCVBuiltin<"uint32_t(uint32_t, int)">;
+def sshlr_u32 : RISCVBuiltin<"uint32_t(uint32_t, int)">;
+let Features = "experimental-p,64bit" in {
+def sha_i64 : RISCVBuiltin<"int64_t(int64_t, int)">;
+def shar_i64 : RISCVBuiltin<"int64_t(int64_t, int)">;
+def shl_u64 : RISCVBuiltin<"uint64_t(uint64_t, int)">;
+def shlr_u64 : RISCVBuiltin<"uint64_t(uint64_t, int)">;
+} // Features = "experimental-p,64bit"
+
 // Scalar Narrowing Clip
 def nclipu_u32  : RISCVBuiltin<"uint32_t(uint64_t, unsigned int)">;
 def nclipru_u32 : RISCVBuiltin<"uint32_t(uint64_t, unsigned int)">;

diff  --git a/clang/lib/CodeGen/TargetBuiltins/RISCV.cpp 
b/clang/lib/CodeGen/TargetBuiltins/RISCV.cpp
index e19acce0cdc44..4bf1df69505c2 100644
--- a/clang/lib/CodeGen/TargetBuiltins/RISCV.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/RISCV.cpp
@@ -1722,6 +1722,32 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned 
BuiltinID,
     ID = Intrinsic::riscv_ssh1sadd_i32;
     break;
 
+  // Scalar Saturating and Rounding Shift
+  case RISCV::BI__builtin_riscv_ssha_i32:
+    ID = Intrinsic::riscv_ssha_i32;
+    break;
+  case RISCV::BI__builtin_riscv_sshar_i32:
+    ID = Intrinsic::riscv_sshar_i32;
+    break;
+  case RISCV::BI__builtin_riscv_sshl_u32:
+    ID = Intrinsic::riscv_sshl_u32;
+    break;
+  case RISCV::BI__builtin_riscv_sshlr_u32:
+    ID = Intrinsic::riscv_sshlr_u32;
+    break;
+  case RISCV::BI__builtin_riscv_sha_i64:
+    ID = Intrinsic::riscv_sha_i64;
+    break;
+  case RISCV::BI__builtin_riscv_shar_i64:
+    ID = Intrinsic::riscv_shar_i64;
+    break;
+  case RISCV::BI__builtin_riscv_shl_u64:
+    ID = Intrinsic::riscv_shl_u64;
+    break;
+  case RISCV::BI__builtin_riscv_shlr_u64:
+    ID = Intrinsic::riscv_shlr_u64;
+    break;
+
   // Scalar Comparison
   case RISCV::BI__builtin_riscv_mseq_u32:
     ID = Intrinsic::riscv_mseq_u32;

diff  --git a/clang/lib/Headers/riscv_packed_simd.h 
b/clang/lib/Headers/riscv_packed_simd.h
index 104283faca173..6eab0bcdac809 100644
--- a/clang/lib/Headers/riscv_packed_simd.h
+++ b/clang/lib/Headers/riscv_packed_simd.h
@@ -554,6 +554,18 @@ __packed_pabs(abs_u64, int64_t, uint64_t)
 #define __riscv_usati_u64(rs1, width) __builtin_riscv_usati_u64(rs1, width)
 #endif
 
+/* Scalar Saturating and Rounding Shift */
+__packed_binary_builtin_mixed(ssha_i32, int32_t, int32_t, int, 
__builtin_riscv_ssha_i32)
+__packed_binary_builtin_mixed(sshar_i32, int32_t, int32_t, int, 
__builtin_riscv_sshar_i32)
+__packed_binary_builtin_mixed(sshl_u32, uint32_t, uint32_t, int, 
__builtin_riscv_sshl_u32)
+__packed_binary_builtin_mixed(sshlr_u32, uint32_t, uint32_t, int, 
__builtin_riscv_sshlr_u32)
+#if __riscv_xlen == 64
+__packed_binary_builtin_mixed(sha_i64, int64_t, int64_t, int, 
__builtin_riscv_sha_i64)
+__packed_binary_builtin_mixed(shar_i64, int64_t, int64_t, int, 
__builtin_riscv_shar_i64)
+__packed_binary_builtin_mixed(shl_u64, uint64_t, uint64_t, int, 
__builtin_riscv_shl_u64)
+__packed_binary_builtin_mixed(shlr_u64, uint64_t, uint64_t, int, 
__builtin_riscv_shlr_u64)
+#endif
+
 /* Scalar Narrowing Clip */
 __packed_binary_builtin_mixed(nclipu_u32, uint32_t, uint64_t, unsigned,
                               __builtin_riscv_nclipu_u32)

diff  --git a/clang/test/CodeGen/RISCV/rvp-intrinsics.c 
b/clang/test/CodeGen/RISCV/rvp-intrinsics.c
index dcca0f9d328eb..5ee7bbb8da9b7 100644
--- a/clang/test/CodeGen/RISCV/rvp-intrinsics.c
+++ b/clang/test/CodeGen/RISCV/rvp-intrinsics.c
@@ -748,6 +748,114 @@ uint64_t test_usati_u64(int64_t a) {
 }
 #endif
 
+/* Scalar Saturating and Rounding Shift */
+
+// RV32-LABEL: define dso_local i32 @test_ssha_i32(
+// RV32-SAME: i32 noundef [[A:%.*]], i32 noundef [[S:%.*]]) #[[ATTR0]] {
+// RV32-NEXT:  [[ENTRY:.*:]]
+// RV32-NEXT:    [[TMP0:%.*]] = call i32 @llvm.riscv.ssha.i32(i32 [[A]], i32 
[[S]])
+// RV32-NEXT:    ret i32 [[TMP0]]
+//
+// RV64-LABEL: define dso_local signext i32 @test_ssha_i32(
+// RV64-SAME: i32 noundef signext [[A:%.*]], i32 noundef signext [[S:%.*]]) 
#[[ATTR0]] {
+// RV64-NEXT:  [[ENTRY:.*:]]
+// RV64-NEXT:    [[TMP0:%.*]] = call i32 @llvm.riscv.ssha.i32(i32 [[A]], i32 
[[S]])
+// RV64-NEXT:    ret i32 [[TMP0]]
+//
+int32_t test_ssha_i32(int32_t a, int s) {
+  return __riscv_ssha_i32(a, s);
+}
+
+// RV32-LABEL: define dso_local i32 @test_sshar_i32(
+// RV32-SAME: i32 noundef [[A:%.*]], i32 noundef [[S:%.*]]) #[[ATTR0]] {
+// RV32-NEXT:  [[ENTRY:.*:]]
+// RV32-NEXT:    [[TMP0:%.*]] = call i32 @llvm.riscv.sshar.i32(i32 [[A]], i32 
[[S]])
+// RV32-NEXT:    ret i32 [[TMP0]]
+//
+// RV64-LABEL: define dso_local signext i32 @test_sshar_i32(
+// RV64-SAME: i32 noundef signext [[A:%.*]], i32 noundef signext [[S:%.*]]) 
#[[ATTR0]] {
+// RV64-NEXT:  [[ENTRY:.*:]]
+// RV64-NEXT:    [[TMP0:%.*]] = call i32 @llvm.riscv.sshar.i32(i32 [[A]], i32 
[[S]])
+// RV64-NEXT:    ret i32 [[TMP0]]
+//
+int32_t test_sshar_i32(int32_t a, int s) {
+  return __riscv_sshar_i32(a, s);
+}
+
+// RV32-LABEL: define dso_local i32 @test_sshl_u32(
+// RV32-SAME: i32 noundef [[A:%.*]], i32 noundef [[S:%.*]]) #[[ATTR0]] {
+// RV32-NEXT:  [[ENTRY:.*:]]
+// RV32-NEXT:    [[TMP0:%.*]] = call i32 @llvm.riscv.sshl.u32(i32 [[A]], i32 
[[S]])
+// RV32-NEXT:    ret i32 [[TMP0]]
+//
+// RV64-LABEL: define dso_local signext i32 @test_sshl_u32(
+// RV64-SAME: i32 noundef signext [[A:%.*]], i32 noundef signext [[S:%.*]]) 
#[[ATTR0]] {
+// RV64-NEXT:  [[ENTRY:.*:]]
+// RV64-NEXT:    [[TMP0:%.*]] = call i32 @llvm.riscv.sshl.u32(i32 [[A]], i32 
[[S]])
+// RV64-NEXT:    ret i32 [[TMP0]]
+//
+uint32_t test_sshl_u32(uint32_t a, int s) {
+  return __riscv_sshl_u32(a, s);
+}
+
+// RV32-LABEL: define dso_local i32 @test_sshlr_u32(
+// RV32-SAME: i32 noundef [[A:%.*]], i32 noundef [[S:%.*]]) #[[ATTR0]] {
+// RV32-NEXT:  [[ENTRY:.*:]]
+// RV32-NEXT:    [[TMP0:%.*]] = call i32 @llvm.riscv.sshlr.u32(i32 [[A]], i32 
[[S]])
+// RV32-NEXT:    ret i32 [[TMP0]]
+//
+// RV64-LABEL: define dso_local signext i32 @test_sshlr_u32(
+// RV64-SAME: i32 noundef signext [[A:%.*]], i32 noundef signext [[S:%.*]]) 
#[[ATTR0]] {
+// RV64-NEXT:  [[ENTRY:.*:]]
+// RV64-NEXT:    [[TMP0:%.*]] = call i32 @llvm.riscv.sshlr.u32(i32 [[A]], i32 
[[S]])
+// RV64-NEXT:    ret i32 [[TMP0]]
+//
+uint32_t test_sshlr_u32(uint32_t a, int s) {
+  return __riscv_sshlr_u32(a, s);
+}
+
+#if __riscv_xlen == 64
+// RV64-LABEL: define dso_local i64 @test_sha_i64(
+// RV64-SAME: i64 noundef [[A:%.*]], i32 noundef signext [[S:%.*]]) #[[ATTR0]] 
{
+// RV64-NEXT:  [[ENTRY:.*:]]
+// RV64-NEXT:    [[TMP0:%.*]] = call i64 @llvm.riscv.sha.i64(i64 [[A]], i32 
[[S]])
+// RV64-NEXT:    ret i64 [[TMP0]]
+//
+int64_t test_sha_i64(int64_t a, int s) {
+  return __riscv_sha_i64(a, s);
+}
+
+// RV64-LABEL: define dso_local i64 @test_shar_i64(
+// RV64-SAME: i64 noundef [[A:%.*]], i32 noundef signext [[S:%.*]]) #[[ATTR0]] 
{
+// RV64-NEXT:  [[ENTRY:.*:]]
+// RV64-NEXT:    [[TMP0:%.*]] = call i64 @llvm.riscv.shar.i64(i64 [[A]], i32 
[[S]])
+// RV64-NEXT:    ret i64 [[TMP0]]
+//
+int64_t test_shar_i64(int64_t a, int s) {
+  return __riscv_shar_i64(a, s);
+}
+
+// RV64-LABEL: define dso_local i64 @test_shl_u64(
+// RV64-SAME: i64 noundef [[A:%.*]], i32 noundef signext [[S:%.*]]) #[[ATTR0]] 
{
+// RV64-NEXT:  [[ENTRY:.*:]]
+// RV64-NEXT:    [[TMP0:%.*]] = call i64 @llvm.riscv.shl.u64(i64 [[A]], i32 
[[S]])
+// RV64-NEXT:    ret i64 [[TMP0]]
+//
+uint64_t test_shl_u64(uint64_t a, int s) {
+  return __riscv_shl_u64(a, s);
+}
+
+// RV64-LABEL: define dso_local i64 @test_shlr_u64(
+// RV64-SAME: i64 noundef [[A:%.*]], i32 noundef signext [[S:%.*]]) #[[ATTR0]] 
{
+// RV64-NEXT:  [[ENTRY:.*:]]
+// RV64-NEXT:    [[TMP0:%.*]] = call i64 @llvm.riscv.shlr.u64(i64 [[A]], i32 
[[S]])
+// RV64-NEXT:    ret i64 [[TMP0]]
+//
+uint64_t test_shlr_u64(uint64_t a, int s) {
+  return __riscv_shlr_u64(a, s);
+}
+#endif
+
 /* Scalar Narrowing Clip */
 
 // RV32-LABEL: define dso_local i32 @test_nclipu_u32(

diff  --git a/cross-project-tests/intrinsic-header-tests/riscv_packed_simd.c 
b/cross-project-tests/intrinsic-header-tests/riscv_packed_simd.c
index 666f69e6deaac..768817fc08bf0 100644
--- a/cross-project-tests/intrinsic-header-tests/riscv_packed_simd.c
+++ b/cross-project-tests/intrinsic-header-tests/riscv_packed_simd.c
@@ -212,6 +212,62 @@ int64_t test_sati_i64(int64_t a) { return 
__riscv_sati_i64(a, 16); }
 uint64_t test_usati_u64(int64_t a) { return __riscv_usati_u64(a, 16); }
 #endif
 
+// CHECK-LABEL: test_ssha_i32:
+// RV32:        ssha{{[[:space:]]}}
+// RV64:        pssha.ws
+int32_t test_ssha_i32(int32_t a, int s) { return __riscv_ssha_i32(a, s); }
+
+// CHECK-LABEL: test_ssha_i32_imm:
+// RV32:        sslai{{[[:space:]]}}
+// RV64:        psslai.w
+int32_t test_ssha_i32_imm(int32_t a) { return __riscv_ssha_i32(a, 3); }
+
+// CHECK-LABEL: test_sshar_i32:
+// RV32:        sshar{{[[:space:]]}}
+// RV64:        psshar.ws
+int32_t test_sshar_i32(int32_t a, int s) { return __riscv_sshar_i32(a, s); }
+
+// CHECK-LABEL: test_sshar_i32_negimm:
+// RV32:        srari{{[[:space:]]}}
+// RV64:        psrari.w
+int32_t test_sshar_i32_negimm(int32_t a) { return __riscv_sshar_i32(a, -3); }
+
+// CHECK-LABEL: test_sshl_u32:
+// RV32:        sshl{{[[:space:]]}}
+// RV64:        psshl.ws
+uint32_t test_sshl_u32(uint32_t a, int s) { return __riscv_sshl_u32(a, s); }
+
+// CHECK-LABEL: test_sshlr_u32:
+// RV32:        sshlr{{[[:space:]]}}
+// RV64:        psshlr.ws
+uint32_t test_sshlr_u32(uint32_t a, int s) { return __riscv_sshlr_u32(a, s); }
+
+#if __riscv_xlen == 64
+// RV64-LABEL: test_sha_i64:
+// RV64:        sha{{[[:space:]]}}
+int64_t test_sha_i64(int64_t a, int s) { return __riscv_sha_i64(a, s); }
+
+// RV64-LABEL: test_sha_i64_imm:
+// RV64:        slli{{[[:space:]]}}
+int64_t test_sha_i64_imm(int64_t a) { return __riscv_sha_i64(a, 3); }
+
+// RV64-LABEL: test_shar_i64:
+// RV64:        shar{{[[:space:]]}}
+int64_t test_shar_i64(int64_t a, int s) { return __riscv_shar_i64(a, s); }
+
+// RV64-LABEL: test_shar_i64_negimm:
+// RV64:        srari{{[[:space:]]}}
+int64_t test_shar_i64_negimm(int64_t a) { return __riscv_shar_i64(a, -3); }
+
+// RV64-LABEL: test_shl_u64:
+// RV64:        shl{{[[:space:]]}}
+uint64_t test_shl_u64(uint64_t a, int s) { return __riscv_shl_u64(a, s); }
+
+// RV64-LABEL: test_shlr_u64:
+// RV64:        shlr{{[[:space:]]}}
+uint64_t test_shlr_u64(uint64_t a, int s) { return __riscv_shlr_u64(a, s); }
+#endif
+
 // CHECK-LABEL: test_nclipu_u32:
 // RV32:        nclipu{{[[:space:]]}}
 // RV64:        srl{{[[:space:]]}}

diff  --git a/llvm/include/llvm/IR/IntrinsicsRISCV.td 
b/llvm/include/llvm/IR/IntrinsicsRISCV.td
index 48019b212a42e..ace9384cb1fe8 100644
--- a/llvm/include/llvm/IR/IntrinsicsRISCV.td
+++ b/llvm/include/llvm/IR/IntrinsicsRISCV.td
@@ -2184,11 +2184,13 @@ class RVPBinaryIntrinsic
   def int_riscv_pmulhsu  : RVPBinaryIntrinsic;
   def int_riscv_pmulhrsu : RVPBinaryIntrinsic;
 
-  // Scalar Averaging Addition and Subtraction. On RV64 these map to the
-  // packed paadd.w family on the low words.
+  // Scalar binary intrinsic on i32 operands. On RV64 these map to a packed .w
+  // instruction on the low words.
   class RVPScalarBinaryIntrinsic
       : DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
                               [IntrNoMem, IntrSpeculatable]>;
+
+  // Scalar Averaging Addition and Subtraction.
   def int_riscv_aadd_i32  : RVPScalarBinaryIntrinsic;
   def int_riscv_aaddu_u32 : RVPScalarBinaryIntrinsic;
   def int_riscv_asub_i32  : RVPScalarBinaryIntrinsic;
@@ -2197,6 +2199,21 @@ class RVPBinaryIntrinsic
   // Scalar Shift-Add. On RV64 this maps to pssh1sadd.w on the low words.
   def int_riscv_ssh1sadd_i32 : RVPScalarBinaryIntrinsic;
 
+  // Scalar Saturating and Rounding Shifts. The 32-bit forms saturate, the
+  // 64-bit forms do not. The second operand is a signed shift amount; negative
+  // amounts shift right.
+  class RVPScalarShift64Intrinsic
+      : DefaultAttrsIntrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i32_ty],
+                              [IntrNoMem, IntrSpeculatable]>;
+  def int_riscv_ssha_i32  : RVPScalarBinaryIntrinsic;
+  def int_riscv_sshar_i32 : RVPScalarBinaryIntrinsic;
+  def int_riscv_sshl_u32  : RVPScalarBinaryIntrinsic;
+  def int_riscv_sshlr_u32 : RVPScalarBinaryIntrinsic;
+  def int_riscv_sha_i64  : RVPScalarShift64Intrinsic;
+  def int_riscv_shar_i64 : RVPScalarShift64Intrinsic;
+  def int_riscv_shl_u64  : RVPScalarShift64Intrinsic;
+  def int_riscv_shlr_u64 : RVPScalarShift64Intrinsic;
+
   // Scalar Comparison. The result is a 0/-1 mask; the derived forms
   // (msne/msgt/msge/...) are composed in the header.
   class RVPScalarCmpIntrinsic

diff  --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 609a7fc2acba4..45b34b60473b7 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -9684,7 +9684,7 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
           Opc = RISCVISD::PSRA;
           break;
         case ISD::SSHLSAT:
-          Opc = RISCVISD::PSSHA;
+          Opc = RISCVISD::SSHA;
           break;
         }
         return DAG.getNode(Opc, SDLoc(Op), Op.getValueType(), Op.getOperand(0),
@@ -12470,13 +12470,21 @@ static unsigned getRVPShiftOpcode(Intrinsic::ID 
IntNo) {
   case Intrinsic::riscv_psra:
     return RISCVISD::PSRA;
   case Intrinsic::riscv_pssha:
-    return RISCVISD::PSSHA;
+    return RISCVISD::SSHA;
   case Intrinsic::riscv_psshar:
-    return RISCVISD::PSSHAR;
+    return RISCVISD::SSHAR;
   case Intrinsic::riscv_psshl:
-    return RISCVISD::PSSHL;
+    return RISCVISD::SSHL;
   case Intrinsic::riscv_psshlr:
-    return RISCVISD::PSSHLR;
+    return RISCVISD::SSHLR;
+  case Intrinsic::riscv_sha_i64:
+    return RISCVISD::SHA;
+  case Intrinsic::riscv_shar_i64:
+    return RISCVISD::SHAR;
+  case Intrinsic::riscv_shl_u64:
+    return RISCVISD::SHL;
+  case Intrinsic::riscv_shlr_u64:
+    return RISCVISD::SHLR;
   }
 }
 
@@ -12557,7 +12565,7 @@ static unsigned getRVPScalarOpcode(unsigned IntNo) {
   default:
     llvm_unreachable(
         "Unexpected RISC-V scalar averaging, multiply high, Q-format "
-        "multiply or multiply high accumulate intrinsic");
+        "multiply, multiply high accumulate or saturating shift intrinsic");
   case Intrinsic::riscv_aadd_i32:
     return ISD::AVGFLOORS;
   case Intrinsic::riscv_aaddu_u32:
@@ -12568,6 +12576,14 @@ static unsigned getRVPScalarOpcode(unsigned IntNo) {
     return ISD::AVGSUBFLOORU;
   case Intrinsic::riscv_ssh1sadd_i32:
     return RISCVISD::SSH1SADD;
+  case Intrinsic::riscv_ssha_i32:
+    return RISCVISD::SSHA;
+  case Intrinsic::riscv_sshar_i32:
+    return RISCVISD::SSHAR;
+  case Intrinsic::riscv_sshl_u32:
+    return RISCVISD::SSHL;
+  case Intrinsic::riscv_sshlr_u32:
+    return RISCVISD::SSHLR;
   case Intrinsic::riscv_mseq_u32:
     return RISCVISD::MSEQ;
   case Intrinsic::riscv_mslt_i32:
@@ -13419,7 +13435,13 @@ SDValue 
RISCVTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
   case Intrinsic::riscv_pssha:
   case Intrinsic::riscv_psshar:
   case Intrinsic::riscv_psshl:
-  case Intrinsic::riscv_psshlr: {
+  case Intrinsic::riscv_psshlr:
+  case Intrinsic::riscv_sha_i64:
+  case Intrinsic::riscv_shar_i64:
+  case Intrinsic::riscv_shl_u64:
+  case Intrinsic::riscv_shlr_u64: {
+    // The 64-bit scalar shifts share the shift amount handling here; the 
32-bit
+    // scalar shifts are lowered with the scalar i32 intrinsics below.
     SDValue ShAmt = Op.getOperand(2);
     ShAmt = DAG.getAnyExtOrTrunc(ShAmt, DL, XLenVT);
     return DAG.getNode(getRVPShiftOpcode(IntNo), DL, Op.getValueType(),
@@ -13577,6 +13599,10 @@ SDValue 
RISCVTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
   case Intrinsic::riscv_asub_i32:
   case Intrinsic::riscv_asubu_u32:
   case Intrinsic::riscv_ssh1sadd_i32:
+  case Intrinsic::riscv_ssha_i32:
+  case Intrinsic::riscv_sshar_i32:
+  case Intrinsic::riscv_sshl_u32:
+  case Intrinsic::riscv_sshlr_u32:
   case Intrinsic::riscv_mseq_u32:
   case Intrinsic::riscv_mslt_i32:
   case Intrinsic::riscv_msltu_u32:
@@ -18725,6 +18751,23 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
       Results.push_back(DAG.getExtractVectorElt(DL, MVT::i32, Res, 0));
       return;
     }
+    case Intrinsic::riscv_ssha_i32:
+    case Intrinsic::riscv_sshar_i32:
+    case Intrinsic::riscv_sshl_u32:
+    case Intrinsic::riscv_sshlr_u32: {
+      // RV64 has no scalar saturating shift instructions; reuse the packed .ws
+      // family on the low word. The shift amount stays a scalar. Unlike sati
+      // this cannot be promoted to i64: SHA/SHL do not saturate.
+      assert(Subtarget.is64Bit() && N->getValueType(0) == MVT::i32 &&
+             "Unexpected subtarget or result type");
+      unsigned Opc = getRVPScalarOpcode(IntNo);
+      SDValue Rs1 =
+          DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, MVT::v2i32, N->getOperand(1));
+      SDValue ShAmt = DAG.getAnyExtOrTrunc(N->getOperand(2), DL, MVT::i64);
+      SDValue Res = DAG.getNode(Opc, DL, MVT::v2i32, Rs1, ShAmt);
+      Results.push_back(DAG.getExtractVectorElt(DL, MVT::i32, Res, 0));
+      return;
+    }
     case Intrinsic::riscv_sati:
     case Intrinsic::riscv_usati: {
       // RV64 has no 32-bit sati; promote to i64.
@@ -18865,7 +18908,7 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
         Opc = RISCVISD::PSRA;
         break;
       case Intrinsic::riscv_pnsrar:
-        Opc = RISCVISD::PSSHAR;
+        Opc = RISCVISD::SSHAR;
         ShAmt = DAG.getNode(ISD::AND, DL, XLenVT, ShAmt,
                             DAG.getConstant(31, DL, XLenVT));
         ShAmt = DAG.getNegative(ShAmt, DL, XLenVT);
@@ -18908,7 +18951,7 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
       }
 
       unsigned ShiftOpc = IsRounding
-                              ? (IsSigned ? RISCVISD::PSSHAR : 
RISCVISD::PSSHLR)
+                              ? (IsSigned ? RISCVISD::SSHAR : RISCVISD::SSHLR)
                               : (IsSigned ? RISCVISD::PSRA : RISCVISD::PSRL);
       SDValue Shifted = DAG.getNode(ShiftOpc, DL, SrcVT, Src, ShAmt);
       MVT WideVT = VT == MVT::v4i8 ? MVT::v8i8 : MVT::v4i16;
@@ -25702,10 +25745,10 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode 
*N,
     break;
   }
   case RISCVISD::PSLL:
-  case RISCVISD::PSSHA:
-  case RISCVISD::PSSHAR:
-  case RISCVISD::PSSHL:
-  case RISCVISD::PSSHLR:
+  case RISCVISD::SSHA:
+  case RISCVISD::SSHAR:
+  case RISCVISD::SSHL:
+  case RISCVISD::SSHLR:
   case RISCVISD::SHAR:
   case RISCVISD::SHLR: {
     if (isNullConstant(N->getOperand(1)))

diff  --git a/llvm/lib/Target/RISCV/RISCVInstrInfoP.td 
b/llvm/lib/Target/RISCV/RISCVInstrInfoP.td
index dc8cac9442226..21df95066d092 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoP.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoP.td
@@ -125,8 +125,7 @@ class RISCVUImmNegLeaf<int bitsNum>
 
 def uimm4_neg : RISCVUImmNegLeaf<4>;
 def uimm5_neg : RISCVUImmNegLeaf<5>;
-def uimm6_neg_or_zero
-    : ImmLeaf<XLenVT, "return Imm <= 0 && isUInt<6>(-Imm);", NegImm>;
+def uimm6_neg : RISCVUImmNegLeaf<6>;
 
 
//===----------------------------------------------------------------------===//
 // Instruction class templates
@@ -2125,12 +2124,22 @@ def SDT_RISCVPackedShift : SDTypeProfile<1, 2, 
[SDTCisVec<0>,
 def riscv_psll : RVSDNode<"PSLL", SDT_RISCVPackedShift>;
 def riscv_psrl : RVSDNode<"PSRL", SDT_RISCVPackedShift>;
 def riscv_psra : RVSDNode<"PSRA", SDT_RISCVPackedShift>;
-def riscv_pssha : RVSDNode<"PSSHA", SDT_RISCVPackedShift>;
-def riscv_psshar : RVSDNode<"PSSHAR", SDT_RISCVPackedShift>;
-def riscv_psshl : RVSDNode<"PSSHL", SDT_RISCVPackedShift>;
-def riscv_psshlr : RVSDNode<"PSSHLR", SDT_RISCVPackedShift>;
 
+// The shifted value is a scalar (ssha/sshar/sshl/sshlr) or a packed vector
+// (pssha/psshar/psshl/psshlr). The shift amount is always a scalar.
+def SDT_RISCVSaturatingShift : SDTypeProfile<1, 2, [SDTCisInt<0>,
+                                                    SDTCisSameAs<0, 1>,
+                                                    SDTCisVT<2, XLenVT>]>;
+def riscv_ssha  : RVSDNode<"SSHA",  SDT_RISCVSaturatingShift>;
+def riscv_sshar : RVSDNode<"SSHAR", SDT_RISCVSaturatingShift>;
+def riscv_sshl  : RVSDNode<"SSHL",  SDT_RISCVSaturatingShift>;
+def riscv_sshlr : RVSDNode<"SSHLR", SDT_RISCVSaturatingShift>;
+
+// Non-saturating 64-bit shifts. The shift amount is a signed value taken from
+// the low 8 bits of rs2.
+def riscv_sha  : RVSDNode<"SHA",  SDT_RISCVIntBinOpW>;
 def riscv_shar : RVSDNode<"SHAR", SDT_RISCVIntBinOpW>;
+def riscv_shl  : RVSDNode<"SHL",  SDT_RISCVIntBinOpW>;
 def riscv_shlr : RVSDNode<"SHLR", SDT_RISCVIntBinOpW>;
 
 // RV32 packed narrowing shift.
@@ -2289,10 +2298,10 @@ class PatPSh1AddPair<RVInst Inst, ValueType vt>
     : Pat<(vt (add (riscv_psll (vt GPRPair:$rs1), (XLenVT 1)), (vt 
GPRPair:$rs2))),
           (Inst GPRPair:$rs1, GPRPair:$rs2)>;
 
-// Vector sshlsat is custom-lowered to riscv_pssha before isel; saddsat(a, a)
+// Vector sshlsat is custom-lowered to riscv_ssha before isel; saddsat(a, a)
 // is an equivalent shape via the signed sshlsat(a, 1) identity.
 def saturating_shl1 : PatFrags<(ops node:$a),
-                               [(riscv_pssha node:$a, (XLenVT 1)),
+                               [(riscv_ssha node:$a, (XLenVT 1)),
                                 (saddsat node:$a, node:$a)]>;
 
 class PatPSSh1SAdd<RVInst Inst, ValueType vt>
@@ -2454,14 +2463,14 @@ let Predicates = [HasStdExtP] in {
   def : PatGprImm<riscv_psra, PSRAI_H, uimm4, XLenVecI16VT>;
 
   // 16-bit saturating shift patterns
-  def : PatGprImm<riscv_pssha, PSSLAI_H, uimm4, XLenVecI16VT>;
-  def : PatGprImm<riscv_psshar, PSSLAI_H, uimm4, XLenVecI16VT>;
-  def : PatGprImm<riscv_pssha, PSRAI_H, uimm4_neg, XLenVecI16VT>;
-  def : PatGprImm<riscv_psshar, PSRARI_H, uimm4_neg, XLenVecI16VT>;
-  def : PatGprShift<riscv_pssha, PSSHA_HS, XLenVecI16VT>;
-  def : PatGprShift<riscv_psshar, PSSHAR_HS, XLenVecI16VT>;
-  def : PatGprShift<riscv_psshl, PSSHL_HS, XLenVecI16VT>;
-  def : PatGprShift<riscv_psshlr, PSSHLR_HS, XLenVecI16VT>;
+  def : PatGprImm<riscv_ssha, PSSLAI_H, uimm4, XLenVecI16VT>;
+  def : PatGprImm<riscv_sshar, PSSLAI_H, uimm4, XLenVecI16VT>;
+  def : PatGprImm<riscv_ssha, PSRAI_H, uimm4_neg, XLenVecI16VT>;
+  def : PatGprImm<riscv_sshar, PSRARI_H, uimm4_neg, XLenVecI16VT>;
+  def : PatGprShift<riscv_ssha, PSSHA_HS, XLenVecI16VT>;
+  def : PatGprShift<riscv_sshar, PSSHAR_HS, XLenVecI16VT>;
+  def : PatGprShift<riscv_sshl, PSSHL_HS, XLenVecI16VT>;
+  def : PatGprShift<riscv_sshlr, PSSHLR_HS, XLenVecI16VT>;
 
   // 16-bit packed saturation patterns
   def : PatGprImm<riscv_sati, PSATI_H, sati_width4, XLenVecI16VT>;
@@ -2631,6 +2640,16 @@ let append Predicates = [IsRV32] in {
   def : PatGprImm<sshlsat, SSLAI, uimm5>;
   // No SSLLI
 
+  // 32-bit saturating and rounding shift patterns
+  def : PatGprImm<riscv_ssha, SSLAI, uimm5>;
+  def : PatGprImm<riscv_sshar, SSLAI, uimm5>;
+  def : PatGprImm<riscv_ssha, SRAI, uimm5_neg>;
+  def : PatGprImm<riscv_sshar, SRARI_RV32, uimm5_neg>;
+  def : PatGprShiftMask<riscv_ssha, SSHA, shiftMask256>;
+  def : PatGprShiftMask<riscv_sshar, SSHAR, shiftMask256>;
+  def : PatGprShiftMask<riscv_sshl, SSHL, shiftMask256>;
+  def : PatGprShiftMask<riscv_sshlr, SSHLR, shiftMask256>;
+
   def : Pat<(XLenVT (saddsat (sshlsat GPR:$rs1, (XLenVT 1)), GPR:$rs2)),
             (SSH1SADD GPR:$rs1, GPR:$rs2)>;
   def : Pat<(XLenVT (saddsat (saddsat GPR:$rs1, GPR:$rs1), GPR:$rs2)),
@@ -3116,28 +3135,28 @@ let append Predicates = [IsRV32] in {
   def : PatGprPairImm<riscv_psra, PSRAI_DW, uimm5, v2i32>;
 
   // 16-bit saturating shift patterns
-  def : PatGprPairImm<riscv_pssha, PSSLAI_DH, uimm4, v4i16>;
-  def : PatGprPairImm<riscv_psshar, PSSLAI_DH, uimm4, v4i16>;
-  def : PatGprPairImm<riscv_pssha, PSRAI_DH, uimm4_neg, v4i16>;
-  def : PatGprPairImm<riscv_psshar, PSRARI_DH, uimm4_neg, v4i16>;
-  def : PatGprPairShift<riscv_pssha, PSSHA_DHS, v4i16>;
-  def : PatGprPairShift<riscv_psshar, PSSHAR_DHS, v4i16>;
-  def : PatGprPairShift<riscv_psshl, PSSHL_DHS, v4i16>;
-  def : PatGprPairShift<riscv_psshlr, PSSHLR_DHS, v4i16>;
+  def : PatGprPairImm<riscv_ssha, PSSLAI_DH, uimm4, v4i16>;
+  def : PatGprPairImm<riscv_sshar, PSSLAI_DH, uimm4, v4i16>;
+  def : PatGprPairImm<riscv_ssha, PSRAI_DH, uimm4_neg, v4i16>;
+  def : PatGprPairImm<riscv_sshar, PSRARI_DH, uimm4_neg, v4i16>;
+  def : PatGprPairShift<riscv_ssha, PSSHA_DHS, v4i16>;
+  def : PatGprPairShift<riscv_sshar, PSSHAR_DHS, v4i16>;
+  def : PatGprPairShift<riscv_sshl, PSSHL_DHS, v4i16>;
+  def : PatGprPairShift<riscv_sshlr, PSSHLR_DHS, v4i16>;
 
   // 16-bit packed saturation patterns
   def : PatGprPairImm<riscv_sati, PSATI_DH, sati_width4, v4i16>;
   def : PatGprPairImm<riscv_usati, PUSATI_DH, usati_width4, v4i16>;
 
   // 32-bit saturating shift patterns
-  def : PatGprPairImm<riscv_pssha, PSSLAI_DW, uimm5, v2i32>;
-  def : PatGprPairImm<riscv_psshar, PSSLAI_DW, uimm5, v2i32>;
-  def : PatGprPairImm<riscv_pssha, PSRAI_DW, uimm5_neg, v2i32>;
-  def : PatGprPairImm<riscv_psshar, PSRARI_DW, uimm5_neg, v2i32>;
-  def : PatGprPairShift<riscv_pssha, PSSHA_DWS, v2i32>;
-  def : PatGprPairShift<riscv_psshar, PSSHAR_DWS, v2i32>;
-  def : PatGprPairShift<riscv_psshl, PSSHL_DWS, v2i32>;
-  def : PatGprPairShift<riscv_psshlr, PSSHLR_DWS, v2i32>;
+  def : PatGprPairImm<riscv_ssha, PSSLAI_DW, uimm5, v2i32>;
+  def : PatGprPairImm<riscv_sshar, PSSLAI_DW, uimm5, v2i32>;
+  def : PatGprPairImm<riscv_ssha, PSRAI_DW, uimm5_neg, v2i32>;
+  def : PatGprPairImm<riscv_sshar, PSRARI_DW, uimm5_neg, v2i32>;
+  def : PatGprPairShift<riscv_ssha, PSSHA_DWS, v2i32>;
+  def : PatGprPairShift<riscv_sshar, PSSHAR_DWS, v2i32>;
+  def : PatGprPairShift<riscv_sshl, PSSHL_DWS, v2i32>;
+  def : PatGprPairShift<riscv_sshlr, PSSHLR_DWS, v2i32>;
 
   // 32-bit packed saturation patterns
   def : PatGprPairImm<riscv_sati, PSATI_DW, sati_width5, v2i32>;
@@ -3403,10 +3422,6 @@ let append Predicates = [IsRV64] in {
   def : Pat<(XLenVT (riscv_usati GPR:$rs1, usati_width6:$imm)),
             (USATI_RV64 GPR:$rs1, usati_width6:$imm)>;
 
-  def : PatGprShift<riscv_shar, SHAR, i64>;
-  def : PatGprShift<riscv_shlr, SHLR, i64>;
-  def : PatGprImm<riscv_shar, SRARI_RV64, uimm6_neg_or_zero, i64>;
-
   // Word multiply patterns where one operand is a sext.w or zext.w and
   // the other is a sext.w or zext.w or is known to be sign/zero-extended. We
   // prefer plain mul when both operands are known to be sign/zero-extended.
@@ -3703,14 +3718,24 @@ let append Predicates = [IsRV64] in {
   def : PatGprImm<riscv_psra, PSRAI_W, uimm5, v2i32>;
 
   // 32-bit saturating shift patterns
-  def : PatGprImm<riscv_pssha, PSSLAI_W, uimm5, v2i32>;
-  def : PatGprImm<riscv_psshar, PSSLAI_W, uimm5, v2i32>;
-  def : PatGprImm<riscv_pssha, PSRAI_W, uimm5_neg, v2i32>;
-  def : PatGprImm<riscv_psshar, PSRARI_W, uimm5_neg, v2i32>;
-  def : PatGprShift<riscv_pssha, PSSHA_WS, v2i32>;
-  def : PatGprShift<riscv_psshar, PSSHAR_WS, v2i32>;
-  def : PatGprShift<riscv_psshl, PSSHL_WS, v2i32>;
-  def : PatGprShift<riscv_psshlr, PSSHLR_WS, v2i32>;
+  def : PatGprImm<riscv_ssha, PSSLAI_W, uimm5, v2i32>;
+  def : PatGprImm<riscv_sshar, PSSLAI_W, uimm5, v2i32>;
+  def : PatGprImm<riscv_ssha, PSRAI_W, uimm5_neg, v2i32>;
+  def : PatGprImm<riscv_sshar, PSRARI_W, uimm5_neg, v2i32>;
+  def : PatGprShiftMask<riscv_ssha, PSSHA_WS, shiftMask256, v2i32>;
+  def : PatGprShiftMask<riscv_sshar, PSSHAR_WS, shiftMask256, v2i32>;
+  def : PatGprShiftMask<riscv_sshl, PSSHL_WS, shiftMask256, v2i32>;
+  def : PatGprShiftMask<riscv_sshlr, PSSHLR_WS, shiftMask256, v2i32>;
+
+  // 64-bit shift patterns
+  def : PatGprImm<riscv_sha, SLLI, uimm6>;
+  def : PatGprImm<riscv_shar, SLLI, uimm6>;
+  def : PatGprImm<riscv_sha, SRAI, uimm6_neg>;
+  def : PatGprImm<riscv_shar, SRARI_RV64, uimm6_neg>;
+  def : PatGprShiftMask<riscv_sha, SHA, shiftMask256>;
+  def : PatGprShiftMask<riscv_shar, SHAR, shiftMask256>;
+  def : PatGprShiftMask<riscv_shl, SHL, shiftMask256>;
+  def : PatGprShiftMask<riscv_shlr, SHLR, shiftMask256>;
 
   // 32-bit packed saturation patterns
   def : PatGprImm<riscv_sati, PSATI_W, sati_width5, v2i32>;

diff  --git a/llvm/test/CodeGen/RISCV/rvp-scalar-rv64.ll 
b/llvm/test/CodeGen/RISCV/rvp-scalar-rv64.ll
index 8b410a3ef05cd..b1af5c39604a0 100644
--- a/llvm/test/CodeGen/RISCV/rvp-scalar-rv64.ll
+++ b/llvm/test/CodeGen/RISCV/rvp-scalar-rv64.ll
@@ -1689,6 +1689,118 @@ define signext i32 @ssh1sadd_intrinsic_i32(i32 signext 
%a, i32 signext %b) nounw
   ret i32 %res
 }
 
+define i64 @test_sha_i64(i64 %a, i32 %shamt) {
+; CHECK-LABEL: test_sha_i64:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    sha a0, a0, a1
+; CHECK-NEXT:    ret
+  %res = call i64 @llvm.riscv.sha.i64(i64 %a, i32 %shamt)
+  ret i64 %res
+}
+
+define i64 @test_sha_i64_imm(i64 %a) {
+; CHECK-LABEL: test_sha_i64_imm:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    slli a0, a0, 3
+; CHECK-NEXT:    ret
+  %res = call i64 @llvm.riscv.sha.i64(i64 %a, i32 3)
+  ret i64 %res
+}
+
+define i64 @test_sha_i64_negimm(i64 %a) {
+; CHECK-LABEL: test_sha_i64_negimm:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    srai a0, a0, 3
+; CHECK-NEXT:    ret
+  %res = call i64 @llvm.riscv.sha.i64(i64 %a, i32 -3)
+  ret i64 %res
+}
+
+define i64 @test_sha_i64_mask(i64 %a, i32 %shamt) {
+; CHECK-LABEL: test_sha_i64_mask:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    sha a0, a0, a1
+; CHECK-NEXT:    ret
+  %m = and i32 %shamt, 255
+  %res = call i64 @llvm.riscv.sha.i64(i64 %a, i32 %m)
+  ret i64 %res
+}
+
+define i64 @test_shar_i64(i64 %a, i32 %shamt) {
+; CHECK-LABEL: test_shar_i64:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    shar a0, a0, a1
+; CHECK-NEXT:    ret
+  %res = call i64 @llvm.riscv.shar.i64(i64 %a, i32 %shamt)
+  ret i64 %res
+}
+
+define i64 @test_shar_i64_imm(i64 %a) {
+; CHECK-LABEL: test_shar_i64_imm:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    slli a0, a0, 3
+; CHECK-NEXT:    ret
+  %res = call i64 @llvm.riscv.shar.i64(i64 %a, i32 3)
+  ret i64 %res
+}
+
+define i64 @test_shar_i64_negimm(i64 %a) {
+; CHECK-LABEL: test_shar_i64_negimm:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    srari a0, a0, 3
+; CHECK-NEXT:    ret
+  %res = call i64 @llvm.riscv.shar.i64(i64 %a, i32 -3)
+  ret i64 %res
+}
+
+define i64 @test_shl_u64(i64 %a, i32 %shamt) {
+; CHECK-LABEL: test_shl_u64:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    shl a0, a0, a1
+; CHECK-NEXT:    ret
+  %res = call i64 @llvm.riscv.shl.u64(i64 %a, i32 %shamt)
+  ret i64 %res
+}
+
+define i64 @test_shlr_u64(i64 %a, i32 %shamt) {
+; CHECK-LABEL: test_shlr_u64:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    shlr a0, a0, a1
+; CHECK-NEXT:    ret
+  %res = call i64 @llvm.riscv.shlr.u64(i64 %a, i32 %shamt)
+  ret i64 %res
+}
+
+define i64 @test_shl_u64_imm(i64 %a) {
+; CHECK-LABEL: test_shl_u64_imm:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    li a1, 3
+; CHECK-NEXT:    shl a0, a0, a1
+; CHECK-NEXT:    ret
+  %res = call i64 @llvm.riscv.shl.u64(i64 %a, i32 3)
+  ret i64 %res
+}
+
+define i64 @test_shlr_u64_negimm(i64 %a) {
+; CHECK-LABEL: test_shlr_u64_negimm:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    li a1, -3
+; CHECK-NEXT:    shlr a0, a0, a1
+; CHECK-NEXT:    ret
+  %res = call i64 @llvm.riscv.shlr.u64(i64 %a, i32 -3)
+  ret i64 %res
+}
+
+define signext i32 @ssha_intrinsic_i32_signext(i32 signext %a, i32 signext 
%shamt) nounwind {
+; CHECK-LABEL: ssha_intrinsic_i32_signext:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    pssha.ws a0, a0, a1
+; CHECK-NEXT:    sext.w a0, a0
+; CHECK-NEXT:    ret
+  %res = call i32 @llvm.riscv.ssha.i32(i32 %a, i32 %shamt)
+  ret i32 %res
+}
+
 declare i32 @llvm.riscv.mseq.u32(i32, i32)
 declare i32 @llvm.riscv.mslt.i32(i32, i32)
 declare i32 @llvm.riscv.msltu.u32(i32, i32)

diff  --git a/llvm/test/CodeGen/RISCV/rvp-scalar.ll 
b/llvm/test/CodeGen/RISCV/rvp-scalar.ll
index 3119891a188b2..85bcebca49b55 100644
--- a/llvm/test/CodeGen/RISCV/rvp-scalar.ll
+++ b/llvm/test/CodeGen/RISCV/rvp-scalar.ll
@@ -4075,6 +4075,165 @@ define signext i32 @test_usati_u32_w31_signext(i32 
signext %a) {
   ret i32 %res
 }
 
+define i32 @test_ssha_i32(i32 %a, i32 %shamt) {
+; RV32-LABEL: test_ssha_i32:
+; RV32:       # %bb.0:
+; RV32-NEXT:    ssha a0, a0, a1
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_ssha_i32:
+; RV64:       # %bb.0:
+; RV64-NEXT:    pssha.ws a0, a0, a1
+; RV64-NEXT:    ret
+  %res = call i32 @llvm.riscv.ssha.i32(i32 %a, i32 %shamt)
+  ret i32 %res
+}
+
+define i32 @test_ssha_i32_imm(i32 %a) {
+; RV32-LABEL: test_ssha_i32_imm:
+; RV32:       # %bb.0:
+; RV32-NEXT:    sslai a0, a0, 3
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_ssha_i32_imm:
+; RV64:       # %bb.0:
+; RV64-NEXT:    psslai.w a0, a0, 3
+; RV64-NEXT:    ret
+  %res = call i32 @llvm.riscv.ssha.i32(i32 %a, i32 3)
+  ret i32 %res
+}
+
+define i32 @test_ssha_i32_negimm(i32 %a) {
+; RV32-LABEL: test_ssha_i32_negimm:
+; RV32:       # %bb.0:
+; RV32-NEXT:    srai a0, a0, 3
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_ssha_i32_negimm:
+; RV64:       # %bb.0:
+; RV64-NEXT:    psrai.w a0, a0, 3
+; RV64-NEXT:    ret
+  %res = call i32 @llvm.riscv.ssha.i32(i32 %a, i32 -3)
+  ret i32 %res
+}
+
+define i32 @test_ssha_i32_mask(i32 %a, i32 %shamt) {
+; RV32-LABEL: test_ssha_i32_mask:
+; RV32:       # %bb.0:
+; RV32-NEXT:    ssha a0, a0, a1
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_ssha_i32_mask:
+; RV64:       # %bb.0:
+; RV64-NEXT:    pssha.ws a0, a0, a1
+; RV64-NEXT:    ret
+  %m = and i32 %shamt, 255
+  %res = call i32 @llvm.riscv.ssha.i32(i32 %a, i32 %m)
+  ret i32 %res
+}
+
+define i32 @test_sshar_i32(i32 %a, i32 %shamt) {
+; RV32-LABEL: test_sshar_i32:
+; RV32:       # %bb.0:
+; RV32-NEXT:    sshar a0, a0, a1
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_sshar_i32:
+; RV64:       # %bb.0:
+; RV64-NEXT:    psshar.ws a0, a0, a1
+; RV64-NEXT:    ret
+  %res = call i32 @llvm.riscv.sshar.i32(i32 %a, i32 %shamt)
+  ret i32 %res
+}
+
+define i32 @test_sshar_i32_imm(i32 %a) {
+; RV32-LABEL: test_sshar_i32_imm:
+; RV32:       # %bb.0:
+; RV32-NEXT:    sslai a0, a0, 3
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_sshar_i32_imm:
+; RV64:       # %bb.0:
+; RV64-NEXT:    psslai.w a0, a0, 3
+; RV64-NEXT:    ret
+  %res = call i32 @llvm.riscv.sshar.i32(i32 %a, i32 3)
+  ret i32 %res
+}
+
+define i32 @test_sshar_i32_negimm(i32 %a) {
+; RV32-LABEL: test_sshar_i32_negimm:
+; RV32:       # %bb.0:
+; RV32-NEXT:    srari a0, a0, 3
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_sshar_i32_negimm:
+; RV64:       # %bb.0:
+; RV64-NEXT:    psrari.w a0, a0, 3
+; RV64-NEXT:    ret
+  %res = call i32 @llvm.riscv.sshar.i32(i32 %a, i32 -3)
+  ret i32 %res
+}
+
+define i32 @test_sshl_u32(i32 %a, i32 %shamt) {
+; RV32-LABEL: test_sshl_u32:
+; RV32:       # %bb.0:
+; RV32-NEXT:    sshl a0, a0, a1
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_sshl_u32:
+; RV64:       # %bb.0:
+; RV64-NEXT:    psshl.ws a0, a0, a1
+; RV64-NEXT:    ret
+  %res = call i32 @llvm.riscv.sshl.u32(i32 %a, i32 %shamt)
+  ret i32 %res
+}
+
+define i32 @test_sshlr_u32(i32 %a, i32 %shamt) {
+; RV32-LABEL: test_sshlr_u32:
+; RV32:       # %bb.0:
+; RV32-NEXT:    sshlr a0, a0, a1
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_sshlr_u32:
+; RV64:       # %bb.0:
+; RV64-NEXT:    psshlr.ws a0, a0, a1
+; RV64-NEXT:    ret
+  %res = call i32 @llvm.riscv.sshlr.u32(i32 %a, i32 %shamt)
+  ret i32 %res
+}
+
+define i32 @test_sshl_u32_imm(i32 %a) {
+; RV32-LABEL: test_sshl_u32_imm:
+; RV32:       # %bb.0:
+; RV32-NEXT:    li a1, 3
+; RV32-NEXT:    sshl a0, a0, a1
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_sshl_u32_imm:
+; RV64:       # %bb.0:
+; RV64-NEXT:    li a1, 3
+; RV64-NEXT:    psshl.ws a0, a0, a1
+; RV64-NEXT:    ret
+  %res = call i32 @llvm.riscv.sshl.u32(i32 %a, i32 3)
+  ret i32 %res
+}
+
+define i32 @test_sshlr_u32_negimm(i32 %a) {
+; RV32-LABEL: test_sshlr_u32_negimm:
+; RV32:       # %bb.0:
+; RV32-NEXT:    li a1, -3
+; RV32-NEXT:    sshlr a0, a0, a1
+; RV32-NEXT:    ret
+;
+; RV64-LABEL: test_sshlr_u32_negimm:
+; RV64:       # %bb.0:
+; RV64-NEXT:    li a1, -3
+; RV64-NEXT:    psshlr.ws a0, a0, a1
+; RV64-NEXT:    ret
+  %res = call i32 @llvm.riscv.sshlr.u32(i32 %a, i32 -3)
+  ret i32 %res
+}
+
 define i32 @nclipu_u32(i64 %a, i32 %shamt) {
 ; RV32-LABEL: nclipu_u32:
 ; RV32:       # %bb.0:


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to