From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc36.google.com (mail-oo1-xc36.google.com [IPv6:2607:f8b0:4864:20::c36]) by sourceware.org (Postfix) with ESMTPS id 7ABE13858C78 for ; Tue, 19 Mar 2024 04:14:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7ABE13858C78 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7ABE13858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c36 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710821658; cv=none; b=TzZJJj/D48ya4T6vT4HW/c0Y8VNENNDBblMPGjd7guAMuaHnxkRI0d09uytG4C8iq37ajxF9mKN5/Cno+u/QwTnN2BApNb5zdNQGT20TaPylgulaJ4oegTSHJaoltmMdnQuEaSVEx1dr9XL0jY6yEDZb5yYyTU43/+Dnv1xvLBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710821658; c=relaxed/simple; bh=1ksPabLXkZwYYvnfx2PzuJsC1CVpFSYxb1sHphZSVCk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=V3vQUDqve7wcq2Wa9vD5jYCChxGsRBf5KttIOrOtMuTlDzYWF889t4BSuRPxiEpeCl6HP+yqT9F6sTExISjzH4/H0czdzD2EzufeI/9h+r76oHBl9lUHGmsd5b7Li4T2tHDh8+SNfWAhO1qCUw0+NdvvJUblZYG049hQTL/OiPw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-5a4789684abso2453389eaf.0 for ; Mon, 18 Mar 2024 21:14:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710821656; x=1711426456; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=+4++RMM35/8BdU0hpFPqlLRgKalPd6H22ZlEjsP8f/4=; b=RbUecA29tlgzdNAcW7KhzZpXYcZRfllSW45NB9rWIpPwd4+5n3h7TsqNIbTqPCV64v m5YoFKGkpd1pbLPrzB5yh5Yy7yg/5V1vrfKEI0pK6h10WP9GJgDigUgB/HkDzWDV6Vwr 95hj8qWhZsIPKpJvrF7GUj++ulDKJxaB+yaF94kALy+gZuU7k5inyDeH6NoMY3hq0IUC xFgZU6UqL33/U47OB733cOc4IsoumKhDNWp9qrw4wqn+kxrJ6ablnux/FE7CPHW+NtnD q9Uh1H57xLaKpkQL9zCZx5sPjc1TFyU6K0bk3iMgo/Rjx6kt3hzVwOM3CbXqOP39AnM4 z0+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710821656; x=1711426456; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+4++RMM35/8BdU0hpFPqlLRgKalPd6H22ZlEjsP8f/4=; b=Jhy+76npOOT4BLadR/vj/cryCFKds/HMZ0eTYZNOMT7A7rKsSggKPgDUeznWp7+wMf bjLu5eA14GBJE8ljhDBzgrGwY7QXCGQ/eHAbN5tj7ZCiVBgje5FcMsivXwOEBurfcYpO Sg0XJYwRx1JY6qvZpocgI5cJTHPD97ONvD6UWK/d2OOhD15n/P0Lc3LMs3V5KyksvC2I QxtI9OD/TyiDvXwkT/las2ZKb91ZFEd/8Pp1q1KLexbim7Pb6WL+NyYnv7Ken4uNyqkM sFkr2Va9Hcm6Hhn4hKcio0gaKXFqmeRhEvJaYL87dDnN2eCR6Zvli5igUraSibnf63P+ kF9g== X-Forwarded-Encrypted: i=1; AJvYcCWNB1wRIUFIfHX2f3oEiX1wNfuWCJYH4lFdcCtT5qyYMK3SIiodVoNnyPTBA/cOTC3bjwVGwWprP8XpOKT+oVjks2F5XlH/wQ== X-Gm-Message-State: AOJu0Yz00T8lFNC0haLDajDWXEI+04O/P8miWZZhk4Sc6hI49qqOqjC8 G/5nUMZfI6YgXaL0XOT5KarBMfxZ2Plfhf45uTkLRw7uVDo6bgsg X-Google-Smtp-Source: AGHT+IGlpCgBkUpR8dsm0wIT66XDwzDB4k9G/rnW8+PRfJb0TV+f2VDLMeG6mwH/tBj9SUH32Jy+dw== X-Received: by 2002:a05:6820:2981:b0:5a4:b8fb:1ed8 with SMTP id dq1-20020a056820298100b005a4b8fb1ed8mr1798873oob.7.1710821655643; Mon, 18 Mar 2024 21:14:15 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id m13-20020a4aedcd000000b005a47a6b8f67sm1835967ooh.29.2024.03.18.21.14.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Mar 2024 21:14:15 -0700 (PDT) Message-ID: <656a6d4f-04c6-46a7-9baf-0bcc7246daf0@gmail.com> Date: Mon, 18 Mar 2024 22:14:14 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [PATCH, RFC] combine: Don't truncate const operand of AND if it's no benefits Content-Language: en-US To: HAO CHEN GUI , gcc-patches Cc: Segher Boessenkool , David , "Kewen.Lin" , Peter Bergner References: From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.4 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 List-Id: On 3/10/24 11:41 PM, HAO CHEN GUI wrote: > Hi, > This patch tries to fix the problem when a canonical form doesn't benefit > on a specific target. The const operand of AND is and with the nonzero > bits of another operand in combine pass. It's a canonical form, but it's no > benefits for the target which has rotate and mask insns. As the mask is > truncated, it can't match the insn conditions which it originally matches. > For example, the following insn condition checks the sum of two AND masks. > When one of the mask is truncated, the condition breaks. > > (define_insn "*rotlsi3_insert_5" > [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r") > (ior:SI (and:SI (match_operand:SI 1 "gpc_reg_operand" "0,r") > (match_operand:SI 2 "const_int_operand" "n,n")) > (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,0") > (match_operand:SI 4 "const_int_operand" "n,n"))))] > "rs6000_is_valid_mask (operands[2], NULL, NULL, SImode) > && UINTVAL (operands[2]) != 0 && UINTVAL (operands[4]) != 0 > && UINTVAL (operands[2]) + UINTVAL (operands[4]) + 1 == 0" > ... > > This patch tries to fix the problem by comparing the rtx cost. If another > operand (varop) is not changed and rtx cost with new mask is not less than > the original one, the mask is restored to original one. > > I'm not sure if comparison of rtx cost here is proper. The outer code is > unknown and I suppose it as "SET". Also the rtx cost might not be accurate. > From my understanding, the canonical forms should always benefit as it can't > be undo in combine pass. Do we have a perfect solution for this kind of > issues? Looking forward for your advice. > > Another similar issues for canonical forms. Whether the widen mode for > lshiftrt is always good? > https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624852.html > > Thanks > Gui Haochen > > ChangeLog > Combine: Don't truncate const operand of AND if it's no benefits > > In combine pass, the canonical form is to turn off all bits in the constant > that are know to already be zero for AND. > > /* 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 > which is tested below. */ > > constop &= nonzero; > > But it doesn't benefit when the target has rotate and mask insert insns. > The AND mask is truncated and lost its information. Thus it can't match > the insn conditions. For example, the following insn condition checks > the sum of two AND masks. > > (define_insn "*rotlsi3_insert_5" > [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r") > (ior:SI (and:SI (match_operand:SI 1 "gpc_reg_operand" "0,r") > (match_operand:SI 2 "const_int_operand" "n,n")) > (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,0") > (match_operand:SI 4 "const_int_operand" "n,n"))))] > "rs6000_is_valid_mask (operands[2], NULL, NULL, SImode) > && UINTVAL (operands[2]) != 0 && UINTVAL (operands[4]) != 0 > && UINTVAL (operands[2]) + UINTVAL (operands[4]) + 1 == 0" > ... > > This patch restores the const operand of AND if the another operand is > not optimized and the truncated const operand doesn't save the rtx cost. > > gcc/ > * combine.cc (simplify_and_const_int_1): Restore the const operand > of AND if varop is not optimized and the rtx cost of the new const > operand is not reduced. > > gcc/testsuite/ > * gcc.target/powerpc/rlwimi-0.c: Reduced total number of insns and > adjust the number of rotate and mask insns. > * gcc.target/powerpc/rlwimi-1.c: Likewise. > * gcc.target/powerpc/rlwimi-2.c: Likewise. It seems like this should defer to gcc-15. jeff