From patchwork Sun Jul 7 18:45:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1128713 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-504542-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="nPJMooqs"; 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 45hcwx5bzhz9sNk for ; Mon, 8 Jul 2019 04:46:00 +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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=PFZevs4MxD+hEgqb0fl/Nq1VvGod6hfhc3OjZnJnpYcJph2KTD HqJDRQUhOVJ3qJE/GrPfeG5oVrxmJbvHB4ng9lMLlLyDe7LFKuGmcqxnqCaBDisW h/ucyfaxE3pUhy+Fol60JtFvG3Z+SVFgJ6xI1lufpKPg5VyaoQKiSWjZY= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=n88rvgU72qkM0HfSWpJk4lub974=; b=nPJMooqsKX1QDbFwbd8L SEg4BBj7uh5MEZCsYvmxO6Ey6HAwS/bFYhuN77T//Sstj9zWiptjFvssJr1esB4b MCsr/PYT4aYmM9JXTBRTM5MwqvkO/oO3lgycagPfvKKgrkY6zhyIzaGzZJ1osV9d jDL2NpDYyK6G2xcfKW5GErQ= Received: (qmail 89911 invoked by alias); 7 Jul 2019 18:45:53 -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 89903 invoked by uid 89); 7 Jul 2019 18:45:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 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; Sun, 07 Jul 2019 18:45:51 +0000 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C835308339B for ; Sun, 7 Jul 2019 18:45:50 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-28.rdu2.redhat.com [10.10.112.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FEF219C5B for ; Sun, 7 Jul 2019 18:45:49 +0000 (UTC) To: gcc-patches From: Jeff Law Subject: [committed] [PR tree-optimization/91090] Fix logic error in jump threading Openpgp: preference=signencrypt Message-ID: <2664dc86-02c3-c8cc-40bf-c51b32209b9b@redhat.com> Date: Sun, 7 Jul 2019 12:45:47 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 X-IsSubscribed: yes This code was copied and reindented from tree-vrp.c. It looks like in that process the second conditional moved inside the true arm of the first conditional, which was wrong. It won't cause incorrect code, just missed optimizations. I also verified that the code is still live -- it triggers during a bootstrap when building the Fortran front-end for example. Given that I just fixed it on the trunk. I don't think there's much value in fixing on the release branches. Bootstrapped and regression tested on x86_64-linux-gnu. Installed on the trunk. jeff commit f60e7cee5700a9f9515ab4e2a922c325149c49e1 Author: law Date: Sun Jul 7 18:42:45 2019 +0000 PR tree-optimization/91090 * tree-ssa-dom.c (simplify_stmt_for_jump_threading): Fix logic error in handling of ranges to simplify switch statements. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@273184 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0ef7eb6b93b..9f83f75b0bf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-07-07 Jeff Law + + PR tree-optimization/91090 + * tree-ssa-dom.c (simplify_stmt_for_jump_threading): Fix logic error + in handling of ranges to simplify switch statements. + 2019-07-07 Iain Sandoe * config/darwin.c (darwin_override_options): Make a final check on PIC diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index b0d56fcf3e3..17c852d5299 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -913,21 +913,26 @@ simplify_stmt_for_jump_threading (gimple *stmt, find_case_label_range (switch_stmt, vr->min (), vr->max (), &i, &j); + /* Is there only one such label? */ if (i == j) { tree label = gimple_switch_label (switch_stmt, i); tree singleton; + /* The i'th label will only be taken if the value range of the + operand is entirely within the bounds of this label. */ if (CASE_HIGH (label) != NULL_TREE ? (tree_int_cst_compare (CASE_LOW (label), vr->min ()) <= 0 && tree_int_cst_compare (CASE_HIGH (label), vr->max ()) >= 0) : (vr->singleton_p (&singleton) && tree_int_cst_equal (CASE_LOW (label), singleton))) return label; - - if (i > j) - return gimple_switch_label (switch_stmt, 0); } + + /* If there are no such labels, then the default label + will be taken. */ + if (i > j) + return gimple_switch_label (switch_stmt, 0); } if (vr->kind () == VR_ANTI_RANGE)