From patchwork Wed Nov 28 13:03:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1004539 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-491096-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="KWEkwiH/"; 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 434gnQ4G71z9s2P for ; Thu, 29 Nov 2018 00:03:22 +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:subject:message-id:mime-version:content-type; q=dns; s= default; b=ZGoNmyPVtmDK3269NFJngR0vuuvExYBZ8ZEC9OZ/gLYvdoKqkLAEQ kT+BJRubMQ5UEYMFfNkmwpywdQfceVKXTYyzpxRNB6z8js7ZDvPgDEIp2iw4oF/+ YzqMHUS6hW5HsVrQYVhislEep9qqgVKvpofpDYidvep/wiI30JS/KE= 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:subject:message-id:mime-version:content-type; s= default; bh=MTi6XfwaUvV850tRAoRhttTGShk=; b=KWEkwiH/k+eFA+Y/TscC W14ssB6+O7vz/qi1+C9Sr7vyFVR5gprYykMWD8BY6v+Gj/kVW+Hy3rFNqztl0DJ2 BkLc+r+p3gRLbjOpZqJQJk+n+0nx7FQBfFQMb4xgPmHvAJpOWOINzsXLwkHaJjJ7 Q6EwWmn4Kw00WAVERlg1oQQ= Received: (qmail 60631 invoked by alias); 28 Nov 2018 13:03:15 -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 59900 invoked by uid 89); 28 Nov 2018 13:03:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.2 spammy=value_range, gphi, our X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Nov 2018 13:03:13 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3EB24AD85 for ; Wed, 28 Nov 2018 13:03:11 +0000 (UTC) Date: Wed, 28 Nov 2018 14:03:11 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR88217 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 The following fixes infinite looping in VRP because of tricks we pull off in PHI handling which are not handling our inconsistent honoring of TYPE_{MIN,MAX}_VALUE. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. From 9d76e3649ff28f6abdd4960647de03f10573f546 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Wed, 28 Nov 2018 11:22:48 +0100 Subject: [PATCH] fix-pr88217 2018-11-28 Richard Biener PR tree-optimization/88217 * vr-values.c (vr_values::extract_range_from_phi_node): Make sure to handle results > +INF and < -INF correctly when trying to drop down to +INF - 1 or -INF + 1. * g++.dg/pr88217.C: New testcase. diff --git a/gcc/testsuite/g++.dg/pr88217.C b/gcc/testsuite/g++.dg/pr88217.C new file mode 100644 index 00000000000..b0506acabd7 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr88217.C @@ -0,0 +1,18 @@ +// { dg-do compile { target c++11 } } +// { dg-options "-O2 -fstrict-enums -fno-tree-forwprop -fno-tree-fre" } + +extern "C" int printf (const char *, ...); + +enum E { e1, e2, e3, X }; +E operator*(E e) { return e; } +E begin(E e) { return e; } +E end(E e) { return X; } +E operator++(E& e) { return e = E(e+1); } + +int main() +{ + for (auto e: e1) + { + printf ("%d ", e); + } +} diff --git a/gcc/vr-values.c b/gcc/vr-values.c index 41862b97601..a0027c0b353 100644 --- a/gcc/vr-values.c +++ b/gcc/vr-values.c @@ -2857,7 +2857,8 @@ vr_values::extract_range_from_phi_node (gphi *phi, value_range *vr_result) if (cmp_min < 0) new_min = lhs_vr->min (); else if (cmp_min > 0 - && !vrp_val_is_min (vr_result->min ())) + && tree_int_cst_lt (vrp_val_min (vr_result->type ()), + vr_result->min ())) new_min = int_const_binop (PLUS_EXPR, vrp_val_min (vr_result->type ()), build_int_cst (vr_result->type (), 1)); @@ -2866,7 +2867,8 @@ vr_values::extract_range_from_phi_node (gphi *phi, value_range *vr_result) if (cmp_max > 0) new_max = lhs_vr->max (); else if (cmp_max < 0 - && !vrp_val_is_max (vr_result->max ())) + && tree_int_cst_lt (vr_result->max (), + vrp_val_max (vr_result->type ()))) new_max = int_const_binop (MINUS_EXPR, vrp_val_max (vr_result->type ()), build_int_cst (vr_result->type (), 1));