[llvm] a227dc7 - [DAG] visitIS_FPCLASS - fold to constant when result is fully determined by KnownFPClass (#193737)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 24 04:09:27 PDT 2026
Author: Xinlong Chen
Date: 2026-04-24T11:09:22Z
New Revision: a227dc7c0980c414c4a7d9f1f3f64130b1956b0c
URL: https://github.com/llvm/llvm-project/commit/a227dc7c0980c414c4a7d9f1f3f64130b1956b0c
DIFF: https://github.com/llvm/llvm-project/commit/a227dc7c0980c414c4a7d9f1f3f64130b1956b0c.diff
LOG: [DAG] visitIS_FPCLASS - fold to constant when result is fully determined by KnownFPClass (#193737)
This PR teaches `DAGCombiner::visitIS_FPCLASS` to fold directly to
constant `true` based on the source's `KnownFPClass`, instead of only
narrowing the test mask.
Prep work to help with https://github.com/llvm/llvm-project/pull/193672
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/RISCV/combine-is_fpclass.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 01d7023799138..41fe4f6c09a56 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -16162,6 +16162,10 @@ SDValue DAGCombiner::visitIS_FPCLASS(SDNode *N) {
KnownFPClass Known = DAG.computeKnownFPClass(Src, Mask);
+ // All possible classes are within the mask: result is always true.
+ if ((~Mask & Known.KnownFPClasses) == fcNone)
+ return DAG.getBoolConstant(true, DL, VT, Src.getValueType());
+
// Clear test bits we know must be false from the source value.
// fp_class (nnan x), qnan|snan|other -> fp_class (nnan x), other
// fp_class (ninf x), ninf|pinf|other -> fp_class (ninf x), other
diff --git a/llvm/test/CodeGen/RISCV/combine-is_fpclass.ll b/llvm/test/CodeGen/RISCV/combine-is_fpclass.ll
index 71621b8837d6b..99c0be5b9692b 100644
--- a/llvm/test/CodeGen/RISCV/combine-is_fpclass.ll
+++ b/llvm/test/CodeGen/RISCV/combine-is_fpclass.ll
@@ -186,6 +186,16 @@ define i1 @extract_scalable_fabs_isneg(<vscale x 4 x float> %a0) nounwind {
ret i1 %res
}
+define i1 @fabs_is_nonneg_or_nan(float %x) nounwind {
+; CHECK-LABEL: fabs_is_nonneg_or_nan:
+; CHECK: # %bb.0:
+; CHECK-NEXT: li a0, 1
+; CHECK-NEXT: ret
+ %a = call float @llvm.fabs.f32(float %x)
+ %res = call i1 @llvm.is.fpclass.f32(float %a, i32 963) ; 0x3C3 = any positive | nan
+ ret i1 %res
+}
+
define <vscale x 4 x i1> @splat_constant_is_pos_normal() {
; CHECK-LABEL: splat_constant_is_pos_normal:
; CHECK: # %bb.0:
More information about the llvm-commits
mailing list