From patchwork Thu Nov 7 15:15:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 289381 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EF6C02C0087 for ; Fri, 8 Nov 2013 02:15:36 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=JB6JojGwI2qlX9UyouhJym7C64r0pdreA6r4mG6ubPR/V52sS5 lz9GsEcdXcyIC0sngYkJaXDNxOmPDF80rYWzFWZwAJ07tJrBw2nzjGbGe8tiVlwm KyOkl5gnEOxbhZvl26BehupfaaPi10EQmKIwoFHEG5yLHs/+3hlnC4MUQ= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=XepwHSmPz32JlN+jf0dUu8W/NxI=; b=wnYWmi2ri0pVzHv26anX 3rlVNL/XrRLNC8jJvd1pDVk6pnNf/900btW5xpFpHwzCiopuzAp3rpna6XzMKEWe rfxji1c4dnAHL12Mjl3l+qO8PV/psIs47+buyuLbax35mpAgMTXalVZZO3HuMmOe NbPfd6POvqk48chaf1ZWvvw= Received: (qmail 4647 invoked by alias); 7 Nov 2013 15:15:25 -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 4633 invoked by uid 89); 7 Nov 2013 15:15:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.1 required=5.0 tests=AWL, BAYES_50, RDNS_NONE, SPAM_SUBJECT, SPF_HELO_PASS, SPF_PASS, URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from Unknown (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Nov 2013 15:15:23 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA7FFFeX027237 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 7 Nov 2013 10:15:16 -0500 Received: from redhat.com (vpn-54-220.rdu2.redhat.com [10.10.54.220]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rA7FFB3X016744 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 7 Nov 2013 10:15:14 -0500 Date: Thu, 7 Nov 2013 16:15:11 +0100 From: Marek Polacek To: GCC Patches Cc: Jeff Law Subject: [PATCH] Don't simplify_conversion_from_bitmask on x & 1 (PR tree-optimization/59014) Message-ID: <20131107151511.GK30062@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Here, forward propagation turned _6 = a.1_5 & 1; _7 = (_Bool) _6; into _7 = (_Bool) a.1_5; but that's wrong: e.g. if a = 2 then (_Bool) _6 is 0, but (_Bool) a.1_5 is 1. If a is an odd number, this is correct, but we don't know the value of a, so I disabled this optimization for "x & 1" cases. For e.g. "x & 255", this still works correctly. In this PR, VRP created wrong ASSERT_EXPR because of this, thus we were miscompiling the following testcase... Regtested/bootstrapped on x86_64-linux, ok for trunk? 2013-11-07 Marek Polacek PR tree-optimization/59014 * tree-ssa-forwprop.c (simplify_conversion_from_bitmask): Don't optimize x & 1 expressions here. testsuite/ * gcc.dg/torture/pr59014.c: New test. Marek --- gcc/testsuite/gcc.dg/torture/pr59014.c.mp 2013-11-07 14:47:38.040941144 +0100 +++ gcc/testsuite/gcc.dg/torture/pr59014.c 2013-11-07 14:49:03.646271031 +0100 @@ -0,0 +1,26 @@ +/* PR tree-optimization/59014 */ +/* { dg-do run } */ + +int a = 2, b, c, d; + +int +foo () +{ + for (;; c++) + if ((b > 0) | (a & 1)) + ; + else + { + d = a; + return 0; + } +} + +int +main () +{ + foo (); + if (d != 2) + __builtin_abort (); + return 0; +} --- gcc/tree-ssa-forwprop.c.mp 2013-11-07 14:30:43.785733810 +0100 +++ gcc/tree-ssa-forwprop.c 2013-11-07 14:42:31.836765375 +0100 @@ -1199,9 +1199,16 @@ simplify_conversion_from_bitmask (gimple if (TREE_CODE (rhs_def_operand1) == SSA_NAME && ! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs_def_operand1) && TREE_CODE (rhs_def_operand2) == INTEGER_CST + /* We can't turn + _6 = a & 1; + _7 = (_Bool) _6; + into + _7 = (_Bool) a; + as that's wrong if A is an even number. */ + && ! integer_onep (rhs_def_operand2) && operand_equal_p (rhs_def_operand2, build_low_bits_mask (TREE_TYPE (rhs_def_operand2), - TYPE_PRECISION (lhs_type)), + TYPE_PRECISION (lhs_type)), 0)) { /* This is an optimizable case. Replace the source operand