From patchwork Sat Sep 6 10:28:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 386606 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 CE08C1400D7 for ; Sat, 6 Sep 2014 20:28:46 +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:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=Wzpe/OSST6O7RUoV5+fxzdUSxfx3xMnE59gsfyWoLjnxZHFxY4kFb A4+hVUU+480KlpRIRck3NjyvNTmjTWDzxvsqckPjc7tddKSLUDvr7my1Os2T6aIB 2Lt5RyqoHZtlWXiuQ1IR6dtoi0EYPIGrkFL3HThIMaOgQflaSotKtw= 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; s= default; bh=WGuaiV5TE+I+dFpJijAKVQP5XMM=; b=CGDyuudlpSocykyN6U0j rT91dny+n74NqklfW/AzxF38Wc11KVzAo52Zoxu4bpKq4j0+pEjqQyIPU3gDEfJm ItMutg+MO1Qs8ew/kT5jQnm7+yusrP0ssuDVbnarz3Ux+nqcp2zVu0ofgwgaLeH2 RKAXAiUT4jIJTeIMifYGME8= Received: (qmail 7418 invoked by alias); 6 Sep 2014 10:28:39 -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 7370 invoked by uid 89); 6 Sep 2014 10:28:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f47.google.com Received: from mail-wg0-f47.google.com (HELO mail-wg0-f47.google.com) (74.125.82.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 06 Sep 2014 10:28:33 +0000 Received: by mail-wg0-f47.google.com with SMTP id z12so12830645wgg.30 for ; Sat, 06 Sep 2014 03:28:30 -0700 (PDT) X-Received: by 10.194.71.136 with SMTP id v8mr20761057wju.38.1409999310078; Sat, 06 Sep 2014 03:28:30 -0700 (PDT) Received: from localhost ([2.25.234.45]) by mx.google.com with ESMTPSA id lh11sm4586120wic.17.2014.09.06.03.28.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Sep 2014 03:28:29 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, rdsandiford@googlemail.com Subject: RFA: PR62208: const0_rtx used for vectors in simplify-rtx.c Date: Sat, 06 Sep 2014 11:28:29 +0100 Message-ID: <87tx4lxctu.fsf@googlemail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 This PR is about a case where an XOR+EQ sequence can legitimately be simplified. The problem was that the sequence was operating on vectors while the simplified version used a 0 CONST_INT (const0_rtx). The code seems to have been like that for a long time but presumably the bug has been latent until now. I suppose normally we'd want earlier optimisations to catch this. Tested on x86_64-linux-gnu. OK to install? Thanks, Richard gcc/ PR rtl-optimization/62208 * simplify-rtx.c (simplify_relational_operation_1): Use CONST0_RTX rather than const0_rtx in eq/ne-xor simplifications. gcc/testsuite/ * gcc.target/i386/pr62208.c: New test. Index: gcc/simplify-rtx.c =================================================================== --- gcc/simplify-rtx.c 2014-09-06 11:05:20.859563557 +0100 +++ gcc/simplify-rtx.c 2014-09-06 11:05:20.935564244 +0100 @@ -4480,16 +4480,16 @@ simplify_relational_operation_1 (enum rt && op0code == XOR && rtx_equal_p (XEXP (op0, 0), op1) && !side_effects_p (XEXP (op0, 0))) - return simplify_gen_relational (code, mode, cmp_mode, - XEXP (op0, 1), const0_rtx); + return simplify_gen_relational (code, mode, cmp_mode, XEXP (op0, 1), + CONST0_RTX (mode)); /* Likewise (eq/ne (xor x y) y) simplifies to (eq/ne x 0). */ if ((code == EQ || code == NE) && op0code == XOR && rtx_equal_p (XEXP (op0, 1), op1) && !side_effects_p (XEXP (op0, 1))) - return simplify_gen_relational (code, mode, cmp_mode, - XEXP (op0, 0), const0_rtx); + return simplify_gen_relational (code, mode, cmp_mode, XEXP (op0, 0), + CONST0_RTX (mode)); /* (eq/ne (xor x C1) C2) simplifies to (eq/ne x (C1^C2)). */ if ((code == EQ || code == NE) Index: gcc/testsuite/gcc.target/i386/pr62208.c =================================================================== --- /dev/null 2014-09-03 21:33:59.721983712 +0100 +++ gcc/testsuite/gcc.target/i386/pr62208.c 2014-09-06 11:09:18.220708443 +0100 @@ -0,0 +1,23 @@ +/* { dg-options "-O3 -fwhole-program -march=x86-64" } */ + +int *a; +unsigned int b; + +void fn2 () +{ + int t[9]; + for (; b; b++) + *a ^= (~t[b] != t[b]); +} + +int fn1 () +{ + fn2 (); + return 0; +} + +int main () +{ + fn1 (); + return 0; +}