[llvm] IR: Allow !fpmath metadata on homogeneous float structs (PR #193537)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 22 09:52:50 PDT 2026


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/193537

This matches the logic for fast math flags / nofpclass, and allows
marking llvm.sincos calls with !fpmath.

>From dc6d419d583bec0e81e5babaabddc5c8ce5fc5a5 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 22 Apr 2026 17:48:05 +0100
Subject: [PATCH] IR: Allow !fpmath metadata on homogeneous float structs

This matches the logic for fast math flags / nofpclass, and allows
marking llvm.sincos calls with !fpmath.
---
 llvm/lib/IR/Verifier.cpp      |  2 +-
 llvm/test/Assembler/fpmath.ll | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Assembler/fpmath.ll

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 0074ca181d2e7..fe1854384e693 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5751,7 +5751,7 @@ void Verifier::visitInstruction(Instruction &I) {
   }
 
   if (MDNode *MD = I.getMetadata(LLVMContext::MD_fpmath)) {
-    Check(I.getType()->isFPOrFPVectorTy(),
+    Check(FPMathOperator::isSupportedFloatingPointType(I.getType()),
           "fpmath requires a floating point result!", &I);
     Check(MD->getNumOperands() == 1, "fpmath takes one operand!", &I);
     if (ConstantFP *CFP0 =
diff --git a/llvm/test/Assembler/fpmath.ll b/llvm/test/Assembler/fpmath.ll
new file mode 100644
index 0000000000000..772923c795349
--- /dev/null
+++ b/llvm/test/Assembler/fpmath.ll
@@ -0,0 +1,19 @@
+; RUN: llvm-as < %s | llvm-dis
+
+define { float, float } @use_fpmath_struct(float %x) {
+; CHECK-LABEL: @use_fpmath_struct(
+; CHECK: %ret = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> %x), !fpmath !0
+  %ret = call { float, float } @llvm.sincos.f32(float %x), !fpmath !0
+  ret { float, float } %ret
+}
+
+define { <2 x float>, <2 x float> } @use_fpmath_struct_vec(<2 x float> %x) {
+; CHECK-LABEL: @use_fpmath_struct_vec(
+; CHECK: %ret = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> %x), !fpmath !0
+  %ret = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> %x), !fpmath !0
+  ret { <2 x float>, <2 x float> } %ret
+}
+
+!0 = !{float 4.0}
+
+; CHECK: !0 = !{float 4.000000e+00}



More information about the llvm-commits mailing list