]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add op1_range for __builtin_signbit.
authorAldy Hernandez <aldyh@redhat.com>
Wed, 5 Oct 2022 18:23:15 +0000 (20:23 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Mon, 10 Oct 2022 09:39:42 +0000 (11:39 +0200)
This is the op1_range range-op entry for __builtin_signbit.  It allows
us to wind back through a call to signbit.

For example, on the true side of if (__builtin_signbit(x_5) != 0) we
can crop down the range of x_5 to:

[frange] float [-Inf, -0.0 (-0x0.0p+0)] -NAN

Similarly on the false side, we can crop to:

[frange] float [0.0 (0x0.0p+0), +Inf] +NAN

Tested on x86-64 Linux.

gcc/ChangeLog:

* gimple-range-op.cc: Add op1_range entry for __builtin_signbit.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/vrp-float-signbit-3.c: New test.

gcc/gimple-range-op.cc
gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-3.c [new file with mode: 0644]

index 42ebc7d6ce5690880d344aefc630db70a27320b0..abc33e7af0ce879f0d9eeb8641f19a831ead0f2e 100644 (file)
@@ -306,6 +306,7 @@ class cfn_signbit : public range_operator_float
 {
 public:
   using range_operator_float::fold_range;
+  using range_operator_float::op1_range;
   virtual bool fold_range (irange &r, tree type, const frange &lh,
                           const irange &, relation_kind) const
   {
@@ -320,6 +321,25 @@ public:
       }
    return false;
   }
+  virtual bool op1_range (frange &r, tree type, const irange &lhs,
+                         const frange &, relation_kind) const override
+  {
+    if (lhs.zero_p ())
+      {
+       r.set (type, dconst0, frange_val_max (type));
+       r.update_nan (false);
+       return true;
+      }
+    if (!lhs.contains_p (build_zero_cst (lhs.type ())))
+      {
+       REAL_VALUE_TYPE dconstm0 = dconst0;
+       dconstm0.sign = 1;
+       r.set (type, frange_val_min (type), dconstm0);
+       r.update_nan (true);
+       return true;
+      }
+    return false;
+  }
 } op_cfn_signbit;
 
 // Implement range operator for CFN_BUILT_IN_TOUPPER and CFN_BUILT_IN_TOLOWER.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-3.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-3.c
new file mode 100644 (file)
index 0000000..182a33f
--- /dev/null
@@ -0,0 +1,15 @@
+// { dg-do compile }
+// { dg-options "-O2 -ffinite-math-only -fdump-tree-evrp" }
+
+void link_error();
+
+void foo(float x)
+{
+  if (__builtin_signbit (x))
+    {
+      if (x > 0.0)
+       link_error();
+    }
+}
+
+// { dg-final { scan-tree-dump-not "link_error" "evrp" } }