From patchwork Wed Apr 19 06:20:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 752102 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 3w7BhT389hz9s2s for ; Wed, 19 Apr 2017 16:20:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="rBxfvWI4"; 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=JWKPejGK3nfAb8Qf XLWQrdBCg+gqk9pvAyVrjUO5EvA4RXrng0xQ2kVya7oZ0+UzAt+HeyocbhqCnYwm qlkfzHgYufgkVa2MLAqDNoeF+2P25tQJa5JIKe7b+HydSplJethXB8309WZ9HcH6 zkujyHFCRuKesDvRsQIB4pAlLgo= 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=YaG2s8fLNfa72LoRSwMpC6 MDaAs=; b=rBxfvWI4N57cFLqDbUnmpxig3UvLWoanNGXMkdtcicTkbrs8WGM3t1 oYZ9YTZSQQfZOWc/RT1L/h1Zn94iRBxQhijnXsGLyoirRgdkaHUmXgIrcbN+7/W9 5Gacod85f58q21VoQW8szCgR7ZwGkQYqW7ApV17HeWpLY1OWeCdFc= Received: (qmail 90849 invoked by alias); 19 Apr 2017 06:20:47 -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 90815 invoked by uid 89); 19 Apr 2017 06:20:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:ebotcaz, U*ebotcazou, D*ac.jp, (unknown) X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Apr 2017 06:20:42 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id BDF758135F for ; Wed, 19 Apr 2017 08:20:41 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 381bfpof4pAh for ; Wed, 19 Apr 2017 08:20:41 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 963F181358 for ; Wed, 19 Apr 2017 08:20:41 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix PR tree-optimization/80426 Date: Wed, 19 Apr 2017 08:20:40 +0200 Message-ID: <7983915.vF9qLkl6hX@polaris> User-Agent: KMail/4.14.10 (Linux/3.16.7-53-desktop; KDE/4.14.9; x86_64; ; ) MIME-Version: 1.0 Hi, this is a regression on the mainline, but the underlying issue is present on the branches too, and similar to PR tree-optimization/79666, but this time for the invariant part instead of the symbolic one. In extract_range_from_binary_expr_1, when the invariant part of the symbolic computation overflows, we drop to varying: /* If we have overflow for the constant part and the resulting range will be symbolic, drop to VR_VARYING. */ if ((min_ovf && sym_min_op0 != sym_min_op1) || (max_ovf && sym_max_op0 != sym_max_op1)) { set_value_range_to_varying (vr); return; } But we fail to compute the overflow when the operation is MINUS_EXPR and the first operand is 0, i.e. we can silently negate INT_MIN and fail to bail out. Fixed by computing overflow in this case too. Tested on x86_64-suse-linux, OK for mainline and 6 branch? 2017-04-19 Eric Botcazou PR tree-optimization/80426 * tree-vrp.c (extract_range_from_binary_expr_1): For an additive operation on symbolic operands, also compute the overflow for the invariant part when the operation degenerates into a negation. 2017-04-19 Eric Botcazou * gcc.c-torture/execute/20170419-1.c: New test. Index: tree-vrp.c =================================================================== --- tree-vrp.c (revision 246960) +++ tree-vrp.c (working copy) @@ -2461,7 +2461,19 @@ extract_range_from_binary_expr_1 (value_ else if (min_op0) wmin = min_op0; else if (min_op1) - wmin = minus_p ? wi::neg (min_op1) : min_op1; + { + if (minus_p) + { + wmin = wi::neg (min_op1); + + /* Check for overflow. */ + if (wi::cmp (0, min_op1, sgn) + != wi::cmp (wmin, 0, sgn)) + min_ovf = wi::cmp (0, min_op1, sgn); + } + else + wmin = min_op1; + } else wmin = wi::shwi (0, prec); @@ -2489,7 +2501,19 @@ extract_range_from_binary_expr_1 (value_ else if (max_op0) wmax = max_op0; else if (max_op1) - wmax = minus_p ? wi::neg (max_op1) : max_op1; + { + if (minus_p) + { + wmax = wi::neg (max_op1); + + /* Check for overflow. */ + if (wi::cmp (0, max_op1, sgn) + != wi::cmp (wmax, 0, sgn)) + max_ovf = wi::cmp (0, max_op1, sgn); + } + else + wmax = max_op1; + } else wmax = wi::shwi (0, prec);