From patchwork Thu Jun 8 18:49:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 773424 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 3wkDx13h0bz9s7m for ; Fri, 9 Jun 2017 04:49:23 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="E5Xr7pQj"; 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=ri9eNHvuIbcwZjwNnsHhTpSK/ui6V UUHUXztZx3KJs4awFEWOtTzxC9tdrMmlbH/RJqZKVKolfveu9V6QWvZYDcHpEK9m plGnfsSaQ3wKtxJpcx2Fbo9bsBslEPoULVmKEKFv8lD4Bo49ja0yG6exEJWU5UYe p7OGeFZFExv24k= 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=rx89RdL6N1roVdMAM28f+JBCdoQ=; b=E5X r7pQjePD2Dr0b/cxd41333ugkox+AKQh8lBod14iTytWuyi6Fc8k6s0p3JKV55ZK OYZH4v5xiltu0VdSJ61TxqGLjlp8c+tcKfbvsGWRN/B/pbm47EUqpEuLyKRcOBhK TjJga65MfSKrO0H4v1M7/kKslsZJp5SZfgpIp28k= Received: (qmail 23109 invoked by alias); 8 Jun 2017 18:49:09 -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 23090 invoked by uid 89); 8 Jun 2017 18:49:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=GSI, b 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; Thu, 08 Jun 2017 18:49:07 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7EDFC9F75D; Thu, 8 Jun 2017 18:49:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7EDFC9F75D Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7EDFC9F75D Received: from tucnak.zalov.cz (ovpn-117-9.ams2.redhat.com [10.36.117.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 27513197E5; Thu, 8 Jun 2017 18:49:09 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v58In7jD002016; Thu, 8 Jun 2017 20:49:08 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v58In60W002015; Thu, 8 Jun 2017 20:49:06 +0200 Date: Thu, 8 Jun 2017 20:49:06 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix reassoc range opt related ICE (PR tree-optimization/81003) Message-ID: <20170608184906.GA2154@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! force_gimple_operand_gsi called by update_range_test can using match.pd simplifications sometimes return INTEGER_CST (especially when cunroll unrolled code isn't really optimized by forwprop/ccp and similar passes before reassoc2), but that is something not acceptable to the rest of the optimize_range* code, because it needs to know not just the value, but also some gimple_stmt_iterator to insert related code etc. This patch makes sure we have a SSA_NAME even in that case. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-06-08 Jakub Jelinek PR tree-optimization/81003 * tree-ssa-reassoc.c (force_into_ssa_name): New function. (update_range_test): Use it instead of force_gimple_operand_gsi. * gcc.c-torture/compile/pr81003.c: New test. Jakub --- gcc/tree-ssa-reassoc.c.jj 2017-06-05 11:58:14.000000000 +0200 +++ gcc/tree-ssa-reassoc.c 2017-06-08 12:20:47.619790903 +0200 @@ -2282,6 +2282,26 @@ range_entry_cmp (const void *a, const vo } } +/* Helper function for update_range_test. Force EXPR into an SSA_NAME, + insert needed statements BEFORE or after GSI. */ + +static tree +force_into_ssa_name (gimple_stmt_iterator *gsi, tree expr, bool before) +{ + enum gsi_iterator_update m = before ? GSI_SAME_STMT : GSI_CONTINUE_LINKING; + tree ret = force_gimple_operand_gsi (gsi, expr, true, NULL_TREE, before, m); + if (TREE_CODE (ret) != SSA_NAME) + { + gimple *g = gimple_build_assign (make_ssa_name (TREE_TYPE (ret)), ret); + if (before) + gsi_insert_before (gsi, g, GSI_SAME_STMT); + else + gsi_insert_after (gsi, g, GSI_CONTINUE_LINKING); + ret = gimple_assign_lhs (g); + } + return ret; +} + /* Helper routine of optimize_range_test. [EXP, IN_P, LOW, HIGH, STRICT_OVERFLOW_P] is a merged range for RANGE and OTHERRANGE through OTHERRANGE + COUNT - 1 ranges, @@ -2393,15 +2413,13 @@ update_range_test (struct range_entry *r else if (op != range->exp) { gsi_insert_seq_before (&gsi, seq, GSI_SAME_STMT); - tem = force_gimple_operand_gsi (&gsi, tem, true, NULL_TREE, true, - GSI_SAME_STMT); + tem = force_into_ssa_name (&gsi, tem, true); gsi_prev (&gsi); } else if (gimple_code (stmt) != GIMPLE_PHI) { gsi_insert_seq_after (&gsi, seq, GSI_CONTINUE_LINKING); - tem = force_gimple_operand_gsi (&gsi, tem, true, NULL_TREE, false, - GSI_CONTINUE_LINKING); + tem = force_into_ssa_name (&gsi, tem, false); } else { @@ -2419,8 +2437,7 @@ update_range_test (struct range_entry *r } } gsi_insert_seq_before (&gsi, seq, GSI_SAME_STMT); - tem = force_gimple_operand_gsi (&gsi, tem, true, NULL_TREE, true, - GSI_SAME_STMT); + tem = force_into_ssa_name (&gsi, tem, true); if (gsi_end_p (gsi)) gsi = gsi_last_bb (gimple_bb (stmt)); else --- gcc/testsuite/gcc.c-torture/compile/pr81003.c.jj 2017-06-08 12:16:20.284127013 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr81003.c 2017-06-08 12:16:07.000000000 +0200 @@ -0,0 +1,10 @@ +/* PR tree-optimization/81003 */ + +unsigned int a, b; + +void +foo (void) +{ + for (b = 0; b < 13; b += 2) + a &= !!b; +}