From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24162 invoked by alias); 22 Mar 2007 15:12:42 -0000 Received: (qmail 24115 invoked by uid 48); 22 Mar 2007 15:12:27 -0000 Date: Thu, 22 Mar 2007 15:12:00 -0000 Subject: [Bug rtl-optimization/31313] New: consecutive strcmps are not merged X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "tobi at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-03/txt/msg02122.txt.bz2 I just ran into some code which did something like int strcmp(const char *, const char *); int f (const char *c) { return (strcmp (c, "aaa") == 0 || strcmp (c, "aab") == 0); } It would be possible to optimize this into something like (hopefully I get it right) int f (const char *c) { if (strncmp (c, "aa", 2)) return 0; return ((c[2] == 'a' || c[2] == 'b') && !c[3]); } Instead, we scan through the whole string twice, as can be seen in the assembly. Likewise, more complicated combinations of comparisons could be reduced into an optimal matching sequence. Putting this into component rtl-optimization, because the strcmp calls survive all of the tree optimizers unchanged. -- Summary: consecutive strcmps are not merged Product: gcc Version: 4.3.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: tobi at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31313