Skip out on processing __builtin_clz when varying.
authorAldy Hernandez <aldyh@redhat.com>
Wed, 12 May 2021 19:22:15 +0000 (15:22 -0400)
committerAldy Hernandez <aldyh@redhat.com>
Wed, 12 May 2021 20:46:58 +0000 (16:46 -0400)
The previous changes to irange::constant_p return TRUE for
VARYING, since VARYING has numerical end points like any other
constant range.  The problem is that some users of constant_p
depended on constant_p excluding the full domain.  The
range handler for __builtin_clz, that is shared between ranger
and vr_values, is one such user.

This patch excludes varying_p(), to match the original behavior
for clz.

gcc/ChangeLog:

PR c/100521
* gimple-range.cc (range_of_builtin_call): Skip out on
  processing __builtin_clz when varying.

gcc/gimple-range.cc
gcc/testsuite/gcc.dg/pr100521.c [new file with mode: 0644]

index e94bb35..5b288d8 100644 (file)
@@ -737,7 +737,7 @@ range_of_builtin_call (range_query &query, irange &r, gcall *call)
 
       query.range_of_expr (r, arg, call);
       // From clz of minimum we can compute result maximum.
-      if (r.constant_p ())
+      if (r.constant_p () && !r.varying_p ())
        {
          int newmaxi = prec - 1 - wi::floor_log2 (r.lower_bound ());
          // Argument is unsigned, so do nothing if it is [0, ...] range.
diff --git a/gcc/testsuite/gcc.dg/pr100521.c b/gcc/testsuite/gcc.dg/pr100521.c
new file mode 100644 (file)
index 0000000..fd9f0db
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int
+__builtin_clz (int a)
+{
+  return __builtin_clz(a);
+}