From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 86430 invoked by alias); 28 Apr 2016 16:30:29 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 85906 invoked by uid 89); 28 Apr 2016 16:30:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=1 X-HELO: mail-yw0-f176.google.com Received: from mail-yw0-f176.google.com (HELO mail-yw0-f176.google.com) (209.85.161.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 28 Apr 2016 16:30:01 +0000 Received: by mail-yw0-f176.google.com with SMTP id j74so112729617ywg.1 for ; Thu, 28 Apr 2016 09:30:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=DmDXW89Tn6P6wnNTu/RWuILFTQmw/W2f26ND9DxERs0=; b=GCB4N8p0nMHQWxodjshq7E/imhhbnABBL87NSx2NXixdaWiPScyfjpOKVB0hWIjPY5 uap58WKfXZcW5huBX8u47ntpMLuthSwfcghDQmSjtwrMoNhqGKGRU/6m4P6HyN/OXAHp iI43R+oVafrSHDjWCI+mMpcsU4LKTp8g/Q6Ti83tR8qQZcvHE5oVeaWCtbyISCurYs8m azWhNXHNNKQUfBNgQfb+Vkmr0exKzmgPq5tAD/2Ezsd8+n6izqNDknL2F8PSyqcaSuaB s/vLUuZEQt/Dh9/fxmgWBh/ILOIweSePgaYfOY3dSIN6NPkGil3CjjKpc6SRrQGuDX1I Bd3Q== X-Gm-Message-State: AOPr4FWY7f7wXET7pKWpFmCEr1f/6pqnlIxNhdRZZUOXcP96omzxZq5bQAz7Lb3WdKgnDfSqT+4MwAtcR/vsqQ== MIME-Version: 1.0 X-Received: by 10.176.64.104 with SMTP id h95mr8271204uad.84.1461860999255; Thu, 28 Apr 2016 09:29:59 -0700 (PDT) Received: by 10.103.76.220 with HTTP; Thu, 28 Apr 2016 09:29:59 -0700 (PDT) In-Reply-To: <20160428154237.GS26501@tucnak.zalov.cz> References: <20160428154237.GS26501@tucnak.zalov.cz> Date: Thu, 28 Apr 2016 16:30:00 -0000 Message-ID: Subject: Re: [PATCH] Add peephole for -Os lock; dec (PR target/70821) From: Uros Bizjak To: Jakub Jelinek Cc: Kirill Yukhin , "gcc-patches@gcc.gnu.org" Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2016-04/txt/msg01867.txt.bz2 On Thu, Apr 28, 2016 at 5:42 PM, Jakub Jelinek wrote: > Hi! > > Optimizing atomic_fetch_add followed by comparison into just testing > the flags of the lock; sub is handled by a peephole2, which works usually > fine, except that for -Os we have another peephole2 that transforms > movl $-1, %reg into orl $-1, %reg and that causes the above mentioned > peephole2 not to trigger anymore. > > Fixed by adding a peephole2 even for this case. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2016-04-28 Jakub Jelinek > > PR target/70821 > * config/i386/sync.md (define_peephole2 *atomic_fetch_add_cmp): > Add new peephole2 where the first insn is *mov_or instead of > *mov_internal. > > * gcc.target/i386/pr70821.c: New test. OK. Thanks, Uros. > > --- gcc/config/i386/sync.md.jj 2016-01-04 14:55:56.000000000 +0100 > +++ gcc/config/i386/sync.md 2016-04-28 09:40:28.265764880 +0200 > @@ -467,6 +467,36 @@ (define_peephole2 > (plus:SWI (match_dup 1) > (match_dup 2)))])]) > > +;; Likewise, but for the -Os special case of *mov_or. > +(define_peephole2 > + [(parallel [(set (match_operand:SWI 0 "register_operand") > + (match_operand:SWI 2 "constm1_operand")) > + (clobber (reg:CC FLAGS_REG))]) > + (parallel [(set (match_dup 0) > + (unspec_volatile:SWI > + [(match_operand:SWI 1 "memory_operand") > + (match_operand:SI 4 "const_int_operand")] > + UNSPECV_XCHG)) > + (set (match_dup 1) > + (plus:SWI (match_dup 1) > + (match_dup 0))) > + (clobber (reg:CC FLAGS_REG))]) > + (set (reg:CCZ FLAGS_REG) > + (compare:CCZ (match_dup 0) > + (match_operand:SWI 3 "const_int_operand")))] > + "peep2_reg_dead_p (3, operands[0]) > + && (unsigned HOST_WIDE_INT) INTVAL (operands[2]) > + == -(unsigned HOST_WIDE_INT) INTVAL (operands[3]) > + && !reg_overlap_mentioned_p (operands[0], operands[1])" > + [(parallel [(set (reg:CCZ FLAGS_REG) > + (compare:CCZ > + (unspec_volatile:SWI [(match_dup 1) (match_dup 4)] > + UNSPECV_XCHG) > + (match_dup 3))) > + (set (match_dup 1) > + (plus:SWI (match_dup 1) > + (match_dup 2)))])]) > + > (define_insn "*atomic_fetch_add_cmp" > [(set (reg:CCZ FLAGS_REG) > (compare:CCZ > --- gcc/testsuite/gcc.target/i386/pr70821.c.jj 2016-04-28 09:56:06.239893613 +0200 > +++ gcc/testsuite/gcc.target/i386/pr70821.c 2016-04-28 09:55:23.000000000 +0200 > @@ -0,0 +1,16 @@ > +/* PR target/70821 */ > +/* { dg-do compile } */ > +/* { dg-options "-Os" } */ > +/* { dg-additional-options "-march=i686" { target ia32 } } */ > + > +void bar (void); > + > +void > +foo (int *p) > +{ > + if (__atomic_sub_fetch (p, 1, __ATOMIC_SEQ_CST)) > + bar (); > +} > + > +/* { dg-final { scan-assembler "lock;? dec" } } */ > +/* { dg-final { scan-assembler-not "lock;? xadd" } } */ > > Jakub