[llvm] [SPIRV] support for the intrinsic @llvm.fptosi.sat.* and @llvm.fptoui.sat.* (PR #129222)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 5 21:33:06 PST 2025


https://github.com/VishMCW updated https://github.com/llvm/llvm-project/pull/129222

>From 38944e13273c67586e601757af48f5f493d8c412 Mon Sep 17 00:00:00 2001
From: VishMCW <vishakh.prakash at multicorewareinc.com>
Date: Thu, 6 Mar 2025 10:36:49 +0530
Subject: [PATCH] FEAT: Add support for the intrinsic @llvm.fptosi.sat.* and
 @llvm.fptoui.sat.* - add legalizer for G_FPTOSI_SAT and G_FPTOUI_SAT - add
 instructionSelector for G_FPTOSI_SAT and G_FPTOUI_SAT - add function to add
 saturatedConversion decoration to the intrinsic

---
 llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index 5dfba8427258f..eb4c20b9901f5 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -1367,6 +1367,24 @@ static void createSaturatedConversionDecoration(Instruction *I,
   createDecorationIntrinsic(I, SaturatedConversionNode, B);
 }
 
+static void addSaturatedDecorationToIntrinsic(Instruction *I, IRBuilder<> &B) {
+  if (auto *CI = dyn_cast<CallInst>(I)) {
+    if (Function *Fu = CI->getCalledFunction()) {
+      if (Fu->isIntrinsic()) {
+        unsigned const int IntrinsicId = Fu->getIntrinsicID();
+        switch (IntrinsicId) {
+        case Intrinsic::fptosi_sat:
+        case Intrinsic::fptoui_sat:
+          createSaturatedConversionDecoration(I, B);
+          break;
+        default:
+          break;
+        }
+      }
+    }
+  }
+}
+
 Instruction *SPIRVEmitIntrinsics::visitCallInst(CallInst &Call) {
   if (!Call.isInlineAsm())
     return &Call;



More information about the llvm-commits mailing list