From patchwork Tue Sep 10 21:33:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 274075 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 did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 806B42C00C7 for ; Wed, 11 Sep 2013 07:33:58 +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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=hroXMHc6Y2n75XFYbGmdmyFPYn7Y5 sXsQpKkTwli8eWpQ/e2UI3ABMlxQsKd9ekVD0ccp6ZT15y0QRpvxUC04DDvgbSPm ziOmi82vyEEDIFU+bEPWByYIxucqk+M0bCZkX7GolW7BtHSCGjDRUMRFYLLjuSHF Sv4tOr2cnsoCCU= 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=n4UiAWcl2g+ph88QUk65tgzSdY8=; b=quI 7D7OLQZh3g8gN9aIQ2M+CTRFD7G8jLiz/GyexBFu64JC3WP3lPonwO+8W1yPLDbI WuMlxNfJ19ZKn8y8s/I6BGiMwFRx4PGMOECopMbyG4XruOsOO3Ddzvh9QSmPgHel 9XMic6YPUDzZdSrkaS+3wkUYNG+qm+3YuUr8/qeE= Received: (qmail 30214 invoked by alias); 10 Sep 2013 21:33:52 -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 30198 invoked by uid 89); 10 Sep 2013 21:33:51 -0000 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; Tue, 10 Sep 2013 21:33:51 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8ALXn3U028441 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 10 Sep 2013 17:33:49 -0400 Received: from tucnak.zalov.cz (vpn1-7-120.ams2.redhat.com [10.36.7.120]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r8ALXlYm023026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 10 Sep 2013 17:33:48 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id r8ALXkXB019207; Tue, 10 Sep 2013 23:33:47 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id r8ALXkNo019206; Tue, 10 Sep 2013 23:33:46 +0200 Date: Tue, 10 Sep 2013 23:33:46 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix build_range_check (PR tree-optimization/58385) Message-ID: <20130910213346.GK1817@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! If exp has side effects, for [-,-] ranges we would optimize them away. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.8? 2013-09-10 Jakub Jelinek PR tree-optimization/58385 * fold-const.c (build_range_check): If both low and high are NULL, use omit_one_operand_loc to preserve exp side-effects. * gcc.c-torture/execute/pr58385.c: New test. Jakub --- gcc/fold-const.c.jj 2013-09-09 11:32:39.000000000 +0200 +++ gcc/fold-const.c 2013-09-10 20:48:12.018170411 +0200 @@ -4299,7 +4299,7 @@ build_range_check (location_t loc, tree } if (low == 0 && high == 0) - return build_int_cst (type, 1); + return omit_one_operand_loc (loc, type, build_int_cst (type, 1), exp); if (low == 0) return fold_build2_loc (loc, LE_EXPR, type, exp, --- gcc/testsuite/gcc.c-torture/execute/pr58385.c.jj 2013-09-10 20:50:02.909589473 +0200 +++ gcc/testsuite/gcc.c-torture/execute/pr58385.c 2013-09-10 20:48:38.000000000 +0200 @@ -0,0 +1,21 @@ +/* PR tree-optimization/58385 */ + +extern void abort (void); + +int a, b = 1; + +int +foo () +{ + b = 0; + return 0; +} + +int +main () +{ + ((0 || a) & foo () >= 0) <= 1 && 1; + if (b) + abort (); + return 0; +}