[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-23 Thread Matt Arsenault via llvm-branch-commits

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

>From dbb4b7d5f45fe2c07f7533c567848cc195122782 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 15 Jan 2026 11:21:53 +0100
Subject: [PATCH 1/4] InstCombine: Fold known-qnan results to a literal nan

Previously we only considered fcNan to fold to qnan for canonicalizing
results, ignoring the simpler case where we know the nan is already
quiet.
---
 .../InstCombine/InstCombineSimplifyDemanded.cpp  |  2 ++
 .../InstCombine/simplify-demanded-fpclass-exp.ll |  2 +-
 .../simplify-demanded-fpclass-extractelement.ll  |  3 +--
 .../InstCombine/simplify-demanded-fpclass-fadd.ll|  3 +--
 .../InstCombine/simplify-demanded-fpclass-fmul.ll|  6 ++
 .../InstCombine/simplify-demanded-fpclass-fpext.ll   |  3 +--
 .../simplify-demanded-fpclass-fptrunc-round.ll   |  3 +--
 .../InstCombine/simplify-demanded-fpclass-fptrunc.ll |  3 +--
 .../InstCombine/simplify-demanded-fpclass-frexp.ll   |  7 +++
 .../simplify-demanded-fpclass-insertelement.ll   |  7 +++
 .../InstCombine/simplify-demanded-fpclass-maximum.ll |  3 +--
 .../simplify-demanded-fpclass-maximumnum.ll  |  3 +--
 .../InstCombine/simplify-demanded-fpclass-minimum.ll |  3 +--
 .../simplify-demanded-fpclass-minimumnum.ll  |  3 +--
 .../simplify-demanded-fpclass-rounding-intrinsics.ll |  2 +-
 .../simplify-demanded-fpclass-shufflevector.ll   |  7 +++
 .../InstCombine/simplify-demanded-fpclass-sqrt.ll| 12 +++-
 .../InstCombine/simplify-demanded-fpclass.ll |  2 +-
 18 files changed, 28 insertions(+), 46 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index d8f8a03a76a2f..28010f080dc67 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -2029,6 +2029,8 @@ static Constant *getFPClassConstant(Type *Ty, FPClassTest 
Mask,
 return ConstantFP::getInfinity(Ty);
   case fcNegInf:
 return ConstantFP::getInfinity(Ty, true);
+  case fcQNan:
+return ConstantFP::getQNaN(Ty);
   default:
 return nullptr;
   }
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
index ef68699c73166..2a33ff195911e 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
@@ -490,7 +490,7 @@ define nofpclass(nzero) float @source_is_known_snan(float 
nofpclass(inf norm sub
 define nofpclass(nzero) float @source_is_known_qnan(float nofpclass(inf norm 
sub zero snan) %must.be.qnan) {
 ; CHECK-LABEL: define nofpclass(nzero) float @source_is_known_qnan(
 ; CHECK-SAME: float nofpclass(snan inf zero sub norm) [[MUST_BE_QNAN:%.*]]) {
-; CHECK-NEXT:ret float [[MUST_BE_QNAN]]
+; CHECK-NEXT:ret float 0x7FF8
 ;
   %exp = call float @llvm.exp2.f32(float %must.be.qnan)
   ret float %exp
diff --git 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
index e571774c72f2b..6cabee258d2b6 100644
--- 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
+++ 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
@@ -17,8 +17,7 @@ define nofpclass(inf norm sub zero) half 
@ret_only_nan__extractelement_unknown(<
 define nofpclass(snan inf norm sub zero) half 
@ret_only_qnan__extractelement_unknown(<4 x half> %vec, i32 %idx) {
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half 
@ret_only_qnan__extractelement_unknown(
 ; CHECK-SAME: <4 x half> [[VEC:%.*]], i32 [[IDX:%.*]]) {
-; CHECK-NEXT:[[EXT:%.*]] = extractelement <4 x half> [[VEC]], i32 [[IDX]]
-; CHECK-NEXT:ret half [[EXT]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %ext = extractelement <4 x half> %vec, i32 %idx
   ret half %ext
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
index ae9458cc1fe34..ea75dcd33c9c4 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
@@ -43,8 +43,7 @@ define nofpclass(inf zero sub norm) half @ret_only_nan(half 
%x, half %y) {
 define nofpclass(snan inf zero sub norm) half @ret_only_qnan(half %x, half %y) 
{
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half @ret_only_qnan(
 ; CHECK-SAME: half [[X:%.*]], half [[Y:%.*]]) {
-; CHECK-NEXT:[[ADD:%.*]] = fadd half [[X]], [[Y]]
-; CHECK-NEXT:ret half [[ADD]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %add = fadd half %x, %y
   ret half %add
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fmul.ll 

[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-23 Thread Matt Arsenault via llvm-branch-commits

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

>From dbb4b7d5f45fe2c07f7533c567848cc195122782 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 15 Jan 2026 11:21:53 +0100
Subject: [PATCH 1/4] InstCombine: Fold known-qnan results to a literal nan

Previously we only considered fcNan to fold to qnan for canonicalizing
results, ignoring the simpler case where we know the nan is already
quiet.
---
 .../InstCombine/InstCombineSimplifyDemanded.cpp  |  2 ++
 .../InstCombine/simplify-demanded-fpclass-exp.ll |  2 +-
 .../simplify-demanded-fpclass-extractelement.ll  |  3 +--
 .../InstCombine/simplify-demanded-fpclass-fadd.ll|  3 +--
 .../InstCombine/simplify-demanded-fpclass-fmul.ll|  6 ++
 .../InstCombine/simplify-demanded-fpclass-fpext.ll   |  3 +--
 .../simplify-demanded-fpclass-fptrunc-round.ll   |  3 +--
 .../InstCombine/simplify-demanded-fpclass-fptrunc.ll |  3 +--
 .../InstCombine/simplify-demanded-fpclass-frexp.ll   |  7 +++
 .../simplify-demanded-fpclass-insertelement.ll   |  7 +++
 .../InstCombine/simplify-demanded-fpclass-maximum.ll |  3 +--
 .../simplify-demanded-fpclass-maximumnum.ll  |  3 +--
 .../InstCombine/simplify-demanded-fpclass-minimum.ll |  3 +--
 .../simplify-demanded-fpclass-minimumnum.ll  |  3 +--
 .../simplify-demanded-fpclass-rounding-intrinsics.ll |  2 +-
 .../simplify-demanded-fpclass-shufflevector.ll   |  7 +++
 .../InstCombine/simplify-demanded-fpclass-sqrt.ll| 12 +++-
 .../InstCombine/simplify-demanded-fpclass.ll |  2 +-
 18 files changed, 28 insertions(+), 46 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index d8f8a03a76a2f..28010f080dc67 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -2029,6 +2029,8 @@ static Constant *getFPClassConstant(Type *Ty, FPClassTest 
Mask,
 return ConstantFP::getInfinity(Ty);
   case fcNegInf:
 return ConstantFP::getInfinity(Ty, true);
+  case fcQNan:
+return ConstantFP::getQNaN(Ty);
   default:
 return nullptr;
   }
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
index ef68699c73166..2a33ff195911e 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
@@ -490,7 +490,7 @@ define nofpclass(nzero) float @source_is_known_snan(float 
nofpclass(inf norm sub
 define nofpclass(nzero) float @source_is_known_qnan(float nofpclass(inf norm 
sub zero snan) %must.be.qnan) {
 ; CHECK-LABEL: define nofpclass(nzero) float @source_is_known_qnan(
 ; CHECK-SAME: float nofpclass(snan inf zero sub norm) [[MUST_BE_QNAN:%.*]]) {
-; CHECK-NEXT:ret float [[MUST_BE_QNAN]]
+; CHECK-NEXT:ret float 0x7FF8
 ;
   %exp = call float @llvm.exp2.f32(float %must.be.qnan)
   ret float %exp
diff --git 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
index e571774c72f2b..6cabee258d2b6 100644
--- 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
+++ 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
@@ -17,8 +17,7 @@ define nofpclass(inf norm sub zero) half 
@ret_only_nan__extractelement_unknown(<
 define nofpclass(snan inf norm sub zero) half 
@ret_only_qnan__extractelement_unknown(<4 x half> %vec, i32 %idx) {
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half 
@ret_only_qnan__extractelement_unknown(
 ; CHECK-SAME: <4 x half> [[VEC:%.*]], i32 [[IDX:%.*]]) {
-; CHECK-NEXT:[[EXT:%.*]] = extractelement <4 x half> [[VEC]], i32 [[IDX]]
-; CHECK-NEXT:ret half [[EXT]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %ext = extractelement <4 x half> %vec, i32 %idx
   ret half %ext
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
index ae9458cc1fe34..ea75dcd33c9c4 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
@@ -43,8 +43,7 @@ define nofpclass(inf zero sub norm) half @ret_only_nan(half 
%x, half %y) {
 define nofpclass(snan inf zero sub norm) half @ret_only_qnan(half %x, half %y) 
{
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half @ret_only_qnan(
 ; CHECK-SAME: half [[X:%.*]], half [[Y:%.*]]) {
-; CHECK-NEXT:[[ADD:%.*]] = fadd half [[X]], [[Y]]
-; CHECK-NEXT:ret half [[ADD]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %add = fadd half %x, %y
   ret half %add
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fmul.ll 

[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-15 Thread Matt Arsenault via llvm-branch-commits

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

>From 03d27f4a441697c60e9da391e24b7684e4589933 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 15 Jan 2026 11:21:53 +0100
Subject: [PATCH 1/3] InstCombine: Fold known-qnan results to a literal nan

Previously we only considered fcNan to fold to qnan for canonicalizing
results, ignoring the simpler case where we know the nan is already
quiet.
---
 .../InstCombine/InstCombineSimplifyDemanded.cpp  |  2 ++
 .../InstCombine/simplify-demanded-fpclass-exp.ll |  2 +-
 .../simplify-demanded-fpclass-extractelement.ll  |  3 +--
 .../InstCombine/simplify-demanded-fpclass-fadd.ll|  3 +--
 .../InstCombine/simplify-demanded-fpclass-fmul.ll|  6 ++
 .../InstCombine/simplify-demanded-fpclass-fpext.ll   |  3 +--
 .../simplify-demanded-fpclass-fptrunc-round.ll   |  3 +--
 .../InstCombine/simplify-demanded-fpclass-fptrunc.ll |  3 +--
 .../InstCombine/simplify-demanded-fpclass-frexp.ll   |  7 +++
 .../simplify-demanded-fpclass-insertelement.ll   |  7 +++
 .../InstCombine/simplify-demanded-fpclass-maximum.ll |  3 +--
 .../simplify-demanded-fpclass-maximumnum.ll  |  3 +--
 .../InstCombine/simplify-demanded-fpclass-minimum.ll |  3 +--
 .../simplify-demanded-fpclass-minimumnum.ll  |  3 +--
 .../simplify-demanded-fpclass-rounding-intrinsics.ll |  3 +--
 .../simplify-demanded-fpclass-shufflevector.ll   |  7 +++
 .../InstCombine/simplify-demanded-fpclass-sqrt.ll| 12 +++-
 .../InstCombine/simplify-demanded-fpclass.ll |  2 +-
 18 files changed, 28 insertions(+), 47 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index db8193f97ccf8..de1da8acae47a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -2028,6 +2028,8 @@ static Constant *getFPClassConstant(Type *Ty, FPClassTest 
Mask,
 return ConstantFP::getInfinity(Ty);
   case fcNegInf:
 return ConstantFP::getInfinity(Ty, true);
+  case fcQNan:
+return ConstantFP::getQNaN(Ty);
   default:
 return nullptr;
   }
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
index ef68699c73166..2a33ff195911e 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
@@ -490,7 +490,7 @@ define nofpclass(nzero) float @source_is_known_snan(float 
nofpclass(inf norm sub
 define nofpclass(nzero) float @source_is_known_qnan(float nofpclass(inf norm 
sub zero snan) %must.be.qnan) {
 ; CHECK-LABEL: define nofpclass(nzero) float @source_is_known_qnan(
 ; CHECK-SAME: float nofpclass(snan inf zero sub norm) [[MUST_BE_QNAN:%.*]]) {
-; CHECK-NEXT:ret float [[MUST_BE_QNAN]]
+; CHECK-NEXT:ret float 0x7FF8
 ;
   %exp = call float @llvm.exp2.f32(float %must.be.qnan)
   ret float %exp
diff --git 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
index e571774c72f2b..6cabee258d2b6 100644
--- 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
+++ 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
@@ -17,8 +17,7 @@ define nofpclass(inf norm sub zero) half 
@ret_only_nan__extractelement_unknown(<
 define nofpclass(snan inf norm sub zero) half 
@ret_only_qnan__extractelement_unknown(<4 x half> %vec, i32 %idx) {
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half 
@ret_only_qnan__extractelement_unknown(
 ; CHECK-SAME: <4 x half> [[VEC:%.*]], i32 [[IDX:%.*]]) {
-; CHECK-NEXT:[[EXT:%.*]] = extractelement <4 x half> [[VEC]], i32 [[IDX]]
-; CHECK-NEXT:ret half [[EXT]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %ext = extractelement <4 x half> %vec, i32 %idx
   ret half %ext
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
index 02a4fa5b52d10..ec13a1c113d15 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
@@ -43,8 +43,7 @@ define nofpclass(inf zero sub norm) half @ret_only_nan(half 
%x, half %y) {
 define nofpclass(snan inf zero sub norm) half @ret_only_qnan(half %x, half %y) 
{
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half @ret_only_qnan(
 ; CHECK-SAME: half [[X:%.*]], half [[Y:%.*]]) {
-; CHECK-NEXT:[[ADD:%.*]] = fadd half [[X]], [[Y]]
-; CHECK-NEXT:ret half [[ADD]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %add = fadd half %x, %y
   ret half %add
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fmul.ll

[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-15 Thread Matt Arsenault via llvm-branch-commits

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

>From 03d27f4a441697c60e9da391e24b7684e4589933 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 15 Jan 2026 11:21:53 +0100
Subject: [PATCH 1/3] InstCombine: Fold known-qnan results to a literal nan

Previously we only considered fcNan to fold to qnan for canonicalizing
results, ignoring the simpler case where we know the nan is already
quiet.
---
 .../InstCombine/InstCombineSimplifyDemanded.cpp  |  2 ++
 .../InstCombine/simplify-demanded-fpclass-exp.ll |  2 +-
 .../simplify-demanded-fpclass-extractelement.ll  |  3 +--
 .../InstCombine/simplify-demanded-fpclass-fadd.ll|  3 +--
 .../InstCombine/simplify-demanded-fpclass-fmul.ll|  6 ++
 .../InstCombine/simplify-demanded-fpclass-fpext.ll   |  3 +--
 .../simplify-demanded-fpclass-fptrunc-round.ll   |  3 +--
 .../InstCombine/simplify-demanded-fpclass-fptrunc.ll |  3 +--
 .../InstCombine/simplify-demanded-fpclass-frexp.ll   |  7 +++
 .../simplify-demanded-fpclass-insertelement.ll   |  7 +++
 .../InstCombine/simplify-demanded-fpclass-maximum.ll |  3 +--
 .../simplify-demanded-fpclass-maximumnum.ll  |  3 +--
 .../InstCombine/simplify-demanded-fpclass-minimum.ll |  3 +--
 .../simplify-demanded-fpclass-minimumnum.ll  |  3 +--
 .../simplify-demanded-fpclass-rounding-intrinsics.ll |  3 +--
 .../simplify-demanded-fpclass-shufflevector.ll   |  7 +++
 .../InstCombine/simplify-demanded-fpclass-sqrt.ll| 12 +++-
 .../InstCombine/simplify-demanded-fpclass.ll |  2 +-
 18 files changed, 28 insertions(+), 47 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index db8193f97ccf8..de1da8acae47a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -2028,6 +2028,8 @@ static Constant *getFPClassConstant(Type *Ty, FPClassTest 
Mask,
 return ConstantFP::getInfinity(Ty);
   case fcNegInf:
 return ConstantFP::getInfinity(Ty, true);
+  case fcQNan:
+return ConstantFP::getQNaN(Ty);
   default:
 return nullptr;
   }
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
index ef68699c73166..2a33ff195911e 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
@@ -490,7 +490,7 @@ define nofpclass(nzero) float @source_is_known_snan(float 
nofpclass(inf norm sub
 define nofpclass(nzero) float @source_is_known_qnan(float nofpclass(inf norm 
sub zero snan) %must.be.qnan) {
 ; CHECK-LABEL: define nofpclass(nzero) float @source_is_known_qnan(
 ; CHECK-SAME: float nofpclass(snan inf zero sub norm) [[MUST_BE_QNAN:%.*]]) {
-; CHECK-NEXT:ret float [[MUST_BE_QNAN]]
+; CHECK-NEXT:ret float 0x7FF8
 ;
   %exp = call float @llvm.exp2.f32(float %must.be.qnan)
   ret float %exp
diff --git 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
index e571774c72f2b..6cabee258d2b6 100644
--- 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
+++ 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
@@ -17,8 +17,7 @@ define nofpclass(inf norm sub zero) half 
@ret_only_nan__extractelement_unknown(<
 define nofpclass(snan inf norm sub zero) half 
@ret_only_qnan__extractelement_unknown(<4 x half> %vec, i32 %idx) {
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half 
@ret_only_qnan__extractelement_unknown(
 ; CHECK-SAME: <4 x half> [[VEC:%.*]], i32 [[IDX:%.*]]) {
-; CHECK-NEXT:[[EXT:%.*]] = extractelement <4 x half> [[VEC]], i32 [[IDX]]
-; CHECK-NEXT:ret half [[EXT]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %ext = extractelement <4 x half> %vec, i32 %idx
   ret half %ext
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
index 02a4fa5b52d10..ec13a1c113d15 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
@@ -43,8 +43,7 @@ define nofpclass(inf zero sub norm) half @ret_only_nan(half 
%x, half %y) {
 define nofpclass(snan inf zero sub norm) half @ret_only_qnan(half %x, half %y) 
{
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half @ret_only_qnan(
 ; CHECK-SAME: half [[X:%.*]], half [[Y:%.*]]) {
-; CHECK-NEXT:[[ADD:%.*]] = fadd half [[X]], [[Y]]
-; CHECK-NEXT:ret half [[ADD]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %add = fadd half %x, %y
   ret half %add
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fmul.ll

[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-15 Thread via llvm-branch-commits

github-actions[bot] wrote:


# :penguin: Linux x64 Test Results

* 168121 tests passed
* 2990 tests skipped
* 7 tests failed

## Failed Tests
(click on a test name to see its output)

### LLVM

LLVM.Transforms/InstCombine/simplify-demanded-fpclass-exp.ll

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/opt -S 
-passes=instcombine < 
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
 | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck 
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
# executed command: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/opt -S 
-passes=instcombine
# note: command had no output on stdout or stderr
# executed command: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck 
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
# .---command stderr
# | 
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll:493:15:
 error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret float 0x7FF8
# |   ^
# | :225:109: note: scanning from here
# | define nofpclass(nzero) float @source_is_known_qnan(float nofpclass(snan 
inf zero sub norm) %must.be.qnan) {
# | 
^
# | :226:2: note: possible intended match here
# |  ret float %must.be.qnan
# |  ^
# | 
# | Input file: 
# | Check file: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<
# | .
# | .
# | .
# |   220:  
# |   221: define nofpclass(nzero) float @source_is_known_snan(float 
nofpclass(qnan inf zero sub norm) %must.be.snan) { 
# |   222:  ret float %must.be.snan 
# |   223: } 
# |   224:  
# |   225: define nofpclass(nzero) float @source_is_known_qnan(float 
nofpclass(snan inf zero sub norm) %must.be.qnan) { 
# | next:493'0  
   X error: no match found
# |   226:  ret float %must.be.qnan 
# | next:493'0 ~
# | next:493'1  ?possible intended match
# |   227: } 
# | next:493'0 ~~
# |   228:  
# | next:493'0 ~
# |   229: define nofpclass(nan pzero) float 
@source_is_known_zero_or_nan__nnan_result(float nofpclass(inf sub norm) 
%must.be.zero.or.nan) { 
# | next:493'0 

# |   230:  ret float 1.00e+00 
# |   231: } 
# | .
# | .
# | .
# | >>
# `-
# error: command failed with exit status: 1

--

```


LLVM.Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/opt -S 
-passes=instcombine < 
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
 | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck 
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
# executed command: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/opt -S 
-passes=instcombine
# note: command had no output on stdout or stderr
# executed command: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck 
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
# .---command stderr
# | 
/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll:20:15:
 error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret half 0xH7E00
# |   ^
# | :13:114: note: scanning from here
# | define nofpclass(snan inf zero sub norm) half 
@ret_only_qnan__extractelement_unknown(<4 x half> %vec, i32 %idx) {
# | 
 ^
# | :15:2: note: possible intended match here
# |  ret half %ext
# |  ^
# | 
# | Input file: 
# | Check file: 
/home/gha/actions-runne

[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-15 Thread via llvm-branch-commits

github-actions[bot] wrote:


# :window: Windows x64 Test Results

* 129511 tests passed
* 2865 tests skipped
* 7 tests failed

## Failed Tests
(click on a test name to see its output)

### LLVM

LLVM.Transforms/InstCombine/simplify-demanded-fpclass-exp.ll

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
c:\_work\llvm-project\llvm-project\build\bin\opt.exe -S -passes=instcombine < 
C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\simplify-demanded-fpclass-exp.ll
 | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe 
C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\simplify-demanded-fpclass-exp.ll
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\opt.exe' -S 
-passes=instcombine
# note: command had no output on stdout or stderr
# executed command: 
'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 
'C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\simplify-demanded-fpclass-exp.ll'
# .---command stderr
# | 
C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\simplify-demanded-fpclass-exp.ll:493:15:
 error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret float 0x7FF8
# |   ^
# | :225:109: note: scanning from here
# | define nofpclass(nzero) float @source_is_known_qnan(float nofpclass(snan 
inf zero sub norm) %must.be.qnan) {
# | 
^
# | :226:2: note: possible intended match here
# |  ret float %must.be.qnan
# |  ^
# | 
# | Input file: 
# | Check file: 
C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\simplify-demanded-fpclass-exp.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<
# | .
# | .
# | .
# |   220:  
# |   221: define nofpclass(nzero) float @source_is_known_snan(float 
nofpclass(qnan inf zero sub norm) %must.be.snan) { 
# |   222:  ret float %must.be.snan 
# |   223: } 
# |   224:  
# |   225: define nofpclass(nzero) float @source_is_known_qnan(float 
nofpclass(snan inf zero sub norm) %must.be.qnan) { 
# | next:493'0  
   X error: no match found
# |   226:  ret float %must.be.qnan 
# | next:493'0 ~
# | next:493'1  ?possible intended match
# |   227: } 
# | next:493'0 ~~
# |   228:  
# | next:493'0 ~
# |   229: define nofpclass(nan pzero) float 
@source_is_known_zero_or_nan__nnan_result(float nofpclass(inf sub norm) 
%must.be.zero.or.nan) { 
# | next:493'0 

# |   230:  ret float 1.00e+00 
# |   231: } 
# | .
# | .
# | .
# | >>
# `-
# error: command failed with exit status: 1

--

```


LLVM.Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
c:\_work\llvm-project\llvm-project\build\bin\opt.exe -S -passes=instcombine < 
C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\simplify-demanded-fpclass-extractelement.ll
 | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe 
C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\simplify-demanded-fpclass-extractelement.ll
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\opt.exe' -S 
-passes=instcombine
# note: command had no output on stdout or stderr
# executed command: 
'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 
'C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\simplify-demanded-fpclass-extractelement.ll'
# .---command stderr
# | 
C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\simplify-demanded-fpclass-extractelement.ll:20:15:
 error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret half 0xH7E00
# |   ^
# | :13:114: note: scanning from here
# | define nofpclass(snan inf zero sub norm) half 
@ret_only_qnan__extractelement_unknown(<4 x half> %vec, i32 %idx) {
# | 
 ^
# | :15:2: note: possible intended match here
# |  ret half %ext
# |  ^
# | 
# | Input file: 
# | Check file: 
C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\simplify-demanded-fpclass-extractelement.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<
# |.
# |.
# |.
# |8: define nofpclass(inf zero sub norm) half 
@ret_only_nan__extractelement_unknown(<4 

[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-15 Thread Yingwei Zheng via llvm-branch-commits


@@ -2013,21 +2013,24 @@ static Constant *getFPClassConstant(Type *Ty, 
FPClassTest Mask,
   if (Mask == fcPosZero)
 return Constant::getNullValue(Ty);
 
-  // Turn any possible snans into quiet if we can.
-  if (Mask == fcNan && IsCanonicalizing)
-return ConstantFP::getQNaN(Ty);
-
   // TODO: Support aggregate types that are allowed by FPMathOperator.
   if (Ty->isAggregateType())
 return nullptr;
 
+  // Turn any possible snans into quiet if we can.
+  if (Mask == fcNan && IsCanonicalizing)
+return ConstantFP::getQNaN(Ty);
+
   switch (Mask) {
   case fcNegZero:
 return ConstantFP::getZero(Ty, true);
   case fcPosInf:
 return ConstantFP::getInfinity(Ty);
   case fcNegInf:
 return ConstantFP::getInfinity(Ty, true);
+  case fcQNan:

dtcxzyw wrote:

It is identical to modifying the check `Mask == fcNan` to (Mask & fcQNan) != 
fcNone. BTW, can we just return a poison when Mask == fcSNan && 
IsCanonicalizing?

https://github.com/llvm/llvm-project/pull/176123
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-15 Thread Matt Arsenault via llvm-branch-commits

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

>From 76a5fef806f53b39b752b045c851a3735cc29106 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 15 Jan 2026 11:21:53 +0100
Subject: [PATCH 1/3] InstCombine: Fold known-qnan results to a literal nan

Previously we only considered fcNan to fold to qnan for canonicalizing
results, ignoring the simpler case where we know the nan is already
quiet.
---
 .../InstCombine/InstCombineSimplifyDemanded.cpp  |  2 ++
 .../InstCombine/simplify-demanded-fpclass-exp.ll |  2 +-
 .../simplify-demanded-fpclass-extractelement.ll  |  3 +--
 .../InstCombine/simplify-demanded-fpclass-fadd.ll|  3 +--
 .../InstCombine/simplify-demanded-fpclass-fmul.ll|  6 ++
 .../InstCombine/simplify-demanded-fpclass-fpext.ll   |  3 +--
 .../simplify-demanded-fpclass-fptrunc-round.ll   |  3 +--
 .../InstCombine/simplify-demanded-fpclass-fptrunc.ll |  3 +--
 .../InstCombine/simplify-demanded-fpclass-frexp.ll   |  7 +++
 .../simplify-demanded-fpclass-insertelement.ll   |  7 +++
 .../InstCombine/simplify-demanded-fpclass-maximum.ll |  3 +--
 .../simplify-demanded-fpclass-maximumnum.ll  |  3 +--
 .../InstCombine/simplify-demanded-fpclass-minimum.ll |  3 +--
 .../simplify-demanded-fpclass-minimumnum.ll  |  3 +--
 .../simplify-demanded-fpclass-rounding-intrinsics.ll |  3 +--
 .../simplify-demanded-fpclass-shufflevector.ll   |  7 +++
 .../InstCombine/simplify-demanded-fpclass-sqrt.ll| 12 +++-
 .../InstCombine/simplify-demanded-fpclass.ll |  2 +-
 18 files changed, 28 insertions(+), 47 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index f19449a003e9f..c2cdca4134b3e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -2028,6 +2028,8 @@ static Constant *getFPClassConstant(Type *Ty, FPClassTest 
Mask,
 return ConstantFP::getInfinity(Ty);
   case fcNegInf:
 return ConstantFP::getInfinity(Ty, true);
+  case fcQNan:
+return ConstantFP::getQNaN(Ty);
   default:
 return nullptr;
   }
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
index ef68699c73166..2a33ff195911e 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
@@ -490,7 +490,7 @@ define nofpclass(nzero) float @source_is_known_snan(float 
nofpclass(inf norm sub
 define nofpclass(nzero) float @source_is_known_qnan(float nofpclass(inf norm 
sub zero snan) %must.be.qnan) {
 ; CHECK-LABEL: define nofpclass(nzero) float @source_is_known_qnan(
 ; CHECK-SAME: float nofpclass(snan inf zero sub norm) [[MUST_BE_QNAN:%.*]]) {
-; CHECK-NEXT:ret float [[MUST_BE_QNAN]]
+; CHECK-NEXT:ret float 0x7FF8
 ;
   %exp = call float @llvm.exp2.f32(float %must.be.qnan)
   ret float %exp
diff --git 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
index e571774c72f2b..6cabee258d2b6 100644
--- 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
+++ 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
@@ -17,8 +17,7 @@ define nofpclass(inf norm sub zero) half 
@ret_only_nan__extractelement_unknown(<
 define nofpclass(snan inf norm sub zero) half 
@ret_only_qnan__extractelement_unknown(<4 x half> %vec, i32 %idx) {
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half 
@ret_only_qnan__extractelement_unknown(
 ; CHECK-SAME: <4 x half> [[VEC:%.*]], i32 [[IDX:%.*]]) {
-; CHECK-NEXT:[[EXT:%.*]] = extractelement <4 x half> [[VEC]], i32 [[IDX]]
-; CHECK-NEXT:ret half [[EXT]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %ext = extractelement <4 x half> %vec, i32 %idx
   ret half %ext
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
index 099624e912912..4386d22f82df4 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
@@ -43,8 +43,7 @@ define nofpclass(inf zero sub norm) half @ret_only_nan(half 
%x, half %y) {
 define nofpclass(snan inf zero sub norm) half @ret_only_qnan(half %x, half %y) 
{
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half @ret_only_qnan(
 ; CHECK-SAME: half [[X:%.*]], half [[Y:%.*]]) {
-; CHECK-NEXT:[[ADD:%.*]] = fadd half [[X]], [[Y]]
-; CHECK-NEXT:ret half [[ADD]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %add = fadd half %x, %y
   ret half %add
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fmul.ll

[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-15 Thread Matt Arsenault via llvm-branch-commits

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

>From 76a5fef806f53b39b752b045c851a3735cc29106 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Thu, 15 Jan 2026 11:21:53 +0100
Subject: [PATCH 1/3] InstCombine: Fold known-qnan results to a literal nan

Previously we only considered fcNan to fold to qnan for canonicalizing
results, ignoring the simpler case where we know the nan is already
quiet.
---
 .../InstCombine/InstCombineSimplifyDemanded.cpp  |  2 ++
 .../InstCombine/simplify-demanded-fpclass-exp.ll |  2 +-
 .../simplify-demanded-fpclass-extractelement.ll  |  3 +--
 .../InstCombine/simplify-demanded-fpclass-fadd.ll|  3 +--
 .../InstCombine/simplify-demanded-fpclass-fmul.ll|  6 ++
 .../InstCombine/simplify-demanded-fpclass-fpext.ll   |  3 +--
 .../simplify-demanded-fpclass-fptrunc-round.ll   |  3 +--
 .../InstCombine/simplify-demanded-fpclass-fptrunc.ll |  3 +--
 .../InstCombine/simplify-demanded-fpclass-frexp.ll   |  7 +++
 .../simplify-demanded-fpclass-insertelement.ll   |  7 +++
 .../InstCombine/simplify-demanded-fpclass-maximum.ll |  3 +--
 .../simplify-demanded-fpclass-maximumnum.ll  |  3 +--
 .../InstCombine/simplify-demanded-fpclass-minimum.ll |  3 +--
 .../simplify-demanded-fpclass-minimumnum.ll  |  3 +--
 .../simplify-demanded-fpclass-rounding-intrinsics.ll |  3 +--
 .../simplify-demanded-fpclass-shufflevector.ll   |  7 +++
 .../InstCombine/simplify-demanded-fpclass-sqrt.ll| 12 +++-
 .../InstCombine/simplify-demanded-fpclass.ll |  2 +-
 18 files changed, 28 insertions(+), 47 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index f19449a003e9f..c2cdca4134b3e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -2028,6 +2028,8 @@ static Constant *getFPClassConstant(Type *Ty, FPClassTest 
Mask,
 return ConstantFP::getInfinity(Ty);
   case fcNegInf:
 return ConstantFP::getInfinity(Ty, true);
+  case fcQNan:
+return ConstantFP::getQNaN(Ty);
   default:
 return nullptr;
   }
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
index ef68699c73166..2a33ff195911e 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
@@ -490,7 +490,7 @@ define nofpclass(nzero) float @source_is_known_snan(float 
nofpclass(inf norm sub
 define nofpclass(nzero) float @source_is_known_qnan(float nofpclass(inf norm 
sub zero snan) %must.be.qnan) {
 ; CHECK-LABEL: define nofpclass(nzero) float @source_is_known_qnan(
 ; CHECK-SAME: float nofpclass(snan inf zero sub norm) [[MUST_BE_QNAN:%.*]]) {
-; CHECK-NEXT:ret float [[MUST_BE_QNAN]]
+; CHECK-NEXT:ret float 0x7FF8
 ;
   %exp = call float @llvm.exp2.f32(float %must.be.qnan)
   ret float %exp
diff --git 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
index e571774c72f2b..6cabee258d2b6 100644
--- 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
+++ 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
@@ -17,8 +17,7 @@ define nofpclass(inf norm sub zero) half 
@ret_only_nan__extractelement_unknown(<
 define nofpclass(snan inf norm sub zero) half 
@ret_only_qnan__extractelement_unknown(<4 x half> %vec, i32 %idx) {
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half 
@ret_only_qnan__extractelement_unknown(
 ; CHECK-SAME: <4 x half> [[VEC:%.*]], i32 [[IDX:%.*]]) {
-; CHECK-NEXT:[[EXT:%.*]] = extractelement <4 x half> [[VEC]], i32 [[IDX]]
-; CHECK-NEXT:ret half [[EXT]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %ext = extractelement <4 x half> %vec, i32 %idx
   ret half %ext
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
index 099624e912912..4386d22f82df4 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
@@ -43,8 +43,7 @@ define nofpclass(inf zero sub norm) half @ret_only_nan(half 
%x, half %y) {
 define nofpclass(snan inf zero sub norm) half @ret_only_qnan(half %x, half %y) 
{
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half @ret_only_qnan(
 ; CHECK-SAME: half [[X:%.*]], half [[Y:%.*]]) {
-; CHECK-NEXT:[[ADD:%.*]] = fadd half [[X]], [[Y]]
-; CHECK-NEXT:ret half [[ADD]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %add = fadd half %x, %y
   ret half %add
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fmul.ll

[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-15 Thread Yingwei Zheng via llvm-branch-commits


@@ -2028,6 +2028,8 @@ static Constant *getFPClassConstant(Type *Ty, FPClassTest 
Mask,
 return ConstantFP::getInfinity(Ty);

dtcxzyw wrote:

> [Re: line +2018]

I am talking about the previous one.

https://github.com/llvm/llvm-project/pull/176123
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-15 Thread Yingwei Zheng via llvm-branch-commits


@@ -2028,6 +2028,8 @@ static Constant *getFPClassConstant(Type *Ty, FPClassTest 
Mask,
 return ConstantFP::getInfinity(Ty);

dtcxzyw wrote:

[Re: line 
+2018]
IIRC getQNaN doesn't support fp structs either.
See this comment 
inline on https://app.graphite.com/github/pr/llvm/llvm-project/176123?utm_source=unchanged-line-comment";>Graphite.

https://github.com/llvm/llvm-project/pull/176123
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-15 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)


Changes

Previously we only considered fcNan to fold to qnan for canonicalizing
results, ignoring the simpler case where we know the nan is already
quiet.

---

Patch is 21.96 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/176123.diff


18 Files Affected:

- (modified) llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 
(+2) 
- (modified) llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll 
(+1-1) 
- (modified) 
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll 
(+1-2) 
- (modified) llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll 
(+1-2) 
- (modified) llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fmul.ll 
(+2-4) 
- (modified) 
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fpext.ll (+1-2) 
- (modified) 
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fptrunc-round.ll 
(+1-2) 
- (modified) 
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fptrunc.ll (+1-2) 
- (modified) 
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-frexp.ll (+3-4) 
- (modified) 
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-insertelement.ll 
(+3-4) 
- (modified) 
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-maximum.ll (+1-2) 
- (modified) 
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-maximumnum.ll (+1-2) 
- (modified) 
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-minimum.ll (+1-2) 
- (modified) 
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-minimumnum.ll (+1-2) 
- (modified) 
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-rounding-intrinsics.ll
 (+1-2) 
- (modified) 
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-shufflevector.ll 
(+3-4) 
- (modified) llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-sqrt.ll 
(+3-9) 
- (modified) llvm/test/Transforms/InstCombine/simplify-demanded-fpclass.ll 
(+1-1) 


``diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 1fc298dfc52a2..9f32e4fef1c3d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -2028,6 +2028,8 @@ static Constant *getFPClassConstant(Type *Ty, FPClassTest 
Mask,
 return ConstantFP::getInfinity(Ty);
   case fcNegInf:
 return ConstantFP::getInfinity(Ty, true);
+  case fcQNan:
+return ConstantFP::getQNaN(Ty);
   default:
 return nullptr;
   }
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
index ef68699c73166..2a33ff195911e 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-exp.ll
@@ -490,7 +490,7 @@ define nofpclass(nzero) float @source_is_known_snan(float 
nofpclass(inf norm sub
 define nofpclass(nzero) float @source_is_known_qnan(float nofpclass(inf norm 
sub zero snan) %must.be.qnan) {
 ; CHECK-LABEL: define nofpclass(nzero) float @source_is_known_qnan(
 ; CHECK-SAME: float nofpclass(snan inf zero sub norm) [[MUST_BE_QNAN:%.*]]) {
-; CHECK-NEXT:ret float [[MUST_BE_QNAN]]
+; CHECK-NEXT:ret float 0x7FF8
 ;
   %exp = call float @llvm.exp2.f32(float %must.be.qnan)
   ret float %exp
diff --git 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
index e571774c72f2b..6cabee258d2b6 100644
--- 
a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
+++ 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-extractelement.ll
@@ -17,8 +17,7 @@ define nofpclass(inf norm sub zero) half 
@ret_only_nan__extractelement_unknown(<
 define nofpclass(snan inf norm sub zero) half 
@ret_only_qnan__extractelement_unknown(<4 x half> %vec, i32 %idx) {
 ; CHECK-LABEL: define nofpclass(snan inf zero sub norm) half 
@ret_only_qnan__extractelement_unknown(
 ; CHECK-SAME: <4 x half> [[VEC:%.*]], i32 [[IDX:%.*]]) {
-; CHECK-NEXT:[[EXT:%.*]] = extractelement <4 x half> [[VEC]], i32 [[IDX]]
-; CHECK-NEXT:ret half [[EXT]]
+; CHECK-NEXT:ret half 0xH7E00
 ;
   %ext = extractelement <4 x half> %vec, i32 %idx
   ret half %ext
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
index 099624e912912..4386d22f82df4 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fadd.ll
@@ -43,8 +43,7 @@ define nofpclass(inf zero sub norm) half @ret_only_nan(half 
%x, half %y) {
 define nofpclass(snan inf zero 

[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

2026-01-15 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm ready_for_review 
https://github.com/llvm/llvm-project/pull/176123
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits