On 10/19/21 12:28, Jakub Jelinek wrote:
On Tue, Oct 19, 2021 at 09:47:45AM +0530, Siddhesh Poyarekar wrote:
Compute the unknown size value as a function of the min/max bit of
object_size_type.  This transforms into a neat little branchless
sequence on x86_64:

        movl    %edi, %eax
        sarl    %eax
        xorl    $1, %eax
        negl    %eax
        cltq

which should be faster than loading the value from memory.  A quick
unscientific test using

`time make check-gcc RUNTESTFLAGS="dg.exp=builtin*"`

But if you use some other higher bit of object_size_type for the mode
(normal vs. dynamic) you'd need to mask it away, so it will become longer.
Anyway, I guess that part is ok.

Yes, my WIP patchset has:

((unsigned HOST_WIDE_INT) -(((object_size_type & MIN_BIT) >> 1) ^ 1));

which results in:

xorl    %eax, %eax
andl    $2, %edi
sete    %al
negq    %rax

-/* Compute object_sizes for PTR, defined to an unknown value.  */
-
-static void
-unknown_object_size (struct object_size_info *osi, tree ptr)
-{
-  int object_size_type = osi->object_size_type;
-  unsigned int varno = SSA_NAME_VERSION (ptr);
-  unsigned HOST_WIDE_INT bytes;
-
-  gcc_assert (object_sizes[object_size_type][varno]
-             != unknown[object_size_type]);
-  gcc_assert (osi->pass == 0);
-
-  bytes = unknown[object_size_type];
-
-  if ((object_size_type & 2) == 0)
-    {
-      if (object_sizes[object_size_type][varno] < bytes)
-       object_sizes[object_size_type][varno] = bytes;
-    }
-  else
-    {
-      if (object_sizes[object_size_type][varno] > bytes)
-       object_sizes[object_size_type][varno] = bytes;
-    }
-}

But I don't think removing this function is desirable.
Can it be greatly simplified?  Yes, certainly.
The assert verifies it is not unknown before, and then for mode 0 or 1
uses maximum which will always be unknown and for mode 2 or 3
minimum which will always be unknown as well.
But I'd keep the asserts in there.  So it can become
   int object_size_type = osi->object_size_type;
   unsigned int varno = SSA_NAME_VERSION (ptr);
   unsigned HOST_WIDE_INT bytes = unknown (object_size_type);

   gcc_checking_assert (object_sizes[object_size_type][varno] != bytes);
   gcc_checking_assert (osi->pass == 0);
   object_sizes[object_size_type][varno] = bytes;

OK, I'll send an updated patch.

Thanks,
Siddhesh

Reply via email to