From 6fc0bc5b0fa7b87960a8b326853643df503d76f7 Mon Sep 17 00:00:00 2001 From: Serge Pavlov Date: Tue, 24 May 2022 18:30:13 +0700 Subject: [PATCH] Fix behavior of is_fp_class on empty class set The second argument to is_fp_class specifies the set of floating-point class to test against. It can be zero, in this case the intrinsic is expected to return zero value. Differential Revision: https://reviews.llvm.org/D112025 --- llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 4 ++- llvm/test/CodeGen/X86/is_fpclass.ll | 31 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 5af1cd8..5cf5aa9 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -7446,7 +7446,9 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op, assert(OperandVT.isFloatingPoint()); // Degenerated cases. - if (Test == 0 || (Test & fcAllFlags) == fcAllFlags) + if (Test == 0) + return DAG.getBoolConstant(false, DL, ResultVT, OperandVT); + if ((Test & fcAllFlags) == fcAllFlags) return DAG.getBoolConstant(true, DL, ResultVT, OperandVT); // PPC double double is a pair of doubles, of which the higher part determines diff --git a/llvm/test/CodeGen/X86/is_fpclass.ll b/llvm/test/CodeGen/X86/is_fpclass.ll index 3929141..6ef6002 100644 --- a/llvm/test/CodeGen/X86/is_fpclass.ll +++ b/llvm/test/CodeGen/X86/is_fpclass.ll @@ -935,6 +935,37 @@ entry: ret <4 x i1> %0 } +define i1 @isnone_f(float %x) { +; CHECK-32-LABEL: isnone_f: +; CHECK-32: # %bb.0: # %entry +; CHECK-32-NEXT: xorl %eax, %eax +; CHECK-32-NEXT: retl +; +; CHECK-64-LABEL: isnone_f: +; CHECK-64: # %bb.0: # %entry +; CHECK-64-NEXT: xorl %eax, %eax +; CHECK-64-NEXT: retq +entry: + %0 = tail call i1 @llvm.is.fpclass.f32(float %x, i32 0) + ret i1 %0 +} + +define i1 @isany_f(float %x) { +; CHECK-32-LABEL: isany_f: +; CHECK-32: # %bb.0: # %entry +; CHECK-32-NEXT: movb $1, %al +; CHECK-32-NEXT: retl +; +; CHECK-64-LABEL: isany_f: +; CHECK-64: # %bb.0: # %entry +; CHECK-64-NEXT: movb $1, %al +; CHECK-64-NEXT: retq +entry: + %0 = tail call i1 @llvm.is.fpclass.f32(float %x, i32 1023) + ret i1 %0 +} + + declare i1 @llvm.is.fpclass.f32(float, i32) declare i1 @llvm.is.fpclass.f64(double, i32) -- 2.7.4