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

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 11 12:16:26 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Yingwei Zheng (dtcxzyw)

<details>
<summary>Changes</summary>

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?


---
Full diff: https://github.com/llvm/llvm-project/pull/231024.diff


2 Files Affected:

- (modified) llvm/lib/IR/Verifier.cpp (+18) 
- (added) llvm/test/Verifier/fptousi_sat.ll (+17) 


``````````diff
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
+}

``````````

</details>


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


More information about the llvm-commits mailing list