From patchwork Fri May 17 15:51:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 244674 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 11B0B2C00CE for ; Sat, 18 May 2013 01:51:35 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=wrNytST1T8pyONSTWhVnRgWaGPQPOwIGVJCZUmh6LkWOSE lj24WPMyTIXWHMnC+yc7Gnd9yEUDtc7SOYXl63qKYywTYPcbmARFvpAmeES/GAVN /OLv/D1u6K9svu0vPfdrhJEbADy1UqmBVyi6MIIQ5W6mN/O0pXwRw2n3kNYdw= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=R6ridOsEtK78DXw9eDYBRZvjrJw=; b=AJkmvCGJqLbWY3HmDgaF eY90q4qkN8QjeM2fqdTuPMe0vkl3NlhZn98DDHk6daqiWUPHeyj+PPTL9+n12FAZ MwVOWN4tBfp9+yqwIPK0pdYz8gGtMmQPYL79MHES3G/OobnKD1hrCayZooMPfGvr PzGvqFdmOm6o/4SQmSrFfZA= Received: (qmail 32659 invoked by alias); 17 May 2013 15:51:29 -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 32645 invoked by uid 89); 17 May 2013 15:51:27 -0000 X-Spam-SWARE-Status: No, score=-7.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS, TW_CP autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 17 May 2013 15:51:26 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4HFpPIX018558 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 17 May 2013 11:51:25 -0400 Received: from stumpy.slc.redhat.com (ovpn-113-177.phx2.redhat.com [10.3.113.177]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r4HFpPD4013782 for ; Fri, 17 May 2013 11:51:25 -0400 Message-ID: <519651FC.9040901@redhat.com> Date: Fri, 17 May 2013 09:51:24 -0600 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130402 Thunderbird/17.0.5 MIME-Version: 1.0 To: gcc-patches Subject: [PATCH] [tree-optimization/57124] Updated fix for 254.gap problems X-Virus-Found: No As I believe I pointed out in a follow-up message, 254.gap is depending on signed overflow semantics. This patch avoids eliminating a cast feeding a conditional when the SSA_NAME's range has overflowed unless -fstrict-overflow is in effect. Thus 254.gap should be building with -fno-strict-overflow. This patch also introduces a warning when the optimization is applied and the ranges have overflowed. Bootstrapped and regression tested on x86-unknown-linux-gnu. OK for the trunk? commit 62bbaa8de0e8d929eb3c63331b47950e9b09d801 Author: Jeff Law Date: Wed May 1 12:33:20 2013 -0600 PR tree-optimization/57124 * tree-vrp.c (simplify_cond_using_ranges): Only simplify a conversion feeding a condition if the range has an overflow if -fstrict-overflow. Add warnings for when we do make the transformation. PR tree-optimization/57124 * gcc.c-torture/execute/pr57124.c: New test. * gcc.c-torture/execute/pr57124.x: Set -fno-strict-overflow. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8e92c44..9320f21 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2013-05-17 Jeff Law + + PR tree-optimization/57124 + * tree-vrp.c (simplify_cond_using_ranges): Only simplify a + conversion feeding a condition if the range has an overflow + if -fstrict-overflow. Add warnings for when we do make the + transformation. + 2013-05-16 Rainer Orth * reorg.c (link_cc0_insns): Wrap in #ifdef HAVE_cc0. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 879b9bc..482151c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2013-05-17 Jeff Law + + PR tree-optimization/57124 + * gcc.c-torture/execute/pr57124.c: New test. + * gcc.c-torture/execute/pr57124.x: Set -fno-strict-overflow. + 2013-05-16 Greta Yorsh * gcc.target/arm/unaligned-memcpy-2.c: Adjust expected output. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr57124.c b/gcc/testsuite/gcc.c-torture/execute/pr57124.c new file mode 100644 index 0000000..835d249 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr57124.c @@ -0,0 +1,27 @@ +__attribute__ ((noinline)) +foo(short unsigned int *p1, short unsigned int *p2) +{ + short unsigned int x1, x4; + int x2, x3, x5, x6; + unsigned int x7; + + x1 = *p1; + x2 = (int) x1; + x3 = x2 * 65536; + x4 = *p2; + x5 = (int) x4; + x6 = x3 + x4; + x7 = (unsigned int) x6; + if (x7 <= 268435455U) + abort (); + exit (0); +} + +main() +{ + short unsigned int x, y; + x = -5; + y = -10; + foo (&x, &y); +} + diff --git a/gcc/testsuite/gcc.c-torture/execute/pr57124.x b/gcc/testsuite/gcc.c-torture/execute/pr57124.x new file mode 100644 index 0000000..d8cacbe --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr57124.x @@ -0,0 +1,2 @@ +set additional_flags "-fno-strict-overflow" +return 0 diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index b5de683..b3eccf0 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -8669,8 +8669,32 @@ simplify_cond_using_ranges (gimple stmt) && range_fits_type_p (vr, TYPE_PRECISION (TREE_TYPE (op0)), TYPE_UNSIGNED (TREE_TYPE (op0))) - && int_fits_type_p (op1, TREE_TYPE (innerop))) + && int_fits_type_p (op1, TREE_TYPE (innerop)) + /* The range must not have overflowed, or if it did overflow + we must not be wrapping/trapping overflow and optimizing + with strict overflow semantics. */ + && ((!is_negative_overflow_infinity (vr->min) + && !is_positive_overflow_infinity (vr->max)) + || (!flag_wrapv && !flag_trapv && flag_strict_overflow))) { + /* If the range overflowed and the user has asked for warnings + when strict overflow semantics were used to optimize code, + issue an appropriate warning. */ + if ((is_negative_overflow_infinity (vr->min) + || is_positive_overflow_infinity (vr->max)) + && issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_CONDITIONAL)) + { + location_t location; + + if (!gimple_has_location (stmt)) + location = input_location; + else + location = gimple_location (stmt); + warning_at (location, OPT_Wstrict_overflow, + "assuming signed overflow does not occur when " + "simplifying conditional."); + } + tree newconst = fold_convert (TREE_TYPE (innerop), op1); gimple_cond_set_lhs (stmt, innerop); gimple_cond_set_rhs (stmt, newconst);