[Bug tree-optimization/91183] strlen of a strcpy result with a conditional source not folded
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jul 16 18:01:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91183
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Blocks| |83819
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The root cause is the conditional guarding handle_char_store in
tree-ssa-strlen.c:
else if (TREE_CODE (lhs) != SSA_NAME && !TREE_SIDE_EFFECTS (lhs))
{
tree type = TREE_TYPE (lhs);
if (TREE_CODE (type) == ARRAY_TYPE)
type = TREE_TYPE (type);
if (TREE_CODE (type) == INTEGER_TYPE
&& TYPE_MODE (type) == TYPE_MODE (char_type_node)
&& TYPE_PRECISION (type) == TYPE_PRECISION (char_type_node))
{
if (! handle_char_store (gsi))
return false;
}
}
}
which prevents the function from being called on the MEM_REF assignment:
MEM <unsigned int> [(char * {ref-all})&a] = _4;
This case also came up in a recent discussion here:
https://gcc.gnu.org/ml/gcc-patches/2019-06/msg01790.html
As noted there, the function could be enhanced to handle these sorts of
expressions and the conditional relaxed. Incidentally, some existing tests for
the strlen optimization already assume that this works. They just happen to be
written in a way where this particular issue doesn't come up. An example of
one such test is gcc.dg/strlenopt-19.c.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83819
[Bug 83819] [meta-bug] missing strlen optimizations
More information about the Gcc-bugs
mailing list