From patchwork Wed Jul 8 15:03:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renlin Li X-Patchwork-Id: 492975 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 A6E4E1402B5 for ; Thu, 9 Jul 2015 01:04:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=j0BqzOuM; 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 :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=jhYMNRV9NSXv+qDRP34h0Lb4b2bxnUtu79YVl9hyMbh rXmFmrsr8gHtcwsTzr3olRUhxPKwQvuapzRVgijGKyopel7jzI2/vZ/gTDdhzruY WNwi8WzVnsKCoujRc+YH9/nwIX3gZpmKPVMQKBampxwMCzZvdrvzdB7SMy2kLvLM = 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:cc:subject:content-type; s=default; bh=IbK27G0Aa0YYUizw6JS0I0iSuOQ=; b=j0BqzOuMzXOr4+Ath emLNCgAxiW5hFOaZud0k94l+Qt8p+a23F9cMWh7B8VoQQMHTKDkh6zRKKtkPzcqF aMl/bviKY3axgtaW3v7DSSREVSYZViNKNUnSEK+hKs2SChZRaJ+LOFGQ8+n+3m/b ua2S2wdbpdss6/UCFMWv2LR1pk= Received: (qmail 110252 invoked by alias); 8 Jul 2015 15:03:56 -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 110202 invoked by uid 89); 8 Jul 2015 15:03:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 08 Jul 2015 15:03:52 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-25-LT6YlsmVRFaFFi6iAMQBZg-1; Wed, 08 Jul 2015 16:03:47 +0100 Received: from [10.2.207.43] ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 8 Jul 2015 16:03:46 +0100 Message-ID: <559D3BD3.1010808@arm.com> Date: Wed, 08 Jul 2015 16:03:47 +0100 From: Renlin Li User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: segher@gcc.gnu.org, Ramana Radhakrishnan Subject: [PATCH]Fix PR66556. Don't drop side-effect in simplify_const_relational_operation function. X-MC-Unique: LT6YlsmVRFaFFi6iAMQBZg-1 Hi all, In simplify_const_relational_operation function, there are cases a const rtx will be returned. Three cases are considered in this function: 1, comparisons with upper and lower bounds. 2, Integer comparisons with zero. 3, comparison of ABS with zero. It's fine to to the optimization if the operands have no side-effects. For example, I am currently fixing a code generation bug for armv7-a bigendian. It turns out that, the following rtx is simplified into a const, and the side-effect with it is ignored. (ltu:SI (lshiftrt:SI (subreg:SI (mem/c:HI (post_modify:SI (reg/f:SI 156) (plus:SI (reg/f:SI 156) (const_int 20 [0x14]))) [5 g+4 S2 A32]) 0) (const_int 1 [0x1])) (const_int -1 [0xffffffffffffffff])) ------------>>>>>>>>>>>>>>>>>> (const_int 1 [0x1]) This particular case falls into category 1 mentioned above. -1, when regarded as unsigned integer, is the largest unsigned integer. So the result is always a const_true_rtx in this case. However, the first operand of the comparison has POST_MODIFY side-effect. In this case, the simplifications should be checked against side-effect. x86_64 bootstrapping is Okay and arm-none-eabi regression test runs without any new issues. Okay to commit and backport to branch 5? Regards, Renlin Li gcc/ChangeLog: 2015-07-08 Renlin Li PR rtl/66556 * simplify-rtx.c (simplify_const_relational_operation): Add side_effects_p check. gcc/testsuite/ChangeLog: 2015-07-08 Renlin Li PR rtl/66556 * gcc.c-torture/execute/pr66556.c: New. diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index ca8310d..936a144 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -4930,7 +4930,8 @@ simplify_const_relational_operation (enum rtx_code code, /* Optimize comparisons with upper and lower bounds. */ if (HWI_COMPUTABLE_MODE_P (mode) - && CONST_INT_P (trueop1)) + && CONST_INT_P (trueop1) + && !side_effects_p (trueop0)) { int sign; unsigned HOST_WIDE_INT nonzero = nonzero_bits (trueop0, mode); @@ -5043,7 +5044,7 @@ simplify_const_relational_operation (enum rtx_code code, } /* Optimize integer comparisons with zero. */ - if (trueop1 == const0_rtx) + if (trueop1 == const0_rtx && !side_effects_p (trueop0)) { /* Some addresses are known to be nonzero. We don't know their sign, but equality comparisons are known. */ @@ -5094,7 +5095,7 @@ simplify_const_relational_operation (enum rtx_code code, } /* Optimize comparison of ABS with zero. */ - if (trueop1 == CONST0_RTX (mode) + if (trueop1 == CONST0_RTX (mode) && !side_effects_p (trueop0) && (GET_CODE (trueop0) == ABS || (GET_CODE (trueop0) == FLOAT_EXTEND && GET_CODE (XEXP (trueop0, 0)) == ABS))) diff --git a/gcc/testsuite/gcc.c-torture/execute/pr66556.c b/gcc/testsuite/gcc.c-torture/execute/pr66556.c new file mode 100644 index 0000000..f7acf1c --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr66556.c @@ -0,0 +1,52 @@ +/* { dg-do run } */ + +extern void abort (void); + +struct { + unsigned f2; + unsigned f3 : 15; + unsigned f5 : 3; + short f6; +} b = {0x7f8000, 6, 5, 0}, g = {8, 0, 5, 0}; + +short d, l; +int a, c, h = 8; +volatile char e[237] = {4}; +short *f = &d; +short i[5] = {3}; +char j; +int *k = &c; + +int +fn1 (unsigned p1) { return -p1; } + +void +fn2 (char p1) +{ + a = p1; + e[0]; +} + +short +fn3 () +{ + *k = 4; + return *f; +} + +int +main () +{ + + unsigned m; + short *n = &i[4]; + + m = fn1 ((h && j) <= b.f5); + l = m > g.f3; + *n = 3; + fn2 (b.f2 >> 15); + if ((a & 0xff) != 0xff) + abort (); + + return 0; +}