From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 37130 invoked by alias); 7 Oct 2016 10:50:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 37103 invoked by uid 89); 7 Oct 2016 10:50:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=terminated, HX-Envelope-From:sk:richard, Hx-languages-length:2324, Ready X-HELO: mail-wm0-f67.google.com Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Oct 2016 10:50:44 +0000 Received: by mail-wm0-f67.google.com with SMTP id i130so2353179wmg.0 for ; Fri, 07 Oct 2016 03:50:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=9GqTHemMVek80pWfOMvOcQ81DJtWD/3n/x1UeI7kFOc=; b=ccjUILLp2lhiioC82WWr/lOdwDb0iRtWsAkBL/HfTAfv03lUNAyrvVZa6tbOgUbfnC i3iIfd+fT0K9JI+qbgO3T7YXa0Jk5QL3aYK7hgBrW0YYLEX1caUHOtXq78bJpSFoV1jY 1iOLCSwsnJG3f2wxhpF403O8e2vyAnCsRvYAvWbQ0DET3H8sMKC3LnevpvcQnxIbRypE jbdp0FpPSJvbANPDHYXWeqQHDfItYbGx5jHHI7eGxIMT83dTySLKEXw7kW1I9RjdMeZ8 liRrGrJtsVpfopDm6ryZHNS2/CcbveM7lPc1T5WqdQvb2IGEpBKumvfI2XQ5gkcxvPyU 3BhA== X-Gm-Message-State: AA6/9RmYU+N/dxob2XJPykGRM7tQbv+YfGRO4c4xCYttiL7BGNyZkw57VTE7lC68Kxqg0Jkep13/F/NAI7VW8w== X-Received: by 10.28.128.86 with SMTP id b83mr30979125wmd.40.1475837442116; Fri, 07 Oct 2016 03:50:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.155.146 with HTTP; Fri, 7 Oct 2016 03:50:41 -0700 (PDT) In-Reply-To: <678ff58e-4aa3-6145-f56b-780bf618338c@suse.cz> References: <678ff58e-4aa3-6145-f56b-780bf618338c@suse.cz> From: Richard Biener Date: Fri, 07 Oct 2016 10:50:00 -0000 Message-ID: Subject: Re: [PATCH 1/3] Fold __builtin_str{n}{case}cmp functions (version 2) To: =?UTF-8?Q?Martin_Li=C5=A1ka?= Cc: GCC Patches Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00467.txt.bz2 On Fri, Oct 7, 2016 at 10:39 AM, Martin Li=C5=A1ka wrote: > I'm resending the patch, where I implemented all builtins mentions in sub= ject > in gimp-fold.c. > > Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. > > Ready to be installed? + case BUILT_IN_STRNCASECMP: + { + r =3D strncmp (p1, p2, length); + if (r =3D=3D 0) + known_result =3D true; length might be -1 here -- I think you need to guard against that (but you = can handle BUILT_IN_STRCASECMP which you miss?). Likewise for the strncmp case. Also do we know whether the c_getstr () result is '\0'-terminated? AFAICS = these constant foldings were not implemented in builtins.c, I see a STRCMP one in fold-const-call.c though. I believe the STRING_CST string is not guarantee= d to be '\0' terminated (STRING_CST comes with explicit length). + tree temp =3D fold_build2_loc (loc, MEM_REF, cst_uchar_node, str1, + off0); + temp =3D gimple_build (&stmts, loc, NOP_EXPR, cst_uchar_node, temp); please don't use gimple_build here, there is nothing to simplify for it. U= sing a NOP_EXPR is also confusing (to match the API...). Just do gimple_build_assign (make_ssa_name (...), ..) like other folders do. + replace_call_with_value (gsi, fold_convert_loc (loc, type, temp)); and you'd want to replace the call with the MEM_REF stmt using gsi_replace_with_seq_vops as you fail to set virtual operands properly above (thus you'll get ICEs when this only matches during GIMPLE opts). + location_t loc =3D gimple_location (stmt); + tree cst_uchar_node =3D build_type_variant (unsigned_char_type_node, 1, = 0); + tree cst_uchar_ptr_node + =3D build_pointer_type_for_mode (cst_uchar_node, ptr_mode, true); + tree off0 =3D build_int_cst (cst_uchar_ptr_node, 0); it would be nice to not do this tree building if nothign is folded. + case BUILT_IN_STRCMP: + return gimple_fold_builtin_string_compare (gsi); + case BUILT_IN_STRCASECMP: + return gimple_fold_builtin_string_compare (gsi); + case BUILT_IN_STRNCMP: + return gimple_fold_builtin_string_compare (gsi); + case BUILT_IN_STRNCASECMP: + return gimple_fold_builtin_string_compare (gsi); please do + case BUILT_IN_STRCMP: + case BUILT_IN_STRCASECMP: ... + return gimple_fold_builtin_string_compare (gsi); Thanks, Richard. > Martin