From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by sourceware.org (Postfix) with ESMTPS id 934D2385828E for ; Tue, 5 Jul 2022 08:24:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 934D2385828E Received: by mail-qt1-x830.google.com with SMTP id k14so12683684qtm.3 for ; Tue, 05 Jul 2022 01:24:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FXtKkLpeLH4xFJLk++jpUFpK/VLAvJSF83r8evMNyfQ=; b=0NUqlpqgp78ROi00zAA0TjgdJ4fw4IwJHY8UTL/DqRRJsdohqxDX/4QyT0ZKPqEV2V MCKZ5VXUxJlx4lnTAoKsrvMl3Q4MpdoPeH0g3As45opEkboJxT9hw7j3RlVVH3DRsBbu DCfJDwYKnY9gknXa4RI2E5wyRqimGuc89PTUQxvWij0hOzsy1gQfMv/6UJO5hIBq50u4 CElXoHmZue7lizZrkOG3kJIILfQeouEnCRmouTbO7U3FU+6gCaRWkSyai4vFU+aiWqdr J2Qaf1YVyl4HGl52VEyJrPsd8hng/6ILWvDzk5uZGv09WgoVbjkVbdP3+Xkjp6nlrtuJ 6urw== X-Gm-Message-State: AJIora8BAWSNp6uIr81WEyE5SCdgwsI7N6jzeMyhW5Y8ZkgN0zt/4xey 2fvcs53U9RNP5B5pKkcdbbhOQbb2q2rNNeaJj03zbMhT0cHiCA== X-Google-Smtp-Source: AGRyM1vIbMF9Sc9biGJwjdXVQjE3wveai/yNl3n31B8RqJ4giHV/6gLE+7KtZcrDdmyOuqlPPw0Gvmb/M40uTG8HdxU= X-Received: by 2002:a0c:c98f:0:b0:472:f002:4458 with SMTP id b15-20020a0cc98f000000b00472f0024458mr9923563qvk.31.1657009488773; Tue, 05 Jul 2022 01:24:48 -0700 (PDT) MIME-Version: 1.0 References: <00b501d88fd9$e89e6700$b9db3500$@nextmovesoftware.com> In-Reply-To: From: Uros Bizjak Date: Tue, 5 Jul 2022 10:24:37 +0200 Message-ID: Subject: Re: [x86 PATCH take #2] Doubleword version of and; cmp to not; test optimization. To: Roger Sayle Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jul 2022 08:24:51 -0000 On Tue, Jul 5, 2022 at 9:56 AM Uros Bizjak wrote: > > On Mon, Jul 4, 2022 at 9:11 PM Roger Sayle wrote: > > > > > > This patch is the latest revision of the patch originally posted at: > > https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596201.html > > > > This patch extends the earlier and;cmp to not;test optimization to also > > perform this transformation for TImode on TARGET_64BIT and DImode on -m32, > > One motivation for this is that it's a step to fixing the current failure > > of gcc.target/i386/pr65105-5.c on -m32. > > > > A more direct benefit for x86_64 is that the following code: > > > > int foo(__int128 x, __int128 y) > > { > > return (x & y) == y; > > } > > > > improves with -O2 from 15 instructions: > > > > movq %rdi, %r8 > > movq %rsi, %rax > > movq %rax, %rdi > > movq %r8, %rsi > > movq %rdx, %r8 > > andq %rdx, %rsi > > andq %rcx, %rdi > > movq %rsi, %rax > > movq %rdi, %rdx > > xorq %r8, %rax > > xorq %rcx, %rdx > > orq %rdx, %rax > > sete %al > > movzbl %al, %eax > > ret > > > > to the slightly better 13 instructions: > > > > movq %rdi, %r8 > > movq %rsi, %rax > > movq %r8, %rsi > > movq %rax, %rdi > > notq %rsi > > notq %rdi > > andq %rdx, %rsi > > andq %rcx, %rdi > > movq %rsi, %rax > > orq %rdi, %rax > > sete %al > > movzbl %al, %eax > > ret > > > > Now that all of the doubleword pieces are already in the tree, this > > patch is now much shorter (an rtx_costs improvement and a single new > > define_insn_and_split), however I couldn't resist including two very > > minor pattern naming tweaks/clean-ups to fix nits. > > > > This revised patch has been tested on x86_64-pc-linux-gnu with > > make bootstrap and make -k check, where on TARGET_64BIT there are > > no new failures, and on --target_board=unix{-m32} with a single new > > failure; the other dg-final in gcc.target/i386/pr65105-5.c now also > > fails (as that code diverges further from the expected vectorized > > output). This is progress as both FAILs in pr65105-5.c may now be > > fixed by changes localized to the STV pass. OK for mainline? > > > > > > 2022-07-04 Roger Sayle > > > > gcc/ChangeLog > > * config/i386/i386.cc (ix86_rtx_costs) : Provide costs > > for double word comparisons and tests (comparisons against zero). > > * config/i386/i386.md (*test_not_doubleword): Split DWI > > and;cmp into andn;cmp $0 as a pre-reload splitter. > > (*andn3_doubleword_bmi): Use instead of in name. > > (*3_doubleword): Likewise. > > > > gcc/testsuite/ChangeLog > > * gcc.target/i386/testnot-3.c: New test case. > > > > > +;; Split and;cmp (as optimized by combine) into andn;cmp $0 > +(define_insn_and_split "*test_not_doubleword" > + [(set (reg:CCZ FLAGS_REG) > + (compare:CCZ > + (and:DWI > + (not:DWI (match_operand:DWI 0 "nonimmediate_operand")) > + (match_operand:DWI 1 "nonimmediate_operand")) > + (const_int 0)))] > + "ix86_pre_reload_split ()" > + "#" > + "&& 1" > + [(parallel > + [(set (match_dup 2) (and:DWI (not:DWI (match_dup 0)) (match_dup 1))) > + (clobber (reg:CC FLAGS_REG))]) > + (set (reg:CCZ FLAGS_REG) (compare:CCZ (match_dup 2) (const_int 0)))] > { > + operands[0] = force_reg (mode, operands[0]); > operands[2] = gen_reg_rtx (mode); > }) > > I don't think we can count on a follow-up split to lower ANDN for > !TARGET_BMI case, it is also a pre-reload splitter. Actually, splitters *CAN* be chained: Splitting with gen_split_231 (i386.md:10408) scanning new insn with uid = 30. scanning new insn with uid = 31. deleting insn with uid = 12. Splitting with gen_split_235 (i386.md:10444) scanning new insn with uid = 32. scanning new insn with uid = 33. deleting insn with uid = 30. Splitting with gen_split_2 (i386.md:1510) scanning new insn with uid = 34. scanning new insn with uid = 35. scanning new insn with uid = 36. scanning new insn with uid = 37. deleting insn with uid = 31. deleting insn with uid = 12. INSNs are recognized after they are split. The patch is OK as is. Thanks, Uros.