[llvm-branch-commits] [llvm] ValueTracking: Handle ConstantDataSequential in computeKnownFPClass (PR #184191)

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Mar 2 10:46:18 PST 2026


https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/184191

>From 30bad87db69965f3078e5d62e3a4911234dabfcd Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 2 Mar 2026 18:30:42 +0100
Subject: [PATCH] ValueTracking: Handle ConstantDataSequential in
 computeKnownFPClass

---
 llvm/lib/Analysis/ValueTracking.cpp           |  7 ++++
 llvm/test/Transforms/Attributor/nofpclass.ll  | 18 +++++++++++
 .../simplify-demanded-fpclass-aggregates.ll   | 32 +++++++++----------
 3 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 3f925844a4020..f0a11f7d9df3f 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -5051,6 +5051,13 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
     return;
   }
 
+  if (const auto *CDS = dyn_cast<ConstantDataSequential>(V)) {
+    Known.KnownFPClasses = fcNone;
+    for (size_t I = 0, E = CDS->getNumElements(); I != E; ++I)
+      Known |= CDS->getElementAsAPFloat(I).classify();
+    return;
+  }
+
   FPClassTest KnownNotFromFlags = fcNone;
   if (const auto *CB = dyn_cast<CallBase>(V))
     KnownNotFromFlags |= CB->getRetNoFPClass();
diff --git a/llvm/test/Transforms/Attributor/nofpclass.ll b/llvm/test/Transforms/Attributor/nofpclass.ll
index 18adaf437f938..7ed5e78539a90 100644
--- a/llvm/test/Transforms/Attributor/nofpclass.ll
+++ b/llvm/test/Transforms/Attributor/nofpclass.ll
@@ -3847,6 +3847,24 @@ define [4 x float] @infer_return_from_load_nofpclass_md_array(ptr %ptr) {
   ret [4 x float] %load
 }
 
+define [2 x float] @constant_data_array_0() {
+; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
+; CHECK-LABEL: define nofpclass(nan inf nzero sub nnorm) [2 x float] @constant_data_array_0
+; CHECK-SAME: () #[[ATTR3]] {
+; CHECK-NEXT:    ret [2 x float] [float 0.000000e+00, float 1.000000e+00]
+;
+  ret [2 x float] [float 0.0, float 1.0]
+}
+
+define [2 x float] @constant_data_array_1() {
+; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
+; CHECK-LABEL: define nofpclass(snan inf zero sub norm) [2 x float] @constant_data_array_1
+; CHECK-SAME: () #[[ATTR3]] {
+; CHECK-NEXT:    ret [2 x float] [float 0x7FF8000000000000, float 0x7FF8000000000000]
+;
+  ret [2 x float] [float 0x7FF8000000000000, float 0x7FF8000000000000]
+}
+
 declare i64 @_Z13get_global_idj(i32 noundef)
 
 attributes #0 = { denormal_fpenv(preservesign) }
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-aggregates.ll b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-aggregates.ll
index b073e6611d870..68df1fd212d2e 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-aggregates.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-aggregates.ll
@@ -119,8 +119,8 @@ entry:
 ; FIXME (should be poison): Support computeKnownFPClass() for non-zero aggregates.
 define nofpclass(nzero) [ 1 x float ] @ret_nofpclass_multiple_elems_struct_ty_nzero_nzero() {
 ; CHECK-LABEL: define nofpclass(nzero) [1 x float] @ret_nofpclass_multiple_elems_struct_ty_nzero_nzero() {
-; CHECK-NEXT:  entry:
-; CHECK-NEXT:    ret [1 x float] [float -0.000000e+00]
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    ret [1 x float] poison
 ;
 entry:
   ret [ 1 x float ] [ float -0.0 ]
@@ -128,8 +128,8 @@ entry:
 
 ; Fold to ret %y
 define nofpclass(inf) [3 x [2 x float]] @ret_float_array(i1 %cond, [3 x [2 x float]] nofpclass(nan norm zero sub) %x, [3 x [2 x float]] %y) {
-; CHECK-LABEL: define nofpclass(inf) [3 x [2 x float]] @ret_float_array
-; CHECK-SAME: (i1 [[COND:%.*]], [3 x [2 x float]] nofpclass(nan zero sub norm) [[X:%.*]], [3 x [2 x float]] [[Y:%.*]]) {
+; CHECK-LABEL: define nofpclass(inf) [3 x [2 x float]] @ret_float_array(
+; CHECK-SAME: i1 [[COND:%.*]], [3 x [2 x float]] nofpclass(nan zero sub norm) [[X:%.*]], [3 x [2 x float]] [[Y:%.*]]) {
 ; CHECK-NEXT:    ret [3 x [2 x float]] [[Y]]
 ;
   %select = select i1 %cond, [3 x [2 x float]] %x, [3 x [2 x float]] %y
@@ -137,8 +137,8 @@ define nofpclass(inf) [3 x [2 x float]] @ret_float_array(i1 %cond, [3 x [2 x flo
 }
 
 define nofpclass(nan) float @simplify_demanded_extractvalue_array(i1 %cond, [2 x float] %arg0) {
-; CHECK-LABEL: define nofpclass(nan) float @simplify_demanded_extractvalue_array
-; CHECK-SAME: (i1 [[COND:%.*]], [2 x float] [[ARG0:%.*]]) {
+; CHECK-LABEL: define nofpclass(nan) float @simplify_demanded_extractvalue_array(
+; CHECK-SAME: i1 [[COND:%.*]], [2 x float] [[ARG0:%.*]]) {
 ; CHECK-NEXT:    [[TMP1:%.*]] = extractvalue [2 x float] [[ARG0]], 0
 ; CHECK-NEXT:    ret float [[TMP1]]
 ;
@@ -148,8 +148,8 @@ define nofpclass(nan) float @simplify_demanded_extractvalue_array(i1 %cond, [2 x
 }
 
 define nofpclass(nan) float @simplify_demanded_extractvalue_array_partial_positive(i1 %cond, [2 x float] %arg0) {
-; CHECK-LABEL: define nofpclass(nan) float @simplify_demanded_extractvalue_array_partial_positive
-; CHECK-SAME: (i1 [[COND:%.*]], [2 x float] [[ARG0:%.*]]) {
+; CHECK-LABEL: define nofpclass(nan) float @simplify_demanded_extractvalue_array_partial_positive(
+; CHECK-SAME: i1 [[COND:%.*]], [2 x float] [[ARG0:%.*]]) {
 ; CHECK-NEXT:    [[TMP1:%.*]] = extractvalue [2 x float] [[ARG0]], 1
 ; CHECK-NEXT:    [[EXTRACT:%.*]] = select i1 [[COND]], float [[TMP1]], float 0.000000e+00
 ; CHECK-NEXT:    ret float [[EXTRACT]]
@@ -160,8 +160,8 @@ define nofpclass(nan) float @simplify_demanded_extractvalue_array_partial_positi
 }
 
 define nofpclass(nan) float @simplify_demanded_extractvalue_array_partialnegative(i1 %cond, [2 x float] %arg0) {
-; CHECK-LABEL: define nofpclass(nan) float @simplify_demanded_extractvalue_array_partialnegative
-; CHECK-SAME: (i1 [[COND:%.*]], [2 x float] [[ARG0:%.*]]) {
+; CHECK-LABEL: define nofpclass(nan) float @simplify_demanded_extractvalue_array_partialnegative(
+; CHECK-SAME: i1 [[COND:%.*]], [2 x float] [[ARG0:%.*]]) {
 ; CHECK-NEXT:    [[TMP1:%.*]] = extractvalue [2 x float] [[ARG0]], 1
 ; CHECK-NEXT:    ret float [[TMP1]]
 ;
@@ -171,8 +171,8 @@ define nofpclass(nan) float @simplify_demanded_extractvalue_array_partialnegativ
 }
 
 define nofpclass(nan) float @simplify_demanded_extractvalue_struct(i1 %cond, { float, float } %arg0) {
-; CHECK-LABEL: define nofpclass(nan) float @simplify_demanded_extractvalue_struct
-; CHECK-SAME: (i1 [[COND:%.*]], { float, float } [[ARG0:%.*]]) {
+; CHECK-LABEL: define nofpclass(nan) float @simplify_demanded_extractvalue_struct(
+; CHECK-SAME: i1 [[COND:%.*]], { float, float } [[ARG0:%.*]]) {
 ; CHECK-NEXT:    [[TMP1:%.*]] = extractvalue { float, float } [[ARG0]], 0
 ; CHECK-NEXT:    ret float [[TMP1]]
 ;
@@ -182,8 +182,8 @@ define nofpclass(nan) float @simplify_demanded_extractvalue_struct(i1 %cond, { f
 }
 
 define nofpclass(inf norm sub zero) float @simplify_demanded_extractvalue_only_nan(i1 %cond, [2 x float] %arg0) {
-; CHECK-LABEL: define nofpclass(inf zero sub norm) float @simplify_demanded_extractvalue_only_nan
-; CHECK-SAME: (i1 [[COND:%.*]], [2 x float] [[ARG0:%.*]]) {
+; CHECK-LABEL: define nofpclass(inf zero sub norm) float @simplify_demanded_extractvalue_only_nan(
+; CHECK-SAME: i1 [[COND:%.*]], [2 x float] [[ARG0:%.*]]) {
 ; CHECK-NEXT:    [[TMP1:%.*]] = extractvalue [2 x float] [[ARG0]], 0
 ; CHECK-NEXT:    [[EXTRACT:%.*]] = select i1 [[COND]], float [[TMP1]], float 0x7FF8000000000000
 ; CHECK-NEXT:    ret float [[EXTRACT]]
@@ -194,8 +194,8 @@ define nofpclass(inf norm sub zero) float @simplify_demanded_extractvalue_only_n
 }
 
 define nofpclass(nan inf norm sub nzero) float @simplify_demanded_extractvalue_only_pzero(i1 %cond, [2 x float] %arg0) {
-; CHECK-LABEL: define nofpclass(nan inf nzero sub norm) float @simplify_demanded_extractvalue_only_pzero
-; CHECK-SAME: (i1 [[COND:%.*]], [2 x float] [[ARG0:%.*]]) {
+; CHECK-LABEL: define nofpclass(nan inf nzero sub norm) float @simplify_demanded_extractvalue_only_pzero(
+; CHECK-SAME: i1 [[COND:%.*]], [2 x float] [[ARG0:%.*]]) {
 ; CHECK-NEXT:    ret float 0.000000e+00
 ;
   %select = select i1 %cond, [2 x float] %arg0, [2 x float] [float 0x7FF8000000000000, float 0x7FF8000000000000]



More information about the llvm-branch-commits mailing list