[llvm] [FunctionAttrs] Don't infer noundef when return has nofpclass (PR #191822)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 13 07:24:07 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Shonie Caplan (shoniecaplan)
<details>
<summary>Changes</summary>
- 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.
---
Full diff: https://github.com/llvm/llvm-project/pull/191822.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/IPO/FunctionAttrs.cpp (+4)
- (modified) llvm/test/Transforms/FunctionAttrs/noundef.ll (+8)
``````````diff
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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/191822
More information about the llvm-commits
mailing list