[Bug tree-optimization/90625] fold strcmp(a, b) == 0 to zero for strings of unequal but non-const lengths

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon May 27 07:51:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90625

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2019-05-27
                 CC|                            |aph at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hmm.  So I guess the strlen pass would need to track relations of string
lengths as it operates down the dominator tree.  For example strstr(a, b) is
known
to return NULL in case strlen(b) > strlen(a) and could be folded to
strcmp if strlen(a) == strlen(b)?  So not only [in]equalities are interesting.

Confirmed.

As separately noted in several places GCC misses infrastructure for
representing and simplifying relations.  I'd build these ontop
of tree-affine so we can represent / simplify relations of affine
expressions so we can handle a + 5 < b.  It would also allow to
handle 2*a + b + 3 < c of course, not sure if useful (well, we already
have ISL as a build requirement so ...).  Extending tree-affine to
specify an optional maximum number of sub-expressions might be useful
in this context.

Consider as other obvious user of such infrastructure the late
uninit pass which needs to combine predicates on conditional
initialization to see whether it's true (always initialized).


More information about the Gcc-bugs mailing list