From patchwork Thu May 30 21:26:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1107935 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-502010-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="GWbpoox/"; dkim-atps=neutral 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 45FLJJ0VdCz9s3l for ; Fri, 31 May 2019 07:27:11 +1000 (AEST) 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=OuTZmcPZS0mVy4gpap3e2FgVTNTb1 EEcaTT/bLZA8NMo/iErfaKLOP8grDdpPI2moQWYLdvDNvOZ/6SZ/yPM92ZCB6xpG 8pVs5UCf2eouVf+14LwZNN6YhSAP4BXviKsZKxfTY+GOMYUxO9qMCOzO3/NLgzbG qO5H6VedZH3ITU= 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=/BgNLDmEcltjwlP1zDbjApxVM2Q=; b=GWb poox/XZwhLXlUzX7ALLOUePakLEnKJTZjs3h2Zr+HT93GTZjgeQJht0vu6iZ8QEK fVkV4TbPrxPijAzEuF0EHkNcMYcM0hx19TPn/8w+I8MOlQwST3iO+MyhJIKocfOV wv/xGCZoUfiQUItc478Net8/950v30B34JAHbmSI= Received: (qmail 91007 invoked by alias); 30 May 2019 21:27: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 90999 invoked by uid 89); 30 May 2019 21:27:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=wire 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, 30 May 2019 21:27:03 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 957D681F22; Thu, 30 May 2019 21:27:02 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-52.ams2.redhat.com [10.36.116.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 491735C553; Thu, 30 May 2019 21:27:01 +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 x4ULQwj1020644; Thu, 30 May 2019 23:26:59 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x4ULQuJr020643; Thu, 30 May 2019 23:26:56 +0200 Date: Thu, 30 May 2019 23:26:56 +0200 From: Jakub Jelinek To: Richard Biener , Jeff Law , lxo@tucnak.zalov.cz Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ICE in ssa_create_duplicates (PR tree-optimization/90671) Message-ID: <20190530212655.GD19695@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) X-IsSubscribed: yes Hi! The following testcase ICEs on the trunk, because both gsi_split_seq_after and gsi_insert_seq_after have assertions that the split is not after gsi_end_p iterator or insertion is not after such an iterator. My understanding of Alex' change is that it wants to hide any added debug stmts temporarily from create_block_for_threading duplication, so that it remains just in one of the blocks. Now, template_last_to_copy is initialized using last_bb (template_block), if that block is initially completely empty, template_last_to_copy will be gsi_end_p, gsi_stmt on it NULL, so I think in that case we can't split any sequence anywhere, we simply want to hide the whole sequence from the block duplication and put it in afterwards. The following patch does that. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-05-30 Jakub Jelinek PR tree-optimization/90671 * tree-ssa-threadupdate.c (ssa_create_duplicates): If template_block used to be empty on the first call, don't use gsi_split_seq_after and gsi_insert_seq_after, but remember whole seq with bb_seq and set it with set_bb_seq. * gcc.dg/torture/pr90671.c: New test. Jakub --- gcc/tree-ssa-threadupdate.c.jj 2019-05-23 12:57:15.522512319 +0200 +++ gcc/tree-ssa-threadupdate.c 2019-05-30 10:15:44.718468219 +0200 @@ -1142,12 +1142,25 @@ ssa_create_duplicates (struct redirectio gimple_seq seq = NULL; if (gsi_stmt (local_info->template_last_to_copy) != gsi_stmt (gsi_last_bb (local_info->template_block))) - seq = gsi_split_seq_after (local_info->template_last_to_copy); + { + if (gsi_end_p (local_info->template_last_to_copy)) + { + seq = bb_seq (local_info->template_block); + set_bb_seq (local_info->template_block, NULL); + } + else + seq = gsi_split_seq_after (local_info->template_last_to_copy); + } create_block_for_threading (local_info->template_block, rd, 0, &local_info->duplicate_blocks); if (seq) - gsi_insert_seq_after (&local_info->template_last_to_copy, - seq, GSI_SAME_STMT); + { + if (gsi_end_p (local_info->template_last_to_copy)) + set_bb_seq (local_info->template_block, seq); + else + gsi_insert_seq_after (&local_info->template_last_to_copy, + seq, GSI_SAME_STMT); + } /* Go ahead and wire up outgoing edges and update PHIs for the duplicate block. */ --- gcc/testsuite/gcc.dg/torture/pr90671.c.jj 2019-05-30 10:20:13.686068207 +0200 +++ gcc/testsuite/gcc.dg/torture/pr90671.c 2019-05-30 10:19:50.815442342 +0200 @@ -0,0 +1,16 @@ +/* PR tree-optimization/90671 */ +/* { dg-do compile } */ +/* { dg-additional-options "-w -g" } */ + +int a; + +int +main () +{ + int b, c; + for (c = 0; c < 2; c++) + while (a) + if (b) + break; + return 0; +}