[llvm] [FunctionAttrs] Don't infer noundef when return has nofpclass (PR #191822)

Shonie Caplan via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 07:23:02 PDT 2026


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

- Fixes: #191338

nofpclass violations on a return produce poison.
Poison returns marked noundef are UB.
This turns off noundef inference when nofpclass attributes are present.

>From 59656aa3fe3afc349dbb27cdc4f3991f2b9d83e5 Mon Sep 17 00:00:00 2001
From: Shonie Caplan <shonie at genki.com>
Date: Mon, 13 Apr 2026 22:58:19 +0900
Subject: [PATCH] [FunctionAttrs] Don't infer noundef when return has nofpclass

- Fixes: #191338

nofpclass violations on a return produce poison.
Poison returns marked noundef are UB.
This turns off noundef inference when nofpclass attributes are present.
---
 llvm/lib/Transforms/IPO/FunctionAttrs.cpp     | 4 ++++
 llvm/test/Transforms/FunctionAttrs/noundef.ll | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index c5e20c766ad52..e25bf70a6259d 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -1742,6 +1742,10 @@ static void addNoUndefAttrs(const SCCNodeSet &SCCNodes,
                 !Attr.getRange().contains(
                     computeConstantRange(RetVal, /*ForSigned=*/false)))
               return false;
+
+            Attribute NoFP = Attrs.getRetAttr(Attribute::NoFPClass);
+            if (NoFP.hasAttribute(Attribute::NoFPClass))
+              return false;
           }
           return true;
         })) {
diff --git a/llvm/test/Transforms/FunctionAttrs/noundef.ll b/llvm/test/Transforms/FunctionAttrs/noundef.ll
index 4f53c08804621..4b1224fd318f4 100644
--- a/llvm/test/Transforms/FunctionAttrs/noundef.ll
+++ b/llvm/test/Transforms/FunctionAttrs/noundef.ll
@@ -214,3 +214,11 @@ define range(i8 0, 10) i8 @definitely_in_range(i8 noundef range(i8 0, 10) %v) {
 ;
   ret i8 %v
 }
+
+define nofpclass(nan) float @test_ret_nofpclass(float noundef %x) {
+; CHECK-LABEL: define nofpclass(nan) float @test_ret_nofpclass(
+; CHECK-SAME: float noundef returned [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    ret float [[X]]
+;
+  ret float %x
+}



More information about the llvm-commits mailing list