From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by sourceware.org (Postfix) with ESMTPS id 6467A38485AC for ; Thu, 19 May 2022 12:34:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6467A38485AC Received: by mail-qk1-x72c.google.com with SMTP id x65so311365qke.2 for ; Thu, 19 May 2022 05:34:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BMwc6z36sa/Ek2eKM0UuJN0Y6T/CCfIK+f3Igb3eSjI=; b=ZiW9ATlie/Bx2pA9hu9QBivEwPdGbIfn9bHVvcgDLkIPSUl1QIhZyPEAHpcAfTBG6U /i7mZrkK0McOfZAgUcYtF4LdGFnPrwZ6Q/MA8XvLkheRlXhNQR9gmc0p6TE4jrpX8VWq Dkl4Ys6zYt0WKVqFA4n3H6IMGj8hAch6C94Fojs45xrbxBujnrV6D6JzVe+9aEXveUqK jdeQCcdZNjYK4SjyziHD+uym9G+Vn2A5YUsBNmy5++pP2chVoXkf4GXUfTWMXkyXlEWI nnv5aaRAspXkl/bougTpzH+ZuAawMlTNNSmiyf/VJs9WVdiwHlHYl4pKQBEHjEzjLsnp AMBg== X-Gm-Message-State: AOAM532HCKzahAUhK0KgBrEOC7+8egn6SfZp4JezB5saTiV8UiJdpjvr 7oHVSs/MzkUqXYuULszdalSuOz2DhH3smFM2yGYiUYnkqQ8= X-Google-Smtp-Source: ABdhPJxly1Xo56sWkpm8OdMeIxEQ758QV7NYBtiQLYq/vFtqy1VDDeEyno8OcHH1Y6mj/SoEdITsok6Uoe8kZom0gFQ= X-Received: by 2002:a05:620a:2808:b0:67d:1561:f4f2 with SMTP id f8-20020a05620a280800b0067d1561f4f2mr2700598qkp.581.1652963670688; Thu, 19 May 2022 05:34:30 -0700 (PDT) MIME-Version: 1.0 References: <061801d86ad8$13976a00$3ac63e00$@nextmovesoftware.com> In-Reply-To: <061801d86ad8$13976a00$3ac63e00$@nextmovesoftware.com> From: Richard Biener Date: Thu, 19 May 2022 14:34:18 +0200 Message-ID: Subject: Re: [PATCH take #2] PR middle-end/98865: Expand X*Y as X&-Y when Y is [0.1]. To: Roger Sayle Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 May 2022 12:34:34 -0000 On Wed, May 18, 2022 at 6:55 PM Roger Sayle wrote: > > > The patch is a revised solution for PR middle-end/98865 incorporating > the feedback/suggestions from Richard Biener's review here: > https://gcc.gnu.org/pipermail/gcc-patches/2022-May/593928.html > Most significantly, this patch now performs the transformation/optimization > during RTL expansion, where the target's rtx_costs can be used to determine > whether the original multiplication (that may be possibly be implemented by > a shift or lea) is cheaper than a negation and a bit-wise and. > > Previously the expression (x>>63)*y would be compiled with -O2 as > shrq $63, %rdi > movq %rdi, %rax > imulq %rsi, %rax > > but with this patch now produces: > sarq $63, %rdi > movq %rdi, %rax > andq %rsi, %rax > > Likewise the expression (x>>63)*135 [that appears in a hot-spot of the > Botan AES-128 benchmark] was previously: > > shrq $63, %rdi > leaq (%rdi,%rdi,8), %rdx > movq %rdx, %rax > salq $4, %rax > subq %rdx, %rax > > now becomes: > movq %rdi, %rax > sarq $63, %rax > andl $135, %eax > > > This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and > make -k check, both with and without --target_board=unix{-m32}, with no > new failures. Many thanks to Uros for the speedy review and approval of > my x86_rtx_costs patch that enables this transformation on -m32 using the > correct cost of DImode multiplication. Ok for mainline? Looks good to me Thanks, Richard. > 2022-05-18 Roger Sayle > > gcc/ChangeLog > PR middle-end/98865 > * expr.cc (expand_expr_real_2) [MULT_EXPR]: Expand X*Y as X&Y > when both X and Y are [0, 1], X*Y as X&-Y when Y is [0,1] and > likewise X*Y as -X&Y when X is [0,1] using tree_nonzero_bits. > > gcc/testsuite/ChangeLog > PR middle-end/98865 > * gcc.target/i386/pr98865.c: New test case. > > > Thanks in advance, > Roger > -- >