From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 98891 invoked by alias); 1 Aug 2016 07:35:02 -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 98852 invoked by uid 89); 1 Aug 2016 07:35:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=build_int_cst, U*pinskia, Hx-languages-length:1840, sk:pinskia X-HELO: mail-lf0-f46.google.com Received: from mail-lf0-f46.google.com (HELO mail-lf0-f46.google.com) (209.85.215.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 01 Aug 2016 07:34:50 +0000 Received: by mail-lf0-f46.google.com with SMTP id b199so109362457lfe.0 for ; Mon, 01 Aug 2016 00:34:50 -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; bh=+B2NVRlZff71yt7ABpb7J+5RqdmvO38O98v3SDY4olk=; b=cpLIWIvYHAS3PokH7LpoHRdptoj8Q+uPCpDTlOIxes1ED8Y4GruPMt4jH9be3XNgDu k0F4rtsrclJVj0exSfTz4e0zBJ/vzlO32GdgMA97bGzS3t9VgGVk37S5bMNYShDVEBVc BTyo/AmfoEYYO2FZr1XCdGYKnj0D3QbTnI6hUaLgQX73Q9iHWrqtGSamdZNwrO7FaCDS Fs86+OtUFRcE5MSeBv0FYvjc5r0QAY49Y+CcIZo8cRAWr+czLvUsjbkF5hh4qpjsfvPo tkD8zvsp6L9khXckgrjDb/Uxo39WpeER6NE2zNdHa/EjnYb1M6XZvbB2KtznYSlds5Ek hxHw== X-Gm-Message-State: AEkooutwVDCGxDc9oquOId6NYWajrIyxVpcsNfCZvBDjwC6x2ADQe/9VA0BKjAAiNowVrs8KJZmZT7vdhLPY9g== X-Received: by 10.25.150.141 with SMTP id y135mr15921503lfd.66.1470036887089; Mon, 01 Aug 2016 00:34:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.42.4 with HTTP; Mon, 1 Aug 2016 00:34:46 -0700 (PDT) In-Reply-To: References: From: Andrew Pinski Date: Mon, 01 Aug 2016 07:35:00 -0000 Message-ID: Subject: Re: fold strlen (s) eq/ne 0 to *s eq/ne 0 on GIMPLE To: Prathamesh Kulkarni Cc: Richard Biener , gcc Patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-08/txt/msg00013.txt.bz2 On Mon, Aug 1, 2016 at 12:22 AM, Andrew Pinski wrote: > On Mon, Aug 1, 2016 at 12:15 AM, Prathamesh Kulkarni > wrote: >> Hi Richard, >> The attached patch tries to fold strlen (s) eq/ne 0 to *s eq/ne 0 on GIMPLE. >> I am not sure where was the ideal place to put this transform in and ended up >> adding it to strlen_optimize_stmt(). >> Does that look OK ? > > I suspect it might be better in match.pd. The main reason is it is already in fold-const.c: /* Optimize comparisons of strlen vs zero to a compare of the first character of the string vs zero. To wit, strlen(ptr) == 0 => *ptr == 0 strlen(ptr) != 0 => *ptr != 0 Other cases should reduce to one of these two (or a constant) due to the return value of strlen being unsigned. */ if (TREE_CODE (arg0) == CALL_EXPR && integer_zerop (arg1)) { tree fndecl = get_callee_fndecl (arg0); if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_STRLEN && call_expr_nargs (arg0) == 1 && TREE_CODE (TREE_TYPE (CALL_EXPR_ARG (arg0, 0))) == POINTER_TYPE) { tree iref = build_fold_indirect_ref_loc (loc, CALL_EXPR_ARG (arg0, 0)); return fold_build2_loc (loc, code, type, iref, build_int_cst (TREE_TYPE (iref), 0)); } } So you are basically moving that to match.pd instead of adding extra code. Thanks, Andrew Pinski > >> >> I needed to add TODO_update_ssa to strlen pass, otherwise we hit the >> following assert in execute_todo(): >> if (flag_checking >> && cfun >> && need_ssa_update_p (cfun)) >> gcc_assert (flags & TODO_update_ssa_any); > > Also you only need to update the virtual SSAs rather than a full SSA update. > > Thanks, > Andrew > >> >> Bootstrap+test in progress on x86_64-unknown-linux-gnu. >> >> Thanks, >> Prathamesh