From patchwork Fri Jul 14 14:16:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 788552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x8F9H050Sz9s72 for ; Sat, 15 Jul 2017 00:16:18 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="GXH4RziI"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=B1HzaZkOoxKd+Z2OGSt645Kd+HVrDqNZC04RxwkRQc8zhAMQsC y+g2T6IhcafRgR9XqtOVKiRAjybgarxLLHz3Mg56i/FhvIqWbXQZE4vU7Bz6z7Bz Mu5RURfQGRyDOspCyu9ZhTpaZP1iwHRWf6M+FPMBjyhz1mEO5LJ/XjykE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=zWNjPPSmKbfccZYynz/PPTsvBJ4=; b=GXH4RziITNUi2lI72GhL lm8HyHD/sFijiccSJ8iJr18OmroaHL/rVUamE2x0h3UlQpo9l2ryB7leNXU2ncYV 8NICAuzKAJo5gZULsI/NCd6hYdIimu0VOG0dtFUS1xby28oILsbQsi54E6Jap+yy q2uLkjIfuZRUz98CsEduzR4= Received: (qmail 120385 invoked by alias); 14 Jul 2017 14:16:09 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 120363 invoked by uid 89); 14 Jul 2017 14:16:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-12.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=Hx-languages-length:3301 X-HELO: mo4-p00-ob.smtp.rzone.de Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.161) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Jul 2017 14:16:05 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT3ol15ykJcYwR/bcHRirORRW3yMcVao= X-RZG-CLASS-ID: mo00 Received: from [192.168.0.123] (mail.hightec-rt.com [213.135.1.215]) by smtp.strato.de (RZmta 41.1 DYNA|AUTH) with ESMTPSA id V00fect6EEG2fEs (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Fri, 14 Jul 2017 16:16:02 +0200 (CEST) To: gcc-patches Cc: Denis Chertykov From: Georg-Johann Lay Subject: [patch,avr] Fix PR80929, work around middle-end PR81444 Message-ID: <8535f632-7864-b046-f9bb-9f99546c9007@gjlay.de> Date: Fri, 14 Jul 2017 16:16:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi, this patch restores some of the divmod handling. It addresses two issues: 1) rtx_costs might be called with code = LSHIFTRT for a mul_highpart. This is the case when outer_code = TRUNCATE. This patch uses a new function to compute the costs for that case (also used for code = TRUNCATE). 2) Due to PR81444, the middle-end is calling the cost functions with strange RTXes like (truncate:HI (lshiftrt:PSI (mult:PSI (zero_extend:PSI (reg:TI 42)) (zero_extend:PSI (reg:TI 42))) (const_int 16 [0x10]))) i.e. completely messed up modes. The correct RTX would be (truncate:HI (lshiftrt:SI (mult:SI (zero_extend:SI (reg:HI 42)) (zero_extend:SI (reg:HI 42))) (const_int 16 [0x10]))) The is worked around by also considering PSImode in the cost computation. FYI, I am currently also just reg-testing a fix for PR81444, cf. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81444#c1 Ok to apply the patch below (trunk and v7)? Johann PR 80929 * config/avr/avr.c (avr_mul_highpart_cost): New static function. (avr_rtx_costs_1) [TRUNCATE]: Use it to compute mul_highpart cost. [LSHIFTRT, outer_code = TRUNCATE]: Same. Index: config/avr/avr.c =================================================================== --- config/avr/avr.c (revision 250156) +++ config/avr/avr.c (working copy) @@ -10709,6 +10709,33 @@ avr_memory_move_cost (machine_mode mode, } +/* Cost for mul highpart. X is a LSHIFTRT, i.e. the outer TRUNCATE is + already stripped off. */ + +static int +avr_mul_highpart_cost (rtx x, int) +{ + if (AVR_HAVE_MUL + && LSHIFTRT == GET_CODE (x) + && MULT == GET_CODE (XEXP (x, 0)) + && CONST_INT_P (XEXP (x, 1))) + { + // This is the wider mode. + machine_mode mode = GET_MODE (x); + + // The middle-end might still have PR81444, i.e. it is calling the cost + // functions with strange modes. Fix this now by also considering + // PSImode (should actually be SImode instead). + if (HImode == mode || PSImode == mode || SImode == mode) + { + return COSTS_N_INSNS (2); + } + } + + return 10000; +} + + /* Mutually recursive subroutine of avr_rtx_cost for calculating the cost of an RTX operand given its context. X is the rtx of the operand, MODE is its mode, and OUTER is the rtx_code of this @@ -10748,7 +10775,7 @@ avr_operand_rtx_cost (rtx x, machine_mod In either case, *TOTAL contains the cost result. */ static bool -avr_rtx_costs_1 (rtx x, machine_mode mode, int outer_code ATTRIBUTE_UNUSED, +avr_rtx_costs_1 (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UNUSED, int *total, bool speed) { enum rtx_code code = GET_CODE (x); @@ -11402,6 +11429,12 @@ avr_rtx_costs_1 (rtx x, machine_mode mod return true; case LSHIFTRT: + if (outer_code == TRUNCATE) + { + *total = avr_mul_highpart_cost (x, speed); + return true; + } + switch (mode) { case QImode: @@ -11579,16 +11612,10 @@ avr_rtx_costs_1 (rtx x, machine_mode mod return true; case TRUNCATE: - if (AVR_HAVE_MUL - && LSHIFTRT == GET_CODE (XEXP (x, 0)) - && MULT == GET_CODE (XEXP (XEXP (x, 0), 0)) - && CONST_INT_P (XEXP (XEXP (x, 0), 1))) + if (LSHIFTRT == GET_CODE (XEXP (x, 0))) { - if (QImode == mode || HImode == mode) - { - *total = COSTS_N_INSNS (2); - return true; - } + *total = avr_mul_highpart_cost (XEXP (x, 0), speed); + return true; } break;