[llvm] [Verifier] Add type constraint for fpto[su]i.sat (PR #231024)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 11 12:15:44 PDT 2026


https://github.com/dtcxzyw created https://github.com/llvm/llvm-project/pull/231024

The test is generated by DeepSeek-V4.1-Flash while fuzzing llubi.

TBH I don't think duplicating handwritten logic in Verifier is a good idea. It is time to add a new partially dependent type to Intrinsics.td. The same constraint is also suitable for ucmp/scmp/ptrmask/ldexp/frexp... Any thoughts?


>From 843662be329c4a39fbadf2822c533b7687e96498 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Mon, 12 Oct 2026 03:05:24 +0800
Subject: [PATCH] [Verifier] Add type constraint for fpto[su]i.sat

---
 llvm/lib/IR/Verifier.cpp          | 18 ++++++++++++++++++
 llvm/test/Verifier/fptousi_sat.ll | 17 +++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100644 llvm/test/Verifier/fptousi_sat.ll

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index ed7c68b24df1b..f208ac6d49a4a 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -7471,6 +7471,24 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
           &Call);
     break;
   }
+  case Intrinsic::fptosi_sat:
+  case Intrinsic::fptoui_sat: {
+    Type *SrcTy = Call.getOperand(0)->getType();
+    Type *DestTy = Call.getType();
+
+    Check(SrcTy->isVectorTy() == DestTy->isVectorTy(),
+          "fptosi.sat/fptoui.sat argument and result types must both be either "
+          "vector or scalar types",
+          Call);
+    if (DestTy->isVectorTy()) {
+      auto SrcVecLen = cast<VectorType>(SrcTy)->getElementCount();
+      auto DestVecLen = cast<VectorType>(DestTy)->getElementCount();
+      Check(SrcVecLen == DestVecLen,
+            "return type and arguments must have the same number of elements",
+            Call);
+    }
+    break;
+  }
   };
 
   // Verify that there aren't any unmediated control transfers between funclets.
diff --git a/llvm/test/Verifier/fptousi_sat.ll b/llvm/test/Verifier/fptousi_sat.ll
new file mode 100644
index 0000000000000..00b27d6420b85
--- /dev/null
+++ b/llvm/test/Verifier/fptousi_sat.ll
@@ -0,0 +1,17 @@
+; RUN: not opt -passes=verify -disable-output < %s 2>&1 | FileCheck %s
+
+define void @main() {
+; CHECK: fptosi.sat/fptoui.sat argument and result types must both be either vector or scalar types
+; CHECK-NEXT: %1 = call i32 @llvm.fptosi.sat.i32.v1f32(<1 x float> zeroinitializer)
+  call i32 @llvm.fptosi.sat.i32.v1f32(<1 x float> zeroinitializer)
+; CHECK: return type and arguments must have the same number of elements
+; CHECK-NEXT: %2 = call <2 x i32> @llvm.fptosi.sat.v2i32.v1f32(<1 x float> zeroinitializer)
+  call <2 x i32> @llvm.fptosi.sat.v2i32.v1f32(<1 x float> zeroinitializer)
+; CHECK: fptosi.sat/fptoui.sat argument and result types must both be either vector or scalar types
+; CHECK-NEXT: %3 = call i32 @llvm.fptoui.sat.i32.v1f32(<1 x float> zeroinitializer)
+  call i32 @llvm.fptoui.sat.i32.v1f32(<1 x float> zeroinitializer)
+; CHECK: return type and arguments must have the same number of elements
+; CHECK-NEXT: %4 = call <2 x i32> @llvm.fptoui.sat.v2i32.v1f32(<1 x float> zeroinitializer)
+  call <2 x i32> @llvm.fptoui.sat.v2i32.v1f32(<1 x float> zeroinitializer)
+  ret void
+}



More information about the llvm-commits mailing list