From patchwork Tue Aug 9 13:43:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 73550 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp494142qga; Tue, 9 Aug 2016 06:44:03 -0700 (PDT) X-Received: by 10.66.249.201 with SMTP id yw9mr157157587pac.130.1470750243756; Tue, 09 Aug 2016 06:44:03 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id w8si42824069paj.25.2016.08.09.06.44.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Aug 2016 06:44:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-433583-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-433583-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-433583-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:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=eZ56vfD/mXttqRFaOGmEBCdamoPmLudnsN3vVTZE/6ksWj8ylWxJR CRjpc1xt2FJwSSbZABcvmlLwxOaPIb5GT8sNcKuBqJJ/jROjJc87Cx7HsMCNBMF9 IF4UTVkJKp5GivRrPSx3s9/IqDZfW/YTD/ifFg8wDcRtcJHsjORfRc= 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 :subject:to:message-id:date:mime-version:content-type; s= default; bh=Q6otjPiNQdu051FeABcTEUCDdgA=; b=G0+5cpDatXraqxdIXUR9 7Ww5C1CYefhP4279WQgaoUqG2Ql+OYpvRtgrMCrwX/gRD+Xr3nS0cwpka5oVk7+h k+GnU2ZA2Hzbwnve0fNxyiAgZI//zM2uwCLKdsobqcvUqDgUjnjvUKZEa88ZFVlB mWOo6IZGXvy7djSCFWhEl7U= Received: (qmail 42897 invoked by alias); 9 Aug 2016 13:43:48 -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 39258 invoked by uid 89); 9 Aug 2016 13:43:47 -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=H*r:sk:74.2016, Attached X-HELO: mail-pf0-f180.google.com Received: from mail-pf0-f180.google.com (HELO mail-pf0-f180.google.com) (209.85.192.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 09 Aug 2016 13:43:37 +0000 Received: by mail-pf0-f180.google.com with SMTP id p64so5351337pfb.1 for ; Tue, 09 Aug 2016 06:43:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version; bh=sS3yrG3TD4LmiENdO1RaQioqJYf+MJfK9awH+6fjLcY=; b=Bp+cXcf3gdm6GnREJ0SYzz8pLkJvgSqbsdJwqnZyl1FsVxhErANxfN95QsaN97r0dd muwTx3Un7dc1OlqUI+ay5J2JAvIU2vy6cPimPxiiC12CP/yAgOYvZa5SDRG5Pqu37re6 D+Of9R4RzpYjwpTf/m6e8GdHNiTeqgdXynvby/JaK3JNKd+8QJVCWiblAH5KTA+PLOwr UzoPl/2Ms0e4FeFuvi7sTjAmDytOyNNJ8+/TKVA8cy4HJ/PrFdi3UuVPn/G3yd+oQtHB ZpgeR5ANp+oM9wDpnwBMGU5HIUC4Xd7OcoLaeVeqhIW0fU0aV3vJd7Mc1dRwY1EX4E6/ aluQ== X-Gm-Message-State: AEkoouvMAY9s4Zd1N6vT0K4mX4lETdf0mXiRR04JuvlgPfWgF3bHdgYALu7JIVF8N1o231F/ X-Received: by 10.98.80.29 with SMTP id e29mr172435603pfb.76.1470750215298; Tue, 09 Aug 2016 06:43:35 -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 9sm56255305pfo.74.2016.08.09.06.43.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Aug 2016 06:43:34 -0700 (PDT) From: kugan Subject: [PR72835] Incorrect arithmetic optimization involving bitfield arguments To: "gcc-patches@gcc.gnu.org" , Richard Biener Message-ID: <0a1eaaf8-3ede-cd56-ffb5-40b25f94e46e@linaro.org> Date: Tue, 9 Aug 2016 23:43:03 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 X-IsSubscribed: yes 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. Thanks, Kugan gcc/testsuite/ChangeLog: 2016-08-09 Kugan Vivekanandarajah PR tree-optimization/72835 * gcc.dg/torture/pr72835.c: New test. gcc/ChangeLog: 2016-08-09 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/torture/pr72835.c b/gcc/testsuite/gcc.dg/torture/pr72835.c index e69de29..d7d0a8d 100644 --- a/gcc/testsuite/gcc.dg/torture/pr72835.c +++ b/gcc/testsuite/gcc.dg/torture/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 {