From patchwork Mon Jul 6 21:33:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1323974 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=qd4abROg; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B0zMV6cDdz9sRN for ; Tue, 7 Jul 2020 07:33:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 953953857C5A; Mon, 6 Jul 2020 21:33:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id EB00E3858D35 for ; Mon, 6 Jul 2020 21:33:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EB00E3858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=roger@nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=sfh6Hi4tBF+BWkYBPqxMYkmSh0voxJODudQR+dATHBU=; b=qd4abROgDPqVhWjVQekAvdoGJC uoNMc5wm7i++Lw4rCezlbYopUzlzehPfmxwWfQxyi2mLcf+CQWFyO4+ovetJe3RyRRJe8A5uRvtdF Y4xtZoSb5QUi8iUHCMel7992DW5pU+aXl6KofzC3XypX3yIURjJA92eiCN+Uaies+yPHKnNF0q0CJ LIDu6EuMFSdy+0U+JF1Fui0yuoP87Asuncxv58HU0uuPaoWBAsGtiymHhIWaBf08AqzBsq6fU2hkV KiG/w/OPqqn5bb5M72eUJtBu/rxVf84cGS42qaIm+hQO1phwBa7KO9LsUW7O3sJbNIY1xvTA41ERK 7mPvOmuw==; Received: from host86-137-89-56.range86-137.btcentralplus.com ([86.137.89.56]:64365 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jsYjn-0000jW-9M for gcc-patches@gcc.gnu.org; Mon, 06 Jul 2020 17:33:19 -0400 From: "Roger Sayle" To: Subject: [PATCH] middle-end: Improve RTL expansion in expand_mul_overflow, Date: Mon, 6 Jul 2020 22:33:17 +0100 Message-ID: <014301d653dd$10c28670$32479350$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdZT3G6Nsi8nP9T8RRG7NkPbg9YjXg== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This patch improves the RTL that the middle-end generates for testing signed overflow following a widening multiplication. During this expansion the middle-end generates a truncation which can get used multiple times. Placing this intermediate value in a pseudo register reduces the amount of code generated on platforms where this truncation requires an explicit instruction. This simple call to force_reg eliminates 368 lines of the -S output from testsuite/c-c++-common/torture/builtin-arith-overflow-1.c on nvptx-none. An example difference is in t120_1smul where the following 7 instruction sequence in which the 1st and 6th instructions perform the same truncation: < cvt.u32.u64 %r31, %r28; <- truncate %r28 < shr.s32 %r30, %r31, 31; < cvt.u32.u64 %r32, %r29; < setp.eq.u32 %r33, %r30, %r32; < selp.u32 %r24, 0, 1, %r33; < cvt.u32.u64 %r25, %r28; <- truncate %r28 < setp.eq.u32 %r34, %r24, 0; is now generated as a 4 instruction sequence without duplication: > cvt.u32.u64 %r30, %r28; > shr.s32 %r31, %r30, 31; > cvt.u32.u64 %r32, %r29; > setp.eq.u32 %r33, %r31, %r32; On x86_64-pc-linux-gnu, where SUBREGs are free, this patch generates exactly the same builtin-arith-overflow-1.s as before. This patch has been tested on both x86_64-pc-linux-gnu with "make bootstrap" and nvptx-none with "make", with no new testsuite regressions on either platform. Ok for mainline? 2020-07-06 Roger Sayle gcc/ChangeLog: * internal-fn.c (expand_mul_overflow): When checking for signed overflow from a widening multiplication, we access the truncated lowpart RES twice, so keep this value in a pseudo register. Thanks in advance, Roger --- Roger Sayle NextMove Software Cambridge, UK diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index 0be2eb4..d1bd6cc 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -1627,6 +1627,9 @@ expand_mul_overflow (location_t loc, tree lhs, tree arg0, tree arg1, profile_probability::very_likely ()); else { + /* RES is used more than once, place it in a pseudo. */ + res = force_reg (mode, res); + rtx signbit = expand_shift (RSHIFT_EXPR, mode, res, prec - 1, NULL_RTX, 0); /* RES is low half of the double width result, HIPART