From patchwork Sat Oct 8 19:09:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 679961 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 3srwv36h9gz9sBr for ; Sun, 9 Oct 2016 06:10:06 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=W/FfUvHM; 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=YbGQBGQiIdK8rUeqnrMTkrXYH2YHu k+gWmRAWSkqmftPm/BZiJjIn9feWdK+ytFtWjECtX/GOp+tu9T8TSxg72JqrcosU 5tCxx0xib13CThrPwflDYwENH0/7/oli/qzCloUEvPeGZITizl7jrNG+NPLpmYBL aogoIHF3HCOEbs= 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=JAB70UDydmGVibV4vEukBbKtd2o=; b=W/F fUvHM5CqcsTXEAUyRhDaTyz2QeYXwM/KaSZHdZspfXf4QquyWblfMLSJughpGJVO BtgUkCeaBTx5Ie4/CGssYamrEbntccTcbTuWmS+cmnQMSz75c+5niw1RLLG4YJ+P Kx8N9NzBabU/+iMixjPHjVPCosXoXywv4SpBku50= Received: (qmail 46872 invoked by alias); 8 Oct 2016 19:09:56 -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 46856 invoked by uid 89); 8 Oct 2016 19:09:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.6 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=BIT_AND_EXPR X-HELO: mx1.redhat.com 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; Sat, 08 Oct 2016 19:09:52 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 336F788E60; Sat, 8 Oct 2016 19:09:51 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-44.ams2.redhat.com [10.36.116.44]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u98J9me3023868 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 8 Oct 2016 15:09:50 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u98J9jtG010665; Sat, 8 Oct 2016 21:09:46 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u98J9hYM010664; Sat, 8 Oct 2016 21:09:43 +0200 Date: Sat, 8 Oct 2016 21:09:43 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix optimize_range_tests_var_bound (PR tree-optimization/77901) Message-ID: <20161008190943.GN7282@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes Hi! I forgot to take into account that ranges[i].exp might not be just NULL or SSA_NAME, but it can be e.g. BIT_AND_EXPR etc. when optimized by earlier optimize_range_tests* optimizations. We only care about SSA_NAMEs or the a < b comparisons that can be ranges[i].exp == NULL if they are in GIMPLE_COND. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-10-08 Jakub Jelinek PR tree-optimization/77901 * tree-ssa-reassoc.c (optimize_range_tests_var_bound): Only optimize if ranges[i].exp is SSA_NAME when looking for >= and only when ranges[i].exp is NULL or SSA_NAME when looking for the other comparison. * gcc.c-torture/compile/pr77901.c: New test. Jakub --- gcc/tree-ssa-reassoc.c.jj 2016-10-07 11:32:51.000000000 +0200 +++ gcc/tree-ssa-reassoc.c 2016-10-08 18:01:32.773394195 +0200 @@ -2846,7 +2846,9 @@ optimize_range_tests_var_bound (enum tre for (i = first; i < length; i++) { - if (ranges[i].exp == NULL_TREE || !ranges[i].in_p) + if (ranges[i].exp == NULL_TREE + || TREE_CODE (ranges[i].exp) != SSA_NAME + || !ranges[i].in_p) continue; tree type = TREE_TYPE (ranges[i].exp); @@ -2878,6 +2880,8 @@ optimize_range_tests_var_bound (enum tre tree rhs1, rhs2; if (ranges[i].exp) { + if (TREE_CODE (ranges[i].exp) != SSA_NAME) + continue; stmt = SSA_NAME_DEF_STMT (ranges[i].exp); if (!is_gimple_assign (stmt)) continue; --- gcc/testsuite/gcc.c-torture/compile/pr77901.c.jj 2016-10-08 18:05:47.590172355 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr77901.c 2016-10-08 18:05:31.000000000 +0200 @@ -0,0 +1,10 @@ +/* PR tree-optimization/77901 */ + +void bar (void); + +void +foo (int *x, long *y) +{ + if (*y && *x != 10 && *x != 12 && *y >= 0) + bar (); +}