[llvm] [DAG] computeKnownFPClass - add ISD::SPLAT_VECTOR handling (PR #189780)

Kartik Ohlan via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 31 17:51:06 PDT 2026


https://github.com/Ko496-glitch created https://github.com/llvm/llvm-project/pull/189780

Fixes #189481.

Implement ISD::SPLAT_VECTOR in SelectionDAG::computeKnownFPClass to correctly propagate floating-point properties from scalar operands to vectors. 

Added AArch64 and RISC-V test coverage

>From 8f76d3340f47e17ff65ef596ffb4ae695df6e8dd Mon Sep 17 00:00:00 2001
From: kartikohlan <kartik7ohlan at gmail.com>
Date: Tue, 31 Mar 2026 20:35:21 -0400
Subject: [PATCH 1/2] Issue 189529

---
 .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp |   6 +
 .../AArch64/known-fpclass-splat-vector.ll     | 111 ++++++++++++++++++
 .../RISCV/known-fpclass-splat-vector.ll       | 106 +++++++++++++++++
 3 files changed, 223 insertions(+)
 create mode 100644 llvm/test/CodeGen/AArch64/known-fpclass-splat-vector.ll
 create mode 100644 llvm/test/CodeGen/RISCV/known-fpclass-splat-vector.ll

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 3716de880cce3..8bcc25daa6bcc 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6112,6 +6112,12 @@ KnownFPClass SelectionDAG::computeKnownFPClass(SDValue Op,
     }
     break;
   }
+
+  case ISD::SPLAT_VECTOR: {
+    Known = computeKnownFPClass(Op.getOperand(0), InterestedClasses, Depth + 1);
+    break;
+  }
+
   default:
     if (Opcode >= ISD::BUILTIN_OP_END || Opcode == ISD::INTRINSIC_WO_CHAIN ||
         Opcode == ISD::INTRINSIC_W_CHAIN || Opcode == ISD::INTRINSIC_VOID) {
diff --git a/llvm/test/CodeGen/AArch64/known-fpclass-splat-vector.ll b/llvm/test/CodeGen/AArch64/known-fpclass-splat-vector.ll
new file mode 100644
index 0000000000000..769317270c195
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/known-fpclass-splat-vector.ll
@@ -0,0 +1,111 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64 -mattr=+sve < %s | FileCheck %s
+
+define i1 @isinf_f32(float %x) {
+; CHECK-LABEL: isinf_f32:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    fsqrt s0, s0
+; CHECK-NEXT:    mov w8, #-16777216 // =0xff000000
+; CHECK-NEXT:    fmov w9, s0
+; CHECK-NEXT:    cmp w8, w9, lsl #1
+; CHECK-NEXT:    cset w0, eq
+; CHECK-NEXT:    ret
+  %sqr = call nsz ninf float @llvm.sqrt.f32(float %x)
+  %res = tail call i1 @llvm.is.fpclass.f32(float %sqr, i32 516)
+  ret i1 %res
+}
+
+define i1 @isinf_f64(double %x) {
+; CHECK-LABEL: isinf_f64:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    fsqrt d0, d0
+; CHECK-NEXT:    mov x8, #-9007199254740992 // =0xffe0000000000000
+; CHECK-NEXT:    fmov x9, d0
+; CHECK-NEXT:    cmp x8, x9, lsl #1
+; CHECK-NEXT:    cset w0, eq
+; CHECK-NEXT:    ret
+  %sqr = call nsz ninf double @llvm.sqrt.f64(double %x)
+  %res = tail call i1 @llvm.is.fpclass.f64(double %sqr, i32 516)
+  ret i1 %res
+}
+
+define i1 @isinf_f16(half %x) {
+; CHECK-LABEL: isinf_f16:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    fsqrt h0, h0
+; CHECK-NEXT:    mov w8, #31744 // =0x7c00
+; CHECK-NEXT:    fmov h1, w8
+; CHECK-NEXT:    fabs h0, h0
+; CHECK-NEXT:    fcmp h0, h1
+; CHECK-NEXT:    cset w0, eq
+; CHECK-NEXT:    ret
+  %sqr = call nsz ninf half @llvm.sqrt.f16(half %x)
+  %res = tail call i1 @llvm.is.fpclass.f16(half %sqr, i32 516)
+  ret i1 %res
+}
+
+define i1 @isnan_f32(float %x) {
+; CHECK-LABEL: isnan_f32:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    fsqrt s0, s0
+; CHECK-NEXT:    fcmp s0, s0
+; CHECK-NEXT:    cset w0, vs
+; CHECK-NEXT:    ret
+  %sqr = call nsz ninf float @llvm.sqrt.f32(float %x)
+  %res = tail call i1 @llvm.is.fpclass.f32(float %sqr, i32 3)
+  ret i1 %res
+}
+
+define i1 @isnan_f64(double %x) {
+; CHECK-LABEL: isnan_f64:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    fsqrt d0, d0
+; CHECK-NEXT:    fcmp d0, d0
+; CHECK-NEXT:    cset w0, vs
+; CHECK-NEXT:    ret
+  %sqr = call nsz ninf double @llvm.sqrt.f64(double %x)
+  %res = tail call i1 @llvm.is.fpclass.f64(double %sqr, i32 3)
+  ret i1 %res
+}
+
+define i1 @iszero_f32(float %x) {
+; CHECK-LABEL: iszero_f32:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    fsqrt s0, s0
+; CHECK-NEXT:    fcmp s0, #0.0
+; CHECK-NEXT:    cset w0, eq
+; CHECK-NEXT:    ret
+  %sqr = call nsz ninf float @llvm.sqrt.f32(float %x)
+  %res = tail call i1 @llvm.is.fpclass.f32(float %sqr, i32 96)
+  ret i1 %res
+}
+
+define i1 @isnormal_f32(float %x) {
+; CHECK-LABEL: isnormal_f32:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    fsqrt s0, s0
+; CHECK-NEXT:    fmov w8, s0
+; CHECK-NEXT:    and w8, w8, #0x7fffffff
+; CHECK-NEXT:    sub w8, w8, #2048, lsl #12 // =8388608
+; CHECK-NEXT:    lsr w8, w8, #24
+; CHECK-NEXT:    cmp w8, #127
+; CHECK-NEXT:    cset w0, lo
+; CHECK-NEXT:    ret
+  %sqr = call nsz ninf float @llvm.sqrt.f32(float %x)
+  %res = tail call i1 @llvm.is.fpclass.f32(float %sqr, i32 264)
+  ret i1 %res
+}
+
+define <4 x i1> @isinf_v4f32(<4 x float> %x) {
+; CHECK-LABEL: isinf_v4f32:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    fsqrt v0.4s, v0.4s
+; CHECK-NEXT:    mov z1.s, #0x7f800000
+; CHECK-NEXT:    fabs v0.4s, v0.4s
+; CHECK-NEXT:    fcmeq v0.4s, v0.4s, v1.4s
+; CHECK-NEXT:    xtn v0.4h, v0.4s
+; CHECK-NEXT:    ret
+  %sqr = call nsz ninf <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
+  %res = tail call <4 x i1> @llvm.is.fpclass.v4f32(<4 x float> %sqr, i32 516)
+  ret <4 x i1> %res
+}
diff --git a/llvm/test/CodeGen/RISCV/known-fpclass-splat-vector.ll b/llvm/test/CodeGen/RISCV/known-fpclass-splat-vector.ll
new file mode 100644
index 0000000000000..6b5b151c81559
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/known-fpclass-splat-vector.ll
@@ -0,0 +1,106 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv64 -mattr=+v,+f,+d -target-abi lp64d < %s | FileCheck %s
+
+define i1 @isinf_f32(float %x) {
+; CHECK-LABEL: isinf_f32:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    fsqrt.s fa5, fa0
+; CHECK-NEXT:    fclass.s a0, fa5
+; CHECK-NEXT:    andi a0, a0, 129
+; CHECK-NEXT:    snez a0, a0
+; CHECK-NEXT:    ret
+  %sqr = call nsz ninf float @llvm.sqrt.f32(float %x)
+  %res = tail call i1 @llvm.is.fpclass.f32(float %sqr, i32 516)
+  ret i1 %res
+}
+
+define i1 @isnan_f64(double %x) {
+; CHECK-LABEL: isnan_f64:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    fsqrt.d fa5, fa0
+; CHECK-NEXT:    fclass.d a0, fa5
+; CHECK-NEXT:    andi a0, a0, 768
+; CHECK-NEXT:    snez a0, a0
+; CHECK-NEXT:    ret
+  %sqr = call nsz ninf double @llvm.sqrt.f64(double %x)
+  %res = tail call i1 @llvm.is.fpclass.f64(double %sqr, i32 3)
+  ret i1 %res
+}
+
+define <4 x i1> @isinf_v4f32(<4 x float> %x) {
+; CHECK-LABEL: isinf_v4f32:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    vsetivli zero, 4, e32, m1, ta, ma
+; CHECK-NEXT:    vfsqrt.v v8, v8
+; CHECK-NEXT:    vfclass.v v8, v8
+; CHECK-NEXT:    li a0, 129
+; CHECK-NEXT:    vand.vx v8, v8, a0
+; CHECK-NEXT:    vmsne.vi v0, v8, 0
+; CHECK-NEXT:    ret
+  %sqr = call nsz ninf <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
+  %res = tail call <4 x i1> @llvm.is.fpclass.v4f32(<4 x float> %sqr, i32 516)
+  ret <4 x i1> %res
+}
+
+define <vscale x 4 x i1> @isinf_nxv4f32(<vscale x 4 x float> %x) {
+; CHECK-LABEL: isinf_nxv4f32:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    vsetvli a0, zero, e32, m2, ta, ma
+; CHECK-NEXT:    vfsqrt.v v8, v8
+; CHECK-NEXT:    vfclass.v v8, v8
+; CHECK-NEXT:    li a0, 129
+; CHECK-NEXT:    vand.vx v8, v8, a0
+; CHECK-NEXT:    vmsne.vi v0, v8, 0
+; CHECK-NEXT:    ret
+  %sqr = call nsz ninf <vscale x 4 x float> @llvm.sqrt.nxv4f32(<vscale x 4 x float> %x)
+  %res = tail call <vscale x 4 x i1> @llvm.is.fpclass.nxv4f32(<vscale x 4 x float> %sqr, i32 516)
+  ret <vscale x 4 x i1> %res
+}
+
+; --- SPLAT_VECTOR Tests ---
+; These should fold to 'vmset.m v0' if your SelectionDAG logic is working.
+
+define <vscale x 4 x i1> @test_splat_is_pos_normal() {
+; CHECK-LABEL: test_splat_is_pos_normal:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    lui a0, 260096
+; CHECK-NEXT:    vsetvli a1, zero, e32, m2, ta, ma
+; CHECK-NEXT:    vmv.v.x v8, a0
+; CHECK-NEXT:    vfclass.v v8, v8
+; CHECK-NEXT:    li a0, 32
+; CHECK-NEXT:    vmseq.vx v0, v8, a0
+; CHECK-NEXT:    ret
+  %ins   = insertelement <vscale x 4 x float> poison, float 1.0, i64 0
+  %splat = shufflevector <vscale x 4 x float> %ins, <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer
+  %res   = call <vscale x 4 x i1> @llvm.is.fpclass.nxv4f32(<vscale x 4 x float> %splat, i32 128)
+  ret <vscale x 4 x i1> %res
+}
+
+define <vscale x 4 x i1> @test_splat_is_not_nan(float %x) {
+; CHECK-LABEL: test_splat_is_not_nan:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    lui a0, 260096
+; CHECK-NEXT:    fmv.w.x fa5, a0
+; CHECK-NEXT:    fadd.s fa5, fa0, fa5
+; CHECK-NEXT:    vsetvli a0, zero, e32, m2, ta, ma
+; CHECK-NEXT:    vfmv.v.f v8, fa5
+; CHECK-NEXT:    vfclass.v v8, v8
+; CHECK-NEXT:    li a0, 255
+; CHECK-NEXT:    vand.vx v8, v8, a0
+; CHECK-NEXT:    vmsne.vi v0, v8, 0
+; CHECK-NEXT:    ret
+  %val   = fadd nnan float %x, 1.0
+  %ins   = insertelement <vscale x 4 x float> poison, float %val, i64 0
+  %splat = shufflevector <vscale x 4 x float> %ins, <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer
+  %res   = call <vscale x 4 x i1> @llvm.is.fpclass.nxv4f32(<vscale x 4 x float> %splat, i32 1020)
+  ret <vscale x 4 x i1> %res
+}
+
+declare float @llvm.sqrt.f32(float)
+declare double @llvm.sqrt.f64(double)
+declare <4 x float> @llvm.sqrt.v4f32(<4 x float>)
+declare <vscale x 4 x float> @llvm.sqrt.nxv4f32(<vscale x 4 x float>)
+declare i1 @llvm.is.fpclass.f32(float, i32)
+declare i1 @llvm.is.fpclass.f64(double, i32)
+declare <4 x i1> @llvm.is.fpclass.v4f32(<4 x float>, i32)
+declare <vscale x 4 x i1> @llvm.is.fpclass.nxv4f32(<vscale x 4 x float>, i32)

>From 88bdf00441de93a5a19b307a225c02a06b67ebb7 Mon Sep 17 00:00:00 2001
From: kartikohlan <kartik7ohlan at gmail.com>
Date: Tue, 31 Mar 2026 20:40:21 -0400
Subject: [PATCH 2/2] RISC V test

---
 llvm/test/CodeGen/RISCV/known-fpclass-splat-vector.ll | 2 --
 1 file changed, 2 deletions(-)

diff --git a/llvm/test/CodeGen/RISCV/known-fpclass-splat-vector.ll b/llvm/test/CodeGen/RISCV/known-fpclass-splat-vector.ll
index 6b5b151c81559..002fdd1c2e820 100644
--- a/llvm/test/CodeGen/RISCV/known-fpclass-splat-vector.ll
+++ b/llvm/test/CodeGen/RISCV/known-fpclass-splat-vector.ll
@@ -57,8 +57,6 @@ define <vscale x 4 x i1> @isinf_nxv4f32(<vscale x 4 x float> %x) {
   ret <vscale x 4 x i1> %res
 }
 
-; --- SPLAT_VECTOR Tests ---
-; These should fold to 'vmset.m v0' if your SelectionDAG logic is working.
 
 define <vscale x 4 x i1> @test_splat_is_pos_normal() {
 ; CHECK-LABEL: test_splat_is_pos_normal:



More information about the llvm-commits mailing list