From patchwork Thu Nov 9 19:58:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 836488 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-466450-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="NJrOEk8V"; 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 3yXvB323QKz9sRm for ; Fri, 10 Nov 2017 06:58:49 +1100 (AEDT) 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=sp2t9T0YiqNn+veNFqCJk6/CS2yFL NAQTQTjcOgH53hvCKiAytuARnfMChOBEUYG0jW7B7S62vvJJAsMO1AhJyNU3tiqW b/1dEUknKC7g94VQip2+iqbxOO04pOfd1nXDYqNo1eV+XBMZuZBxtkf+t8uWNQpB T5SiYaOunX1Hyo= 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=oBuRBY6vzUvAAvsYIbesWMHvzqw=; b=NJr OEk8VZNDmFkd8chWz3R4+1oVq/eOzGJNxeIK5uEDan8bDit2mmTd1aCkbXUJzkhh LoWNl+vnvdowHoFVuGQgFlSWWp9Ze6FIbmW0Z3IDfR4dwK/XRiHVFJNB+qIoWhxM XEbUW2nWZkal+lkoFO83+JaMlM+29AGLXuzKJwe8= Received: (qmail 127263 invoked by alias); 9 Nov 2017 19:58:41 -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 127253 invoked by uid 89); 9 Nov 2017 19:58:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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, 09 Nov 2017 19:58:39 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 844C585A02; Thu, 9 Nov 2017 19:58:38 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-247.ams2.redhat.com [10.36.116.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1A52F6BF8D; Thu, 9 Nov 2017 19:58:37 +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 vA9JwZDx019057; Thu, 9 Nov 2017 20:58:35 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vA9JwWuP019056; Thu, 9 Nov 2017 20:58:32 +0100 Date: Thu, 9 Nov 2017 20:58:32 +0100 From: Jakub Jelinek To: Eric Botcazou Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix compare-elim.c ICE (PR rtl-optimization/82913) Message-ID: <20171109195832.GE14653@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! My recent changes to compare-elim.c introduced ICE on the following testcase. When computing cmp->in_a_setter, I've made sure it is single_set and therefore I've left the if (!set) return false; stuff out. That usually works, but doesn't if an earlier try_eliminate_compare or try_merge_compare turns that cmp->in_a_setter instruction into a cmp + arith parallel. In that case, previously we'd give up and with the following patch we do as well. In theory, in some cases we could do better than that, e.g. on this testcase there is a SImode comparison of %eax and 0 merged by try_eliminate_compare and then there is a DImode comparison of %rax and 0 that we ICE on. The insn has a zero_extend of plus, and the user of the comparison looks only at the zero flag, so in this case we could leave the second comparison out, as zero extension shouldn't affect the zero flag. If the comparison user looked at some other flags like sign, overflow, carry etc., that wouldn't be the case, so in order to optimize away the second comparison we'd need to use some specialized CC mode like CCZ. Anyway, this patch doesn't do those smarts, just restores previous behavior. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-11-09 Jakub Jelinek PR rtl-optimization/82913 * compare-elim.c (try_merge_compare): Punt if def_insn is not single set. * gcc.c-torture/compile/pr82913.c: New test. Jakub --- gcc/compare-elim.c.jj 2017-11-01 22:51:37.000000000 +0100 +++ gcc/compare-elim.c 2017-11-09 11:44:18.996213647 +0100 @@ -683,6 +683,8 @@ try_merge_compare (struct comparison *cm rtx_insn *def_insn = cmp->in_a_setter; rtx set = single_set (def_insn); + if (!set) + return false; if (!can_merge_compare_into_arith (cmp_insn, def_insn)) return false; --- gcc/testsuite/gcc.c-torture/compile/pr82913.c.jj 2017-11-09 11:47:18.779031240 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr82913.c 2017-11-09 11:46:59.000000000 +0100 @@ -0,0 +1,23 @@ +/* PR rtl-optimization/82913 */ + +unsigned int a; +unsigned long int b; + +int +foo (void) +{ + ++a; + b = 0; +} + +unsigned long int +bar (int x) +{ + if (!foo () || !a) + { + int c = a != b; + if (c != x) + return a; + } + return 0; +}