[llvm] b9f1199 - InstCombine: Support extractvalue in SimplifyDemandedFPClass (#184171)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 4 08:52:48 PST 2026
Author: Matt Arsenault
Date: 2026-03-04T17:52:42+01:00
New Revision: b9f1199581e746152a019a104d22f87ce41f46e1
URL: https://github.com/llvm/llvm-project/commit/b9f1199581e746152a019a104d22f87ce41f46e1
DIFF: https://github.com/llvm/llvm-project/commit/b9f1199581e746152a019a104d22f87ce41f46e1.diff
LOG: InstCombine: Support extractvalue in SimplifyDemandedFPClass (#184171)
Previously this only handled extractvalue of frexp.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-aggregates.ll
Removed:
################################################################################
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-aggregates.ll b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-aggregates.ll
index 0556e7ea232ce..b073e6611d870 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-aggregates.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-aggregates.ll
@@ -135,3 +135,70 @@ define nofpclass(inf) [3 x [2 x float]] @ret_float_array(i1 %cond, [3 x [2 x flo
%select = select i1 %cond, [3 x [2 x float]] %x, [3 x [2 x float]] %y
ret [3 x [2 x float ]] %select
}
+
+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