[PATCH] fix and improve strlen conditional handling of merged stores (PR 91183, 91294, 91315)

Martin Sebor msebor@gmail.com
Wed Aug 14 16:51:00 GMT 2019


>>> Do you want me to post another revision with
>>> the gimple_assign_single_p test removed?
>> I think remove that hunk, bootstrap, test, commit and post for archival
>> purposes.  I do not think another round of review is necessary.
> 
> Done in r274486 (also attached).

I should add that the early store merging on loosely aligned
targets makes the strlen tests prone to failures on strictly
aligned targets (or even ILP32 targets).  The handle_store
function can now deal with all sorts of MEM_REF assignments
that result from the store merging, but because
the handle_builtin_memcpy function lacks the same support,
the tests that expect the assignments to be folded fail when
they are not merged.  For example, the strlen call below is
folded on i386:

   const char a4[32] = "0123";
   const char b4[32] = "3210";

   void f (int i)
   {
     char a[32];
     memcpy (a, i ? a4 + 1 : b4, 8);   // copy just 8 bytes
     if (strlen (a) < 3)
       abort ();
   }

but the equivalent call below is not:

   void g (int i)
   {
     char a[32];
     memcpy (a, i ? a4 + 1 : b4, 16);   // copy 16 bytes
     if (strlen (a) < 3)
       abort ();
   }

This pattern may not be very common in the wild but having
the pass behave consistently without these target dependencies
would be helpful in avoiding these test failures.  I will try
to remember to extend the same enhancement as in handle_store
to handle_builtin_memcpy (ideally by factoring the code out
of handle_store into a helper and letting both functions call
it to do the folding).

Martin



More information about the Gcc-patches mailing list