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: 630388 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3rMvqk2qpRz9ssP for ; Sun, 5 Jun 2016 20:55:12 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Qx+5mryD; dkim-atps=neutral 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=SWSz9bJMS3OUuI5zPnWCyuFLu99TZ1hE8dIF3nehFBikJj4U5G 6HOTjnrPkmv1XGUwqfXUqfPvWGcPv4brRGh20l4ugsCTax4vRHCIdP8dcv9YgCs/ JEZOPMm7lzkmCEp6rdLx7ISMPyYphP7WRHXhpzzN6xymmT5FZl9/kJNyk= 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=Qx+5mryDimqEY78QSeIZ EgyHWfECYSVQ0BKMYpqRcgj0sOY0HREeWDTo9k18OpebwRf5uJRU2f21ZtpmBRmY N67NrJM5IeuPcVh0wRZpDOEaFHt143Ktt3mODjoKqrzCk2vItp19TfN0hWwJvBRO lV4M50A5Y7lR1AtRx5SVBGU= 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)