Bug 14819 - [tree-ssa] strchr is not folded at tree-level
Summary: [tree-ssa] strchr is not folded at tree-level
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: tree-ssa
: P2 enhancement
Target Milestone: 4.0.0
Assignee: Steven Bosscher
URL:
Keywords: missed-optimization, patch
Depends on:
Blocks:
 
Reported: 2004-04-02 06:00 UTC by Kazu Hirata
Modified: 2004-09-01 06:27 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-04-02 14:10:29


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kazu Hirata 2004-04-02 06:00:22 UTC
Consider:

extern char *strchr (__const char *__s, int __c) __attribute__ ((__pure__));

int
foo (void)
{
  int c = '1';
  return (strchr ("<12ers", c) == 0);
}

Here is the last tree form.

foo ()
{
<bb 0>:
  return strchr ("<12ers", 49) == 0B;

}

This strchr seems to be optimized at expand time.

As you might guess from the above testcase, GCC has a lot of redundant
IS_EXPR_CODE_CLASS(CLASS), where CLASS is a compile-time constant.
Optimizing these strchr away in turn allows us to remove a lot of dead code.

It seems to be a simple extension to call simplify_builtin_strchr() from
tree-ssa-ccp.c.
Comment 1 Andrew Pinski 2004-04-02 06:03:04 UTC
Confirmed.
Comment 2 Kazu Hirata 2004-04-02 06:18:26 UTC
Another possible place for this optimization would be fold_builtin().
Comment 3 Steven Bosscher 2004-04-02 14:10:29 UTC
This should be folded in ccp.  Mind if I make this my weekend project?
Comment 4 Andrew Pinski 2004-05-20 19:44:31 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-05/msg01275.html>.
Comment 5 Andrew Pinski 2004-05-24 01:22:12 UTC
The patch was approved with the modification suggested by RTH.
Comment 6 GCC Commits 2004-05-30 21:05:34 UTC
Subject: Bug 14819

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	kazu@gcc.gnu.org	2004-05-30 21:05:21

Modified files:
	gcc            : ChangeLog builtins.c 

Log message:
	PR tree-optimization/14819
	* builtins.c (fold_builtin_strchr): New.
	(fold_builtin_1): Handle BUILT_IN_STRCHR and BUILT_IN_STRRCHR
	with fold_builtin_strchr().

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3792&r2=2.3793
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/builtins.c.diff?cvsroot=gcc&r1=1.327&r2=1.328

Comment 7 Kazu Hirata 2004-05-30 21:07:42 UTC
Just checked in a patch:

http://gcc.gnu.org/ml/gcc-cvs/2004-05/msg01066.html