From patchwork Tue Aug 9 21:42:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 73574 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp97676qga; Tue, 9 Aug 2016 14:43:27 -0700 (PDT) X-Received: by 10.98.14.208 with SMTP id 77mr950137pfo.23.1470779005297; Tue, 09 Aug 2016 14:43:25 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id q6si44590622pfb.204.2016.08.09.14.43.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Aug 2016 14:43:25 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-433635-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-433635-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-433635-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=Hi4/zsn2Qn8TcVPK+ lVC7hZBLcLCYwlf5us+5/6jS8DQkEg85XkrUQdEHRo/3CYLe3UyoiC1f1OG3Gv0a ojl8uuTySFrHPHzG4xyJeCuQN28lTZ2jJXaAQ0qsM/dycIv6j0hf3K8Dt/DxJDGq KSXwggq96C9MFMPqD6a8mMqDDQ= 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 :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=YZTO2qU2Tk481+BC3ZlnzVf xlh8=; b=b+aCE3DTdvoOsDjuuWYMd3LcnZqqLgT0mRYEy2gbyS+wm5YcswMfx0h Uo0vFqf3nBw620QnqDUBuMLw+8RljZQeGiT5p/GIH3SGE9qmC+GMGYdB1RL5ud7V 5LVaAnvxsoj3ZPtrqGrvMcqWWYgT/HWFicZMcUm0AQ6k1EQYw8ms= Received: (qmail 14232 invoked by alias); 9 Aug 2016 21:43:12 -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 14212 invoked by uid 89); 9 Aug 2016 21:43:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=2016-08-10, 20160810, Attached X-HELO: mail-pf0-f172.google.com Received: from mail-pf0-f172.google.com (HELO mail-pf0-f172.google.com) (209.85.192.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 09 Aug 2016 21:42:59 +0000 Received: by mail-pf0-f172.google.com with SMTP id x72so8677242pfd.2 for ; Tue, 09 Aug 2016 14:42:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=99vZUenGBk9EpiTsFp7vb6iAZipIakqtsmYd4I06Bio=; b=WBkBI+3O3OOCUzvreQ5pSWxs28Lbj/7KSdZHJs2EjV9T6LzrTz19eWPv6E9PPSOolb +PZ1RaZdLywoMk8fy0N8qvnZ2MFU4BLacovohE8GMLKYF6m4FtLwbU2KY6XUq50fFRBf eWDqLbHY4VHb2SF+FX0v4f5Pb5JZok1THx7lYU+vb9bntqNQxrj3OiZm6h35O5JWEF9F g8b3mczwhihwErfYGLMM1ozodjN8ZiW5iqml6oMwsIUOFAloSSSXuZ2OFpdhQzgjDqVW 5VaVyWtseCPVFXY07izOrN98ghYr4W9D+jEiYHEfv0fCUrLoojHaKhMfSIUf2kwqYwUc 5cWw== X-Gm-Message-State: AEkooutFfRRjcWjUZTrRdfh9OYC25+I8S5zGQZXYJ8z5sRUBXOKCCxJjEzs/+eLWPuKbgs7h X-Received: by 10.98.204.74 with SMTP id a71mr893462pfg.149.1470778977950; Tue, 09 Aug 2016 14:42:57 -0700 (PDT) Received: from [10.1.1.4] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.gmail.com with ESMTPSA id sy7sm41297902pac.42.2016.08.09.14.42.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Aug 2016 14:42:56 -0700 (PDT) Subject: Re: [PR72835] Incorrect arithmetic optimization involving bitfield arguments To: "gcc-patches@gcc.gnu.org" , Richard Biener References: <0a1eaaf8-3ede-cd56-ffb5-40b25f94e46e@linaro.org> From: kugan Message-ID: <98613cff-7c48-1a56-0014-6d87c35a8f26@linaro.org> Date: Wed, 10 Aug 2016 07:42:25 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <0a1eaaf8-3ede-cd56-ffb5-40b25f94e46e@linaro.org> X-IsSubscribed: yes On 09/08/16 23:43, kugan wrote: > Hi, > > The test-case in PR72835 is failing with -O2 and passing with > -fno-tree-reassoc. It also passes with -O2 -fno-tree-vrp. > > diff of .115t.dse2 and .116t.reassoc1 for the c++ testcase is as > follows, which looks OK. > > + unsigned int _16; > + unsigned int _17; > + unsigned int _18; > > : > _1 = s1.m2; > _2 = (unsigned int) _1; > _3 = s1.m3; > _4 = (unsigned int) _3; > - _5 = -_4; > - _6 = _2 * _5; > + _5 = _4; > + _6 = _5 * _2; > var_32.0_7 = var_32; > _8 = (unsigned int) var_32.0_7; > _9 = s1.m1; > _10 = (unsigned int) _9; > - _11 = -_10; > - _12 = _8 * _11; > - c_14 = _6 + _12; > + _11 = _10; > + _12 = _11 * _8; > + _16 = _12 + _6; > + _18 = _16; > + _17 = -_18; > + c_14 = _17; > if (c_14 != 4098873984) > > > However, I noticed that when we re-associate and assign different > operands to the stmts, we are not resetting the flow information to the > LHS. This looks wrong. Attached patch resets it. With this, the > testcases in TH PR is now working. > > > Bootstrap and regression testing for x86_64-linux-gnu is in progress. Is > this OK for trunk if there is no regression. There was no new regression while testing. I also moved the testcase from gcc.dg/torture/pr72835.c to gcc.dg/tree-ssa/pr72835.c. Is this OK for trunk? Thanks, Kugan gcc/testsuite/ChangeLog: 2016-08-10 Kugan Vivekanandarajah PR tree-optimization/72835 * gcc.dg/tree-ssa/pr72835.c: New test. gcc/ChangeLog: 2016-08-10 Kugan Vivekanandarajah PR tree-optimization/72835 * tree-ssa-reassoc.c (rewrite_expr_tree): Reset value_range of LHS when operands are changed. (rewrite_expr_tree_parallel): Likewise. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr72835.c b/gcc/testsuite/gcc.dg/tree-ssa/pr72835.c index e69de29..d7d0a8d 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr72835.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr72835.c @@ -0,0 +1,36 @@ +/* PR tree-optimization/72835 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +struct struct_1 { + unsigned int m1 : 6 ; + unsigned int m2 : 24 ; + unsigned int m3 : 6 ; +}; + +unsigned short var_32 = 0x2d10; + +struct struct_1 s1; + +void init () +{ + s1.m1 = 4; + s1.m2 = 0x7ca4b8; + s1.m3 = 24; +} + +void foo () +{ + unsigned int c = + ((unsigned int) s1.m2) * (-((unsigned int) s1.m3)) + + (var_32) * (-((unsigned int) (s1.m1))); + if (c != 4098873984) + __builtin_abort (); +} + +int main () +{ + init (); + foo (); + return 0; +} diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 7fd7550..b864ed1 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -3945,6 +3945,7 @@ rewrite_expr_tree (gimple *stmt, unsigned int opindex, gimple_assign_set_rhs1 (stmt, oe1->op); gimple_assign_set_rhs2 (stmt, oe2->op); update_stmt (stmt); + reset_flow_sensitive_info (lhs); } if (rhs1 != oe1->op && rhs1 != oe2->op) @@ -4193,9 +4194,11 @@ rewrite_expr_tree_parallel (gassign *stmt, int width, others are recreated. */ if (i == stmt_num - 1) { + tree lhs = gimple_assign_lhs (stmts[i]); gimple_assign_set_rhs1 (stmts[i], op1); gimple_assign_set_rhs2 (stmts[i], op2); update_stmt (stmts[i]); + reset_flow_sensitive_info (lhs); } else {