[llvm] [IR] treat nofpclass as a poison-generating return attribute (PR #192016)

Shonie Caplan via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 01:08:23 PDT 2026


https://github.com/shoniecaplan created https://github.com/llvm/llvm-project/pull/192016

- For: #191338

Failing nofpclass attribute will generate poison.
This change adds nofpclass attributes to `hasPoisonGeneratingReturnAttributes`/`dropPoisonGeneratingReturnAttributes`.

>From 7ee9c1295cea45e1f036b0ff62721e09be1a5d82 Mon Sep 17 00:00:00 2001
From: Shonie Caplan <shonie4caplan at gmail.com>
Date: Tue, 14 Apr 2026 17:07:15 +0900
Subject: [PATCH] [IR] treat nofpclass as a poison-generating return attribute

- For: #191338

Failing nofpclass attribute will generate poison.
This change adds nofpclass attributes to `hasPoisonGeneratingReturnAttributes`/`dropPoisonGeneratingReturnAttributes`.
---
 llvm/lib/IR/Instruction.cpp                |  4 +++-
 llvm/test/Transforms/InstCombine/freeze.ll | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 8aa19a436a157..7db36ed5f8bbb 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -538,7 +538,8 @@ bool Instruction::hasPoisonGeneratingReturnAttributes() const {
     AttributeSet RetAttrs = CB->getAttributes().getRetAttrs();
     return RetAttrs.hasAttribute(Attribute::Range) ||
            RetAttrs.hasAttribute(Attribute::Alignment) ||
-           RetAttrs.hasAttribute(Attribute::NonNull);
+           RetAttrs.hasAttribute(Attribute::NonNull) ||
+           RetAttrs.hasAttribute(Attribute::NoFPClass);
   }
   return false;
 }
@@ -549,6 +550,7 @@ void Instruction::dropPoisonGeneratingReturnAttributes() {
     AM.addAttribute(Attribute::Range);
     AM.addAttribute(Attribute::Alignment);
     AM.addAttribute(Attribute::NonNull);
+    AM.addAttribute(Attribute::NoFPClass);
     CB->removeRetAttrs(AM);
   }
   assert(!hasPoisonGeneratingReturnAttributes() && "must be kept in sync");
diff --git a/llvm/test/Transforms/InstCombine/freeze.ll b/llvm/test/Transforms/InstCombine/freeze.ll
index 80db307ff5e25..3a401acb6d3ee 100644
--- a/llvm/test/Transforms/InstCombine/freeze.ll
+++ b/llvm/test/Transforms/InstCombine/freeze.ll
@@ -1721,6 +1721,18 @@ bb.13:                                             ; preds = %bb.8, %bb.2
   br label %bb.2
 }
 
+define float @freeze_fabs_nofpclass(float %a) {
+; CHECK-LABEL: define float @freeze_fabs_nofpclass(
+; CHECK-SAME: float [[A:%.*]]) {
+; CHECK-NEXT:    [[A_FR:%.*]] = freeze float [[A]]
+; CHECK-NEXT:    [[X:%.*]] = call float @llvm.fabs.f32(float [[A_FR]])
+; CHECK-NEXT:    ret float [[X]]
+;
+  %x = call nofpclass(nan) float @llvm.fabs.f32(float %a)
+  %x.fr = freeze float %x
+  ret float %x.fr
+}
+
 !0 = !{}
 !1 = !{i64 4}
 !2 = !{i32 0, i32 100}



More information about the llvm-commits mailing list