From patchwork Tue Oct 11 21:59:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 680958 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 3strWL4hdSz9s3T for ; Wed, 12 Oct 2016 08:59:40 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=J3ZMzYZC; 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=HsmRTibS/2fIEfRu8rYC6q9JfH19D VudY+yHR8W60YdBcLVFsykKfzWpSjfP8HKjxvMcg/4nSb0bvcXVleV8QMOzj6RqN d1GnnV3wphrVeWcvod096iyFpmW1Yt3PbJuHTpYVmIQnFXvJdHs1/jFzjmUGPsqZ a2juG+f9sKvud4= 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=8GXTdrEDxWtM+J2jXbJDV9tHwio=; b=J3Z MzYZC9o7Q0f/kT+Gzclx4Lae/47OUvcHNtfPGR8+MrZXqKnNVLNhE78vGKqS+Z2M Xs2wDChS5JtV5sF9sJa1YY2DW66pEDxpMbON5k1/yt+Y94ESOI79Jp9MLBH3ADBz MLkYVnKCFvlnrAZUAwEGejsPHgqmmDF3tqgcSUFU= Received: (qmail 91483 invoked by alias); 11 Oct 2016 21:59:33 -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 91458 invoked by uid 89); 11 Oct 2016 21:59:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2209 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; Tue, 11 Oct 2016 21:59:31 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 547CC66846; Tue, 11 Oct 2016 21:59:30 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-44.ams2.redhat.com [10.36.116.44]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9BLxSgh000677 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 11 Oct 2016 17:59:29 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u9BLxPvP007618; Tue, 11 Oct 2016 23:59:26 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u9BLxOZ4007617; Tue, 11 Oct 2016 23:59:24 +0200 Date: Tue, 11 Oct 2016 23:59:23 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix optimize_range_tests_var_bound reassoc ICE (PR tree-optimization/77929) Message-ID: <20161011215923.GG7282@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! The following testcase ICEs, because ranges[i].exp is x < y with boolean type, but (*ops)[ranges[i].idx] is that result cast to int and the code didn't take into account possible casts that init_range_entry looks through. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-10-11 Jakub Jelinek PR tree-optimization/77929 * tree-ssa-reassoc.c (optimize_range_tests_var_bound): Handle (*ops)[ranges[i].idx]->op != ranges[i].exp case. * gcc.c-torture/compile/pr77929.c: New test. Jakub --- gcc/tree-ssa-reassoc.c.jj 2016-10-09 13:18:21.000000000 +0200 +++ gcc/tree-ssa-reassoc.c 2016-10-11 13:28:08.406340143 +0200 @@ -2994,12 +2994,26 @@ optimize_range_tests_var_bound (enum tre } else { - g = gimple_build_assign (make_ssa_name (TREE_TYPE (ranges[i].exp)), - ccode, rhs1, rhs2); + operand_entry *oe = (*ops)[ranges[i].idx]; + tree ctype = oe->op ? TREE_TYPE (oe->op) : boolean_type_node; + if (!INTEGRAL_TYPE_P (ctype) + || (TREE_CODE (ctype) != BOOLEAN_TYPE + && TYPE_PRECISION (ctype) != 1)) + ctype = boolean_type_node; + g = gimple_build_assign (make_ssa_name (ctype), ccode, rhs1, rhs2); gimple_set_uid (g, uid); gsi_insert_before (&gsi, g, GSI_SAME_STMT); + if (oe->op && ctype != TREE_TYPE (oe->op)) + { + g = gimple_build_assign (make_ssa_name (TREE_TYPE (oe->op)), + NOP_EXPR, gimple_assign_lhs (g)); + gimple_set_uid (g, uid); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + } ranges[i].exp = gimple_assign_lhs (g); - (*ops)[ranges[i].idx]->op = ranges[i].exp; + oe->op = ranges[i].exp; + ranges[i].low = build_zero_cst (TREE_TYPE (ranges[i].exp)); + ranges[i].high = ranges[i].low; } ranges[i].strict_overflow_p = false; operand_entry *oe = (*ops)[ranges[*idx].idx]; --- gcc/testsuite/gcc.c-torture/compile/pr77929.c.jj 2016-10-11 14:00:07.840653109 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr77929.c 2016-10-11 13:59:51.000000000 +0200 @@ -0,0 +1,13 @@ +/* PR tree-optimization/77929 */ + +void bar (void); + +void +foo (int x, unsigned short int y) +{ + int a = 0; + int b = (y != 0) ? (x < y) : (a < 0); + + if (x >= 0 & b) + bar (); +}