[llvm] [GlobalISel] Add Saturated Truncate Instructions (PR #147526)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 8 08:36:35 PDT 2025


================
@@ -809,6 +809,48 @@ class LLVM_ABI MachineIRBuilder {
   MachineInstrBuilder buildZExtInReg(const DstOp &Res, const SrcOp &Op,
                                      int64_t ImmOp);
 
+  /// Build and insert \p Res = \p G_TRUNC_SSAT_S \p Op
+  ///
+  /// G_TRUNC_SSAT_S truncates the saturated signed input, \p Op, to a signed
+  /// result.
+  ///  ///
+  /// \pre setBasicBlock or setMI must have been called.
+  /// \pre \p Res must be a generic virtual register with scalar or vector type.
+  /// \pre \p Op must be a generic virtual register with scalar or vector type.
+  ///
+  /// \return The newly created instruction.
+  MachineInstrBuilder buildTruncSSatS(const DstOp &Res, const SrcOp &Op) {
+    return buildInstr(TargetOpcode::G_TRUNC_SSAT_S, {Res}, {Op});
+  }
+
+  /// Build and insert \p Res = \p G_TRUNC_SSAT_U \p Op
+  ///
+  /// G_TRUNC_SSAT_U truncates the saturated signed input, \p Op, to a unsigned
+  /// result.
+  ///  ///
+  /// \pre setBasicBlock or setMI must have been called.
+  /// \pre \p Res must be a generic virtual register with scalar or vector type.
+  /// \pre \p Op must be a generic virtual register with scalar or vector type.
+  ///
+  /// \return The newly created instruction.
+  MachineInstrBuilder buildTruncSSatU(const DstOp &Res, const SrcOp &Op) {
+    return buildInstr(TargetOpcode::G_TRUNC_SSAT_U, {Res}, {Op});
+  }
+
+  /// Build and insert \p Res = \p G_TRUNC_USAT_U \p Op
+  ///
+  /// G_TRUNC_SSAT_S truncates the saturated unsigned input, \p Op, to a
+  /// unsigned result.
+  ///  ///
----------------
jyli0116 wrote:

Makes sense - I'll remove the double ///s that appear then

https://github.com/llvm/llvm-project/pull/147526


More information about the llvm-commits mailing list