From patchwork Mon Sep 9 15:20:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 273588 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id E90372C00DB for ; Tue, 10 Sep 2013 01:21:13 +1000 (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:reply-to:mime-version :content-type; q=dns; s=default; b=y0/yT0rwLbDdr9+9934sFq7R508ke L01ouUEl7NKnvo+A4YHSxl8qT2PcXb75c0S+a8mxuJfUEF4yHQ8ee9GDkCxS1TEj lNCtsEzuXmLzzsmf78AN17r5SLY5PLOXT9XaTlZmsjCx+Ym3PLjL0JcjowkGKiyk lq1qjYOKDFeSBE= 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:reply-to:mime-version :content-type; s=default; bh=xCBEop/VYUVkyAkDmOU67yItrDk=; b=Pth ET8hqBn64NBA0XLpUQvHAn4V975qRorT2gTez8miWu/YF2ADjy+WF3QmLHH9ez0x sYv0mzb7DuOM8BWyAnpuyLuskxU9nENc9lsYRe+Rhbe8hJGRWd4qKoOKfhZz/T16 oHS/DKXtZUXFwOQ8aOOgAjEMH2VZyScsVj/NDMMA= Received: (qmail 23565 invoked by alias); 9 Sep 2013 15:21:05 -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 23555 invoked by uid 89); 9 Sep 2013 15:21:05 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Sep 2013 15:21:05 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r89FL26e021747 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 9 Sep 2013 11:21:02 -0400 Received: from tucnak.zalov.cz (vpn1-4-75.ams2.redhat.com [10.36.4.75]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r89FL02j005102 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 9 Sep 2013 11:21:01 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id r89FL0sd024501; Mon, 9 Sep 2013 17:21:00 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id r89FKxuW024500; Mon, 9 Sep 2013 17:20:59 +0200 Date: Mon, 9 Sep 2013 17:20:59 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix init_range_entry (PR tree-optimization/58364) Message-ID: <20130909152059.GO1817@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! It is not safe to always handle a = ~b; for bool a and b as in_p = !in_p; exp = arg0. If the current range is say +[-,-] or -[-,-] or similar (i.e. unconditional false or true), then the value of exp doesn't matter and thus the fact that exp has been negated is irrelevant. Fixed by just making sure that the range either has 0 as high limit or 1 as low limit. In fold-const.c we actually are even more conservative and just do test for 0: case TRUTH_NOT_EXPR: /* We can only do something if the range is testing for zero. */ if (low == NULL_TREE || high == NULL_TREE || ! integer_zerop (low) || ! integer_zerop (high)) return NULL_TREE; *p_in_p = ! in_p; return arg0; Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.8? 2013-09-09 Jakub Jelinek PR tree-optimization/58364 * tree-ssa-reassoc.c (init_range_entry): For BIT_NOT_EXPR on BOOLEAN_TYPE, only invert in_p and continue with arg0 if the current range can't be an unconditional true or false. * gcc.c-torture/execute/pr58364.c: New test. Jakub --- gcc/tree-ssa-reassoc.c.jj 2013-08-13 12:20:45.000000000 +0200 +++ gcc/tree-ssa-reassoc.c 2013-09-09 11:30:07.416312027 +0200 @@ -1797,7 +1797,14 @@ init_range_entry (struct range_entry *r, switch (code) { case BIT_NOT_EXPR: - if (TREE_CODE (TREE_TYPE (exp)) == BOOLEAN_TYPE) + if (TREE_CODE (TREE_TYPE (exp)) == BOOLEAN_TYPE + /* Ensure the range is either +[-,0], +[0,0], + -[-,0], -[0,0] or +[1,-], +[1,1], -[1,-] or + -[1,1]. If it is e.g. +[-,-] or -[-,-] + or similar expression of unconditional true or + false, it should not be negated. */ + && ((high && integer_zerop (high)) + || (low && integer_onep (low)))) { in_p = !in_p; exp = arg0; --- gcc/testsuite/gcc.c-torture/execute/pr58364.c.jj 2013-09-09 11:28:59.917681919 +0200 +++ gcc/testsuite/gcc.c-torture/execute/pr58364.c 2013-09-09 11:28:40.000000000 +0200 @@ -0,0 +1,17 @@ +/* PR tree-optimization/58364 */ + +int a = 1, b, c; + +int +foo (int x) +{ + return x < 0 ? 1 : x; +} + +int +main () +{ + if (foo (a > c == (b = 0))) + __builtin_abort (); + return 0; +}