From patchwork Mon May 14 12:48:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 912909 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-477631-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="cSYng194"; 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 40l0qw3qKCz9ry1 for ; Mon, 14 May 2018 22:48:43 +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=HMSU3RP+S0sYkLE2fEd4gWran2Cyx 7H5ArTsbI2J96BqKLoutd7+VBSxEajdZG6v1TxrdkOTBaqAcH8Ey0hBDEN1pfsY1 +7D+sUL2lVoJWHPYHQjIXHW7wFSUZbkFsTSuC5GwLzG20X4BbEac/pff8LeC6gDi b0KVCqXklwbCfc= 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=WTO14+tGcd6NPWKGVm8gLjkQ0V0=; b=cSY ng194BJX7Q+KuNURkgvXrrsR0VD2WMFfVvEld//x2OC9WyLhOllgtXanCGZuRPfT 93h8MQehW6EPh4dcozKc0Qez3i1bsdnqOvC6avnxCJe+ZJYKGzDdvGjzdPMA4I7V EWa0fUXqcVM3Zm7nRIzi4PKBc9voYXSf9hziCyVM= Received: (qmail 75716 invoked by alias); 14 May 2018 12:48:35 -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 75663 invoked by uid 89); 14 May 2018 12:48: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, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=*l, swi 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, 14 May 2018 12:48:29 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 152BCEAEBB; Mon, 14 May 2018 12:48:28 +0000 (UTC) Received: from laptop.zalov.cz (ovpn-116-218.ams2.redhat.com [10.36.116.218]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A734AFD5D; Mon, 14 May 2018 12:48:25 +0000 (UTC) Received: from laptop.zalov.cz (localhost [127.0.0.1]) by laptop.zalov.cz (8.15.2/8.15.2) with ESMTP id w4ECmLCH002669; Mon, 14 May 2018 14:48:21 +0200 Received: (from jakub@localhost) by laptop.zalov.cz (8.15.2/8.15.2/Submit) id w4ECmIQJ002668; Mon, 14 May 2018 14:48:18 +0200 Date: Mon, 14 May 2018 14:48:17 +0200 From: Jakub Jelinek To: Uros Bizjak , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Disallow minus in mem {+,-,&,|,^}= x; mem != 0 peepholes (PR target/85756) Message-ID: <20180514124817.GF13963@laptop.zalov.cz> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.1 (2016-04-27) X-IsSubscribed: yes Hi! The last peephole I've recently added is as the testcase shows fundamentally incompatible with non-commutative operations, because we need to swap the operands. The pattern right before this one already is: (define_peephole2 [(parallel [(set (match_operand:SWI 0 "register_operand") (match_operator:SWI 2 "plusminuslogic_operator" [(match_dup 0) (match_operand:SWI 1 "memory_operand")])) (clobber (reg:CC FLAGS_REG))]) (set (match_dup 1) (match_dup 0)) (set (reg FLAGS_REG) (compare (match_dup 0) (const_int 0)))] "(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ()) && GET_CODE (operands[2]) != MINUS ^^^^^^^^ disallow non-commutative plusminuslogic_operator && peep2_reg_dead_p (3, operands[0]) && !reg_overlap_mentioned_p (operands[0], operands[1]) && ix86_match_ccmode (peep2_next_insn (2), GET_CODE (operands[2]) == PLUS ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no need to check for MINUS here ? CCGOCmode : CCNOmode)" [(parallel [(set (match_dup 3) (match_dup 5)) (set (match_dup 1) (match_dup 4))])] { operands[3] = SET_DEST (PATTERN (peep2_next_insn (2))); operands[4] = gen_rtx_fmt_ee (GET_CODE (operands[2]), GET_MODE (operands[2]), copy_rtx (operands[1]), operands[0]); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ and here is where it swaps the operands, ^^^^^^^^^^^^^^ the memory originally in the last input is here as the first input operands[5] = gen_rtx_COMPARE (GET_MODE (operands[3]), copy_rtx (operands[4]), const0_rtx); }) The following patch handles the cmpelim peephole the same. Ok for trunk? Unfortunately, I'm travelling and can't test it right now, Marek, do you think you could bootstrap/regtest it for me? Thanks. 2018-05-14 Jakub Jelinek PR target/85756 * config/i386/i386.md: Disallow MINUS in last peephole for mem {+,-,&,|,^}= x; mem != 0 after cmpelim optimization. * gcc.c-torture/execute/pr85756.c: New test. Jakub --- gcc/config/i386/i386.md.jj 2018-05-11 18:44:32.000000000 +0200 +++ gcc/config/i386/i386.md 2018-05-14 13:50:28.100482520 +0200 @@ -19397,11 +19397,11 @@ (set (match_dup 0) (match_dup 2))]) (set (match_dup 1) (match_dup 0))] "(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ()) + && GET_CODE (operands[2]) != MINUS && peep2_reg_dead_p (2, operands[0]) && !reg_overlap_mentioned_p (operands[0], operands[1]) && ix86_match_ccmode (peep2_next_insn (0), - (GET_CODE (operands[2]) == PLUS - || GET_CODE (operands[2]) == MINUS) + GET_CODE (operands[2]) == PLUS ? CCGOCmode : CCNOmode)" [(parallel [(set (match_dup 3) (match_dup 5)) (set (match_dup 1) (match_dup 4))])] --- gcc/testsuite/gcc.c-torture/execute/pr85756.c.jj 2018-05-14 13:50:44.384307289 +0200 +++ gcc/testsuite/gcc.c-torture/execute/pr85756.c 2018-05-14 13:48:17.000000000 +0200 @@ -0,0 +1,50 @@ +/* PR target/85756 */ + +#if __CHAR_BIT__ == 8 && __SIZEOF_SHORT__ == 2 && __SIZEOF_INT__ == 4 +int a, c, *e, f, h = 10; +short b; +unsigned int p; + +__attribute__((noipa)) void +bar (int a) +{ + asm volatile ("" : : "r" (a) : "memory"); +} + +void +foo () +{ + unsigned j = 1, m = 430523; + int k, n = 1, *l = &h; +lab: + p = m; + m = -((~65535U | j) - n); + f = b << ~(n - 8); + n = (m || b) ^ f; + j = p; + if (p < m) + *l = k < 3; + if (!n) + l = &k; + if (c) + { + bar (a); + goto lab; + } + if (!*l) + *e = 1; +} + +int +main () +{ + foo (); + return 0; +} +#else +int +main () +{ + return 0; +} +#endif