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

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 06:42:40 PDT 2026


Author: Shonie Caplan
Date: 2026-04-16T14:42:36+01:00
New Revision: 4f50ce24315a03cfb3b9ec2e5480d866c451f1ad

URL: https://github.com/llvm/llvm-project/commit/4f50ce24315a03cfb3b9ec2e5480d866c451f1ad
DIFF: https://github.com/llvm/llvm-project/commit/4f50ce24315a03cfb3b9ec2e5480d866c451f1ad.diff

LOG: [FunctionAttrs] Don't infer noundef when return has nofpclass (#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.

---------

Co-authored-by: Shonie Caplan <shonie at genki.com>
Co-authored-by: Yingwei Zheng <dtcxzyw at qq.com>

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/FunctionAttrs.cpp
    llvm/test/Transforms/FunctionAttrs/noundef.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index c5e20c766ad52..0bbe2d6298811 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -57,6 +57,7 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/KnownFPClass.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Transforms/Utils/Local.h"
@@ -1742,6 +1743,13 @@ static void addNoUndefAttrs(const SCCNodeSet &SCCNodes,
                 !Attr.getRange().contains(
                     computeConstantRange(RetVal, /*ForSigned=*/false)))
               return false;
+
+            FPClassTest AttrFPClass = Attrs.getRetNoFPClass();
+            if (AttrFPClass != fcNone) {
+              KnownFPClass ComputedFPClass = computeKnownFPClass(RetVal, DL);
+              if (!ComputedFPClass.isKnownNever(AttrFPClass))
+                return false;
+            }
           }
           return true;
         })) {

diff  --git a/llvm/test/Transforms/FunctionAttrs/noundef.ll b/llvm/test/Transforms/FunctionAttrs/noundef.ll
index 4f53c08804621..75e5655f2a93e 100644
--- a/llvm/test/Transforms/FunctionAttrs/noundef.ll
+++ b/llvm/test/Transforms/FunctionAttrs/noundef.ll
@@ -214,3 +214,29 @@ define range(i8 0, 10) i8 @definitely_in_range(i8 noundef range(i8 0, 10) %v) {
 ;
   ret i8 %v
 }
+
+define nofpclass(nan) float @maybe_nofpclass(float noundef %x) {
+; CHECK-LABEL: define nofpclass(nan) float @maybe_nofpclass(
+; CHECK-SAME: float noundef returned [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    ret float [[X]]
+;
+  ret float %x
+}
+
+define nofpclass(nan) float @compute_not_nofpclass(float noundef nofpclass(nan) %x) {
+; CHECK-LABEL: define nofpclass(nan) float @compute_not_nofpclass(
+; CHECK-SAME: float noundef nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    [[Y:%.*]] = fmul float [[X]], 0x7FF8000000000000
+; CHECK-NEXT:    ret float [[Y]]
+;
+  %y = fmul float %x, 0x7FF8000000000000
+  ret float %y
+}
+
+define nofpclass(nan) float @definitely_nofpclass(float noundef nofpclass(nan) %x) {
+; CHECK-LABEL: define noundef nofpclass(nan) float @definitely_nofpclass(
+; CHECK-SAME: float noundef returned nofpclass(nan) [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    ret float [[X]]
+;
+  ret float %x
+}


        


More information about the llvm-commits mailing list