From patchwork Mon Jul 23 11:29:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 947694 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-482054-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="JiCjjW9+"; 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 41Yzm738ynz9s0w for ; Mon, 23 Jul 2018 21:29:25 +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:from :to:subject:date:message-id:content-type:mime-version; q=dns; s= default; b=aSH8JOYNFL+9FgBtNQfOa4fs+B4fhdkykkQTnhNTw7a75bPedmlk3 YE4dP11ZNjD+DyjiR/LyR1b3aRm2914rLQIhETCVE9M7iOsP9tvCg63cJxxcHG+W vJN1Ud/cmLW02mtlORgxincUxVMtie7L47P9l9nAQmz2o+GspN5nX0= 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:from :to:subject:date:message-id:content-type:mime-version; s= default; bh=RksHCDTteEeDlqcSB+A98uE7MBs=; b=JiCjjW9+Itdn2b4YIN/z GNasVG61YmXO+K7oMsDUtjWqEnt4vILwPWEBphWwzfTquTw9WcaZZBLa/u9fF/sR YA37hjTOt2e3xOHAA8SlW971KlkBhgfV0ntDbyYpYV+bTLH+2wgYjU+eaW4Q3xam jEFcvryuA91sd9zTeb58yDU= Received: (qmail 117659 invoked by alias); 23 Jul 2018 11:29:18 -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 117650 invoked by uid 89); 23 Jul 2018 11:29:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=rhs, H*c:HHH X-HELO: EUR02-AM5-obe.outbound.protection.outlook.com Received: from mail-oln040092067076.outbound.protection.outlook.com (HELO EUR02-AM5-obe.outbound.protection.outlook.com) (40.92.67.76) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Jul 2018 11:29:16 +0000 Received: from VE1EUR02FT039.eop-EUR02.prod.protection.outlook.com (10.152.12.55) by VE1EUR02HT246.eop-EUR02.prod.protection.outlook.com (10.152.13.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.995.12; Mon, 23 Jul 2018 11:29:13 +0000 Received: from AM5PR0701MB2657.eurprd07.prod.outlook.com (10.152.12.55) by VE1EUR02FT039.mail.protection.outlook.com (10.152.13.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.995.12 via Frontend Transport; Mon, 23 Jul 2018 11:29:13 +0000 Received: from AM5PR0701MB2657.eurprd07.prod.outlook.com ([fe80::b1fe:1b4f:88c3:5243]) by AM5PR0701MB2657.eurprd07.prod.outlook.com ([fe80::b1fe:1b4f:88c3:5243%9]) with mapi id 15.20.0995.014; Mon, 23 Jul 2018 11:29:13 +0000 From: Bernd Edlinger To: GCC Patches , Richard Biener Subject: [PATCH] Fix folding of volatile values (PR 86617) Date: Mon, 23 Jul 2018 11:29:13 +0000 Message-ID: received-spf: None (protection.outlook.com: hotmail.de does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=bernd.edlinger@hotmail.de; MIME-Version: 1.0 Hi! This fixes PR c/86617, where volatile values are folded incorrectly, because LHS and RHS of PLUS_EXPR and MINUS_EXPR are the same pointer. Bootstrapped and reg-tested on x86_64-pc-linux-gnu. Is it OK for trunk (and active branches, 8.2 in particular)? Thanks Bernd. gcc: 2018-07-23 Bernd Edlinger PR c/86617 * genmatch.c (dt_operand::gen_match_op): Avoid folding volatile values. testsuite: 2018-07-23 Bernd Edlinger PR c/86617 * gcc.dg/pr86617.c: New test. Index: gcc/genmatch.c =================================================================== --- gcc/genmatch.c (revision 262904) +++ gcc/genmatch.c (working copy) @@ -2748,12 +2748,14 @@ dt_operand::gen_match_op (FILE *f, int indent, con char match_opname[20]; match_dop->get_name (match_opname); if (value_match) - fprintf_indent (f, indent, "if (%s == %s || operand_equal_p (%s, %s, 0))\n", - opname, match_opname, opname, match_opname); + fprintf_indent (f, indent, "if ((%s == %s && ! TREE_SIDE_EFFECTS (%s)) " + "|| operand_equal_p (%s, %s, 0))\n", + opname, match_opname, opname, opname, match_opname); else - fprintf_indent (f, indent, "if (%s == %s || (operand_equal_p (%s, %s, 0) " + fprintf_indent (f, indent, "if ((%s == %s && ! TREE_SIDE_EFFECTS (%s)) " + "|| (operand_equal_p (%s, %s, 0) " "&& types_match (%s, %s)))\n", - opname, match_opname, opname, match_opname, + opname, match_opname, opname, opname, match_opname, opname, match_opname); fprintf_indent (f, indent + 2, "{\n"); return 1; Index: gcc/testsuite/gcc.dg/pr86617.c =================================================================== --- gcc/testsuite/gcc.dg/pr86617.c (revision 0) +++ gcc/testsuite/gcc.dg/pr86617.c (working copy) @@ -0,0 +1,11 @@ +/* { dg-options "-Os -fdump-rtl-final" } */ + +volatile unsigned char u8; + +void test (void) +{ + u8 = u8 + u8; + u8 = u8 - u8; +} + +/* { dg-final { scan-rtl-dump-times "mem/v" 6 "final" } } */