[llvm] [SPIR-V] Lower G_SSHLSAT and G_USHLSAT (PR #206490)

Arseniy Obolenskiy via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 29 06:21:17 PDT 2026


https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/206490

None

>From 0aabc729ba171a67d7243c568de28646693c45ab Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Mon, 29 Jun 2026 15:20:46 +0200
Subject: [PATCH] [SPIR-V] Lower G_SSHLSAT and G_USHLSAT

---
 llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp |  2 ++
 llvm/test/CodeGen/SPIRV/sat-shifts.ll        | 35 ++++++++++++++++++++
 2 files changed, 37 insertions(+)
 create mode 100644 llvm/test/CodeGen/SPIRV/sat-shifts.ll

diff --git a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
index 21fa782c4cc9e..1da5cc9400b0c 100644
--- a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
@@ -329,6 +329,8 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) {
       .legalFor(allIntScalarsAndVectors)
       .legalIf(extendedScalarsAndVectors);
 
+  getActionDefinitionsBuilder({G_SSHLSAT, G_USHLSAT}).lower();
+
   getActionDefinitionsBuilder(G_STRICT_FLDEXP)
       .legalForCartesianProduct(allFloatScalarsAndVectors, allIntScalars);
 
diff --git a/llvm/test/CodeGen/SPIRV/sat-shifts.ll b/llvm/test/CodeGen/SPIRV/sat-shifts.ll
new file mode 100644
index 0000000000000..03683b8d7da43
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/sat-shifts.ll
@@ -0,0 +1,35 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK-DAG: OpName %[[#Foo:]] "foo"
+; CHECK-DAG: OpName %[[#Bar:]] "bar"
+; CHECK: %[[#Foo]] = OpFunction
+; CHECK: %[[#Bar]] = OpFunction
+
+define spir_func void @foo(i16 %x, i16 %y) {
+entry:
+  %r1 = tail call i16 @llvm.sshl.sat.i16(i16 %x, i16 %y)
+  store i16 %r1, ptr @G_r1_foo
+  %r2 = tail call i16 @llvm.ushl.sat.i16(i16 %x, i16 %y)
+  store i16 %r2, ptr @G_r2_foo
+  ret void
+}
+
+define spir_func void @bar(<4 x i32> %x, <4 x i32> %y) {
+entry:
+  %r1 = tail call <4 x i32> @llvm.sshl.sat.v4i32(<4 x i32> %x, <4 x i32> %y)
+  store <4 x i32> %r1, ptr @G_r1_bar
+  %r2 = tail call <4 x i32> @llvm.ushl.sat.v4i32(<4 x i32> %x, <4 x i32> %y)
+  store <4 x i32> %r2, ptr @G_r2_bar
+  ret void
+}
+
+ at G_r1_foo = global i16 0
+ at G_r2_foo = global i16 0
+ at G_r1_bar = global <4 x i32> zeroinitializer
+ at G_r2_bar = global <4 x i32> zeroinitializer
+
+declare i16 @llvm.sshl.sat.i16(i16, i16)
+declare i16 @llvm.ushl.sat.i16(i16, i16)
+declare <4 x i32> @llvm.sshl.sat.v4i32(<4 x i32>, <4 x i32>)
+declare <4 x i32> @llvm.ushl.sat.v4i32(<4 x i32>, <4 x i32>)



More information about the llvm-commits mailing list