[llvm] InstCombine: Support extractvalue in SimplifyDemandedFPClass (PR #184171)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 2 08:50:21 PST 2026


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

>From 2d1b3e7758fbc2657d09667f14e59c56f83fa403 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 2 Mar 2026 17:34:54 +0100
Subject: [PATCH] InstCombine: Support extractvalue in SimplifyDemandedFPClass

Previously this only handled extractvalue of frexp.
---
 .../InstCombineSimplifyDemanded.cpp           |  7 +-
 .../InstCombine/simplify-demanded-fpclass.ll  | 68 +++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 456d39ecc30cb..6dd89f9c90bbd 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -3458,7 +3458,12 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass(Instruction *I,
         }
       }
     }
-    [[fallthrough]];
+
+    KnownFPClass KnownSrc;
+    if (SimplifyDemandedFPClass(I, 0, DemandedMask, KnownSrc, Depth + 1))
+      return I;
+    Known = KnownSrc;
+    break;
   }
   default:
     Known = computeKnownFPClass(I, DemandedMask, SQ, Depth + 1);
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass.ll b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass.ll
index 6be1c0df2e74c..d9ca1b7cd6ba8 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass.ll
@@ -2709,3 +2709,71 @@ define double @eigen_nofpclass_regression(ptr %ptr, double %arg) {
 }
 
 declare double @func(double nofpclass(nan inf nzero sub norm) %x, double nofpclass(nan inf zero sub nnorm) %v, double nofpclass(nan inf zero sub pnorm) %a)
+
+
+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-NEXT:    [[TMP1:%.*]] = extractvalue [2 x float] [[ARG0]], 0
+; CHECK-NEXT:    ret float [[TMP1]]
+;
+  %select = select i1 %cond, [2 x float] %arg0, [2 x float] [float 0x7FF8000000000000, float 0x7FF8000000000000]
+  %extract = extractvalue [2 x float] %select, 0
+  ret float %extract
+}
+
+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-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]]
+;
+  %select = select i1 %cond, [2 x float] %arg0, [2 x float] [float 0x7FF8000000000000, float 0.0]
+  %extract = extractvalue [2 x float] %select, 1
+  ret float %extract
+}
+
+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-NEXT:    [[TMP1:%.*]] = extractvalue [2 x float] [[ARG0]], 1
+; CHECK-NEXT:    ret float [[TMP1]]
+;
+  %select = select i1 %cond, [2 x float] %arg0, [2 x float] [float 0.0, float 0x7FF8000000000000]
+  %extract = extractvalue [2 x float] %select, 1
+  ret float %extract
+}
+
+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-NEXT:    [[TMP1:%.*]] = extractvalue { float, float } [[ARG0]], 0
+; CHECK-NEXT:    ret float [[TMP1]]
+;
+  %select = select i1 %cond, { float, float } %arg0, { float, float } {float 0x7FF8000000000000, float 0x7FF8000000000000}
+  %extract = extractvalue { float, float } %select, 0
+  ret float %extract
+}
+
+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-NEXT:    [[TMP1:%.*]] = extractvalue [2 x float] [[ARG0]], 0
+; CHECK-NEXT:    [[EXTRACT:%.*]] = select i1 [[COND]], float [[TMP1]], float 0x7FF8000000000000
+; CHECK-NEXT:    ret float [[EXTRACT]]
+;
+  %select = select i1 %cond, [2 x float] %arg0, [2 x float] [float 0x7FF8000000000000, float 0x7FF8000000000000]
+  %extract = extractvalue [2 x float] %select, 0
+  ret float %extract
+}
+
+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-NEXT:    ret float 0.000000e+00
+;
+  %select = select i1 %cond, [2 x float] %arg0, [2 x float] [float 0x7FF8000000000000, float 0x7FF8000000000000]
+  %extract = extractvalue [2 x float] %select, 0
+  ret float %extract
+}



More information about the llvm-commits mailing list