From patchwork Mon Apr 16 19:01:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 898884 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476442-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wdxoBmpo"; dkim-atps=neutral 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 40PzBN2D8xz9s0W for ; Tue, 17 Apr 2018 05:35:40 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=j6pP41d5L2qV8dLDZddFKduS9SgLH 0mZXSF7+f4gpmrvcM5ltKZjd5ukTeEQEPfz/CBmTQCpOw2UUvS+K5ClKMyJb20YD LhEoh4fYyXtG528lKe6/QPdD2tmZWIr/I2BFDaBixmnSYHkd9ll0nvrTJqFg5xnM Ezoi4C+ZyoeIrc= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=WWXphct/zi22Wl2BFdiXyDQQrGw=; b=wdx oBmpoY+o5fleBWxeNWGb6XCMcvqwsdhCC1NVe90wXd0csGkw6Eou+DyL0ThJcmZG 27SdXon2LEWfswBL16qNGrOfKsZ0Uq4VzbV2+FEG6udHKRrRRTuPKsHfcO2MkGWm HZwUOSREH7IBQd2oQ9LmR84xiIISxScyeKQuhN1I= Received: (qmail 63152 invoked by alias); 16 Apr 2018 19:35:32 -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 63141 invoked by uid 89); 16 Apr 2018 19:35:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.2 spammy=HTo:U*ebotcazou, promoted X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Apr 2018 19:35:30 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D8ED240201A0 for ; Mon, 16 Apr 2018 19:35:28 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.36.118.110]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E0A22026DFD for ; Mon, 16 Apr 2018 19:35:28 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w3GJ1wa7019021; Mon, 16 Apr 2018 21:01:59 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w3GJ1vXp019020; Mon, 16 Apr 2018 21:01:57 +0200 Date: Mon, 16 Apr 2018 21:01:57 +0200 From: Jakub Jelinek To: Jeff Law , Eric Botcazou Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix gen_lowpart_if_possible (PR middle-end/85414) Message-ID: <20180416190157.GS8577@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! The following testcase FAILs, because cse_local sees (zero_extend:TI (subreg/s/v:DI (reg:TI ...) 0)) inside of REG_EQUAL note, and simplify-rtx.c attempts to optimize it. case ZERO_EXTEND: /* Check for a zero extension of a subreg of a promoted variable, where the promotion is zero-extended, and the target mode is the same as the variable's promotion. */ if (GET_CODE (op) == SUBREG && SUBREG_PROMOTED_VAR_P (op) && SUBREG_PROMOTED_UNSIGNED_P (op) && !paradoxical_subreg_p (mode, GET_MODE (SUBREG_REG (op)))) { temp = rtl_hooks.gen_lowpart_no_emit (mode, op); if (temp) return temp; } This calls gen_lowpart_common which fails, because: /* MODE must occupy no more of the underlying registers than X. */ poly_uint64 regsize = REGMODE_NATURAL_SIZE (innermode); unsigned int mregs, xregs; if (!can_div_away_from_zero_p (msize, regsize, &mregs) || !can_div_away_from_zero_p (xsize, regsize, &xregs) || mregs > xregs) return 0; and so gen_lowpart_if_possible emits (subreg:TI (subreg/s/v:DI (reg:TI ...) 0) 0) which is invalid, unsurprisingly other passes have issues with it and DF in the middle of reload discovers use of an unsaved call saved register that way. The following patch fixes it by never creating a subreg of subreg, other spots avoid it similarly. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Perhaps in GCC9 we might consider relaxing the above gen_lowpart_common mregs/xregs restriction, say if the inner operand is a lowpart subreg of a register with mode having at least xregs regs, allow it; not really sure if it is desirable though. 2018-04-16 Jakub Jelinek PR middle-end/85414 * rtlhooks.c (gen_lowpart_if_possible): Don't call gen_lowpart_SUBREG on a SUBREG. * gcc.dg/pr85414.c: New test. Jakub --- gcc/rtlhooks.c.jj 2018-01-03 10:19:55.338533987 +0100 +++ gcc/rtlhooks.c 2018-04-16 15:16:54.257664102 +0200 @@ -123,9 +123,9 @@ gen_lowpart_if_possible (machine_mode mo return new_rtx; } - else if (mode != GET_MODE (x) && GET_MODE (x) != VOIDmode + else if (mode != GET_MODE (x) && GET_MODE (x) != VOIDmode && !SUBREG_P (x) && validate_subreg (mode, GET_MODE (x), x, - subreg_lowpart_offset (mode, GET_MODE (x)))) + subreg_lowpart_offset (mode, GET_MODE (x)))) return gen_lowpart_SUBREG (mode, x); else return 0; --- gcc/testsuite/gcc.dg/pr85414.c.jj 2018-04-16 15:32:42.119137550 +0200 +++ gcc/testsuite/gcc.dg/pr85414.c 2018-04-16 15:31:39.332103633 +0200 @@ -0,0 +1,10 @@ +/* PR middle-end/85414 */ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-Og -fgcse -Wno-uninitialized" } */ + +int +foo (void) +{ + unsigned __int128 c; + return __builtin_mul_overflow_p (59, -c, (short) 0); +}