From patchwork Wed Apr 12 16:58:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 82577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp473789vqo; Wed, 12 Apr 2023 09:59:12 -0700 (PDT) X-Google-Smtp-Source: AKy350bVbYjMuiNXn87Zyls2cXZPZGUJ9UpJzAFvq51iCL3rODnEPkpolABqs+tmHNLU0KxqpHRV X-Received: by 2002:a17:906:4b14:b0:93f:9594:d97d with SMTP id y20-20020a1709064b1400b0093f9594d97dmr6558048eju.14.1681318752598; Wed, 12 Apr 2023 09:59:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318752; cv=none; d=google.com; s=arc-20160816; b=TOe5E2lEB9KviYujXpGFBiBAfYBrRHn+RS06u0uGjNX7GnA4LuuDRS7H3wQ1CI3Zdi IQHVZS58qo/3CJVRVhp+hcVOdOX3WrQOBIPepSN9DnjdFoE8niWLrO+hAdA5Qk5QmdBj M7xHHrzfpjQUCbIUY9YaFGPyc023ope9zVXzHnEsOuV4cUkSkosChASxUqLYX2mVMoj7 uhS0DQkMIycf75NPN9DFsGfkgOTpxwiqs6LPcVrVHjgrelxcwAgqSnn0Arw/3Zn/lter JQ+Qsr6vtpv/HhndswkTENidSOmn9zDpCo+afaJjE8VaNF+2YmwfwppE6aRO/d/GM1/I biAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:in-reply-to:mime-version:references:message-id :subject:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=KXD7RfOLGI9aWoevdJKOrY4CQ8DOcbETYLXlVGsuuqk=; b=1EePeTI8EzZ+yShezekIj7x9XwnjB020INP5xRSWj7j0qmzX3DX+es9kymj+CKRie+ bB84VHArr/wvAGydWAQgt1T2CxfD1Aolv/8xwCJ+Zlpi+KcS1pCfEhZxZzvAKjwB3aAW kPJtIEDsbYhZ5Iv/2VYB/MHpyTHxi90q+NFs/p14Pj6WHPpwP5n+hZ9/P6ttMP/Q6WOO 87kdWyFUDIS79g47nMqz0Th41dALyKp/jlVyoRw/86L2V9/ImGlEOueym57IIRIsHSnw SI83oRFlqvPm1iMhL7KEgQCnyZfM9aqh4qo9rVUR41GnqwAidk9r5X+N18z8zrupNrnc qhTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qETKZaUH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hu16-20020a170907a09000b00932987332c3si2233214ejc.431.2023.04.12.09.59.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:59:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qETKZaUH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6B6A23857707 for ; Wed, 12 Apr 2023 16:59:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B6A23857707 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681318746; bh=KXD7RfOLGI9aWoevdJKOrY4CQ8DOcbETYLXlVGsuuqk=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qETKZaUHdklj3xK8kTUOtbUqwmXqVqVneZTxUAxIGmYQyZ2sUdc0GUtib6SMAHoer iGSLKhOAs5bXV8b1Sa47R+YdhhgK8DABlzzD0dpBIpT3QmRuBbS5yHG+K+/NrTXjPU 8b7KGP57qmxrwCSHDbup3iL2nPgdq73dY11Ivil8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 718643858D28 for ; Wed, 12 Apr 2023 16:58:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 718643858D28 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-269-lekl_-D0MgCCh8KCDm7pkA-1; Wed, 12 Apr 2023 12:58:18 -0400 X-MC-Unique: lekl_-D0MgCCh8KCDm7pkA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5CDBE101A550; Wed, 12 Apr 2023 16:58:18 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 157DC492C14; Wed, 12 Apr 2023 16:58:17 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 33CGwEAL3889029 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 12 Apr 2023 18:58:14 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 33CGwBQS3889027; Wed, 12 Apr 2023 18:58:11 +0200 Date: Wed, 12 Apr 2023 18:58:11 +0200 To: Segher Boessenkool , Jeff Law , Eric Botcazou , gcc-patches@gcc.gnu.org, Richard Biener , Richard Sandiford Subject: [PATCH] combine, v4: Fix AND handling for WORD_REGISTER_OPERATIONS targets [PR109040] Message-ID: References: <2220543.iZASKD2KPV@fomalhaut> <3412470.QJadu78ljV@fomalhaut> <8d3c3861-c291-e762-a2a8-0b520f39a7e3@gmail.com> <965831db-ac9e-cc5e-3459-08b6b70fd577@gmail.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990492189716756?= X-GMAIL-MSGID: =?utf-8?q?1762990492189716756?= On Wed, Apr 12, 2023 at 12:02:12PM +0200, Jakub Jelinek via Gcc-patches wrote: > I've tried the pr108947.c testcase, but I see no differences in the assembly > before/after the patch (but dunno if I'm using the right options). > The pr109040.c testcase from the patch I don't see the expected zero > extension without the patch and do see it with it. Seems my cross defaulted to 32-bit compilation, reproduced it with additional -mabi=lp64 -march=rv64gv even on the pr108947.c test. So, let's include that test in the patch too: 2023-04-12 Jeff Law Jakub Jelinek PR target/108947 PR target/109040 * combine.cc (simplify_and_const_int_1): Compute nonzero_bits in word_mode rather than mode if WORD_REGISTER_OPERATIONS and mode is smaller than word_mode. * simplify-rtx.cc (simplify_context::simplify_binary_operation_1) : Likewise. * gcc.dg/pr108947.c: New test. * gcc.c-torture/execute/pr109040.c: New test. Jakub --- gcc/combine.cc.jj 2023-04-07 16:02:06.668051629 +0200 +++ gcc/combine.cc 2023-04-12 11:24:18.458240028 +0200 @@ -10055,9 +10055,12 @@ simplify_and_const_int_1 (scalar_int_mod /* See what bits may be nonzero in VAROP. Unlike the general case of a call to nonzero_bits, here we don't care about bits outside - MODE. */ + MODE unless WORD_REGISTER_OPERATIONS is true. */ - nonzero = nonzero_bits (varop, mode) & GET_MODE_MASK (mode); + scalar_int_mode tmode = mode; + if (WORD_REGISTER_OPERATIONS && GET_MODE_BITSIZE (mode) < BITS_PER_WORD) + tmode = word_mode; + nonzero = nonzero_bits (varop, tmode) & GET_MODE_MASK (tmode); /* Turn off all bits in the constant that are known to already be zero. Thus, if the AND isn't needed at all, we will have CONSTOP == NONZERO_BITS @@ -10071,7 +10074,7 @@ simplify_and_const_int_1 (scalar_int_mod /* If VAROP is a NEG of something known to be zero or 1 and CONSTOP is a power of two, we can replace this with an ASHIFT. */ - if (GET_CODE (varop) == NEG && nonzero_bits (XEXP (varop, 0), mode) == 1 + if (GET_CODE (varop) == NEG && nonzero_bits (XEXP (varop, 0), tmode) == 1 && (i = exact_log2 (constop)) >= 0) return simplify_shift_const (NULL_RTX, ASHIFT, mode, XEXP (varop, 0), i); --- gcc/simplify-rtx.cc.jj 2023-03-02 19:09:45.459594212 +0100 +++ gcc/simplify-rtx.cc 2023-04-12 11:26:26.027400305 +0200 @@ -3752,7 +3752,13 @@ simplify_context::simplify_binary_operat return op0; if (HWI_COMPUTABLE_MODE_P (mode)) { - HOST_WIDE_INT nzop0 = nonzero_bits (trueop0, mode); + /* When WORD_REGISTER_OPERATIONS is true, we need to know the + nonzero bits in WORD_MODE rather than MODE. */ + scalar_int_mode tmode = as_a (mode); + if (WORD_REGISTER_OPERATIONS + && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD) + tmode = word_mode; + HOST_WIDE_INT nzop0 = nonzero_bits (trueop0, tmode); HOST_WIDE_INT nzop1; if (CONST_INT_P (trueop1)) { --- gcc/testsuite/gcc.dg/pr108947.c.jj 2023-04-12 18:54:13.115630365 +0200 +++ gcc/testsuite/gcc.dg/pr108947.c 2023-04-12 18:53:21.166372386 +0200 @@ -0,0 +1,21 @@ +/* PR target/108947 */ +/* { dg-do run } */ +/* { dg-options "-O2 -fno-forward-propagate -Wno-psabi" } */ + +typedef unsigned short __attribute__((__vector_size__ (2 * sizeof (short)))) V; + +__attribute__((__noipa__)) V +foo (V v) +{ + V w = 3 > (v & 3992); + return w; +} + +int +main () +{ + V w = foo ((V) { 0, 9 }); + if (w[0] != 0xffff || w[1] != 0) + __builtin_abort (); + return 0; +} --- gcc/testsuite/gcc.c-torture/execute/pr109040.c.jj 2023-04-12 11:11:56.728938344 +0200 +++ gcc/testsuite/gcc.c-torture/execute/pr109040.c 2023-04-12 11:11:56.728938344 +0200 @@ -0,0 +1,23 @@ +/* PR target/109040 */ + +typedef unsigned short __attribute__((__vector_size__ (32))) V; + +unsigned short a, b, c, d; + +void +foo (V m, unsigned short *ret) +{ + V v = 6 > ((V) { 2124, 8 } & m); + unsigned short uc = v[0] + a + b + c + d; + *ret = uc; +} + +int +main () +{ + unsigned short x; + foo ((V) { 0, 15 }, &x); + if (x != (unsigned short) ~0) + __builtin_abort (); + return 0; +}