From patchwork Sun Jun 5 10:54:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 69346 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp1013129qgf; Sun, 5 Jun 2016 03:55:16 -0700 (PDT) X-Received: by 10.36.3.7 with SMTP id e7mr9077596ite.15.1465124116206; Sun, 05 Jun 2016 03:55:16 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v80si20816276pfj.199.2016.06.05.03.55.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Jun 2016 03:55:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-429057-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-429057-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-429057-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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=GGjUacZuhg82qf+7PyAIX1B8qHMhN2r9IJt9u36ixsSmqLM7Ys nOfTpV6HPpN0WEsxV0bcuz4TpyGrjS8cTwTKj4X++mYrJNipJpv+aOsuD2sfaQi5 tEU33kmrwCeiTyMvBCAZNUNZI1ZCP2aFJgNewKix6BlUi80Bi2ZK1MP6c= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=cRhIEonsibtTtn4elb4+bnyjWWw=; b=RjFjTklJ9/PRYIV34ioc tNCayaV76v7OvDw+nFaf5He2X0Bp+bt8J/r5JrTwoqu4ebmV2Z3nBoNnL7f5LbKn PEDZXdR/+13nGx3oktQAQjuSJMUyFDlGhLxuib7SiK22otj9NqO3i14SeVzKFvvU eMfwN2mHcFMloGDo5a0np0I= Received: (qmail 35008 invoked by alias); 5 Jun 2016 10:55:03 -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 34704 invoked by uid 89); 5 Jun 2016 10:55:02 -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-06-05, HX-Received:10.98.70.76 X-HELO: mail-pf0-f170.google.com Received: from mail-pf0-f170.google.com (HELO mail-pf0-f170.google.com) (209.85.192.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 05 Jun 2016 10:54:52 +0000 Received: by mail-pf0-f170.google.com with SMTP id g64so57906523pfb.2 for ; Sun, 05 Jun 2016 03:54:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version; bh=9bCXMMCaEtlGxO1YtO999tmtU5mxQzW9tli+dObTc9w=; b=k+4jmG/lHeD2hMqEjSIOnxbOil6ske+pXwB0cSfLoADrHRmaL0AJF7QoNkZe/AgZAJ mGSmHqZjV2fjEKSSqvX7GJIsJKeEDrbYe6KI0YBNI1qJ7oNwrbDBy3FRToCVF7Lgjh+M A47ckVvBfiZnH/2iZpHwvbNx/5/fAQ3/kbsFKsHZKzTlDXvEE1ieJ670d/pXYzxUOoOl Givql9OvVIU0PRiuKNc8v/RlLS/ponfjuCT4CkGhNcWtzvltJAAJ/ENg/sphuvd8sAS2 Kzf7IhRv4ZxgUzBGKy5lxizg3uLyxKdIrNICipMxb2lIdfVP8WadRHtZeDZ+1jEW1Csr dVJQ== X-Gm-Message-State: ALyK8tL0b/IoLG4E+9cd0U4ghNK5DrIE+UakJT/SIWIu1aIJQO3fgsvye46fcsRtNRXv/B1Y X-Received: by 10.98.70.76 with SMTP id t73mr18406972pfa.123.1465124089898; Sun, 05 Jun 2016 03:54:49 -0700 (PDT) Received: from [10.1.1.13] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.gmail.com with ESMTPSA id fn3sm17718281pab.20.2016.06.05.03.54.47 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 05 Jun 2016 03:54:48 -0700 (PDT) To: "gcc-patches@gcc.gnu.org" , Richard Biener From: kugan Subject: [PR71408] - Fix wrong code at -Os and above Message-ID: <575404F3.70806@linaro.org> Date: Sun, 5 Jun 2016 20:54:43 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi All, For the testcase in PR71408 zero_one_operation seems still broken. In handling NEGATE_EXPR, as part of undistribute_ops_list, in zero_one_operation, we are doing propagate_op_to_single_use (op, stmt, def); This results in: - _14 = _5 * _12; _15 = (int) _11; _16 = ~_15; _17 = (unsigned int) _16; - _18 = -_5; - _19 = _17 * _18; - _20 = _14 + _19; - _24 = _5 & _20; + _19 = _5 * _17; + _35 = _19 + _12; + _34 = _35 * _5; + _20 = _34; + _24 = _20 & _5; We should instead propagate (-1) as "op" is the one which gets factored out. With the attached patch we now have: - _14 = _5 * _12; _15 = (int) _11; _16 = ~_15; _17 = (unsigned int) _16; - _18 = -_5; - _19 = _17 * _18; - _20 = _14 + _19; - _24 = _5 & _20; + _32 = _17; + _19 = -_32; + _34 = _19 + _12; + _33 = _34 * _5; + _20 = _33; + _24 = _20 & _5; Regression tested and bootstrapped on x86-64-linux-gnu with no new regression. Is this OK for trunk? Thanks, Kugan gcc/ChangeLog: 2016-06-05 Kugan Vivekanandarajah PR middle-end/71408 * tree-ssa-reassoc.c (zero_one_operation): Fix NEGATE_EXPR operand for propagate_op_to_single_use. gcc/testsuite/ChangeLog: 2016-06-05 Kugan Vivekanandarajah PR middle-end/71408 * gcc.dg/tree-ssa/pr71408.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71408.c b/gcc/testsuite/gcc.dg/tree-ssa/pr71408.c index e69de29..896a428 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr71408.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71408.c @@ -0,0 +1,30 @@ +/* PR middle-end/71408 */ +/* { dg-do run } */ +/* { dg-options "-Os" } */ +unsigned a, b; + +struct S0 +{ + int f1:18; + unsigned f3:4; +}; + +void fn1 () +{ + struct S0 c = { 7, 0 }; + if (c.f1) + c.f3 = 3; + a = -~c.f3; + c.f3 = ~(c.f1 && c.f1); + c.f1 = c.f3 * (c.f1 - (c.f1 - a % c.f1)) + ~c.f3 * -a; + b = ~(c.f1 & a); + if (b >= 4294967295) + __builtin_abort (); +} + +int +main () +{ + fn1 (); + return 0; +} diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 1973077..7865df0 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -1203,7 +1203,8 @@ zero_one_operation (tree *def, enum tree_code opcode, tree op) { if (gimple_assign_rhs1 (stmt) == op) { - propagate_op_to_single_use (op, stmt, def); + tree cst = build_minus_one_cst (TREE_TYPE (op)); + propagate_op_to_single_use (cst, stmt, def); return; } else if (integer_minus_onep (op) @@ -1251,7 +1252,8 @@ zero_one_operation (tree *def, enum tree_code opcode, tree op) { if (gimple_assign_rhs1 (stmt2) == op) { - propagate_op_to_single_use (op, stmt2, def); + tree cst = build_minus_one_cst (TREE_TYPE (op)); + propagate_op_to_single_use (cst, stmt2, def); return; } else if (integer_minus_onep (op)