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

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 22 09:53:43 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)

<details>
<summary>Changes</summary>

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

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


2 Files Affected:

- (modified) llvm/lib/IR/Verifier.cpp (+1-1) 
- (added) llvm/test/Assembler/fpmath.ll (+19) 


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

``````````

</details>


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


More information about the llvm-commits mailing list