Fix behavior of is_fp_class on empty class set
authorSerge Pavlov <sepavloff@gmail.com>
Tue, 24 May 2022 11:30:13 +0000 (18:30 +0700)
committerSerge Pavlov <sepavloff@gmail.com>
Tue, 24 May 2022 14:50:18 +0000 (21:50 +0700)
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
llvm/test/CodeGen/X86/is_fpclass.ll

index 5af1cd8..5cf5aa9 100644 (file)
@@ -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
index 3929141..6ef6002 100644 (file)
@@ -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)