From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 15A8B3858CD1 for ; Thu, 20 Jul 2023 21:27:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 15A8B3858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-55b66ca1c80so692446a12.0 for ; Thu, 20 Jul 2023 14:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689888431; x=1690493231; 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=lIKo9EcCP0/EE0wsG7DngOpzd6LTmJmUdh4Z8P82NNQ=; b=D+OWsMCTuUFcP+OjE/RAlf3VzfB/g7wyse5ERksdoOKbVUoIQ5bj87tr2ThCg5UUAK PUnSByeDLyaPaAPjiI3mve+2o7FMRuRI1nFgy4NFE54ZVkfnjdcef4mIaExeEqm1v5dn mc7DJ55z534R8tMi5gwPQyle4p/n3FPklo4wIj9+opF/P7kS45G6nfQdwqyqwUrI0TND Ilyjcz1Tc2bBmIPxJC4gBq7sfMTlpnEfbXHQJ+viwNbsvzI9/WdeaIqh7vz+yv7/n79K yavfIAdP5XLjVXX4StZ4X8NoChFBV82Wa7S1i1rgFF0EjdwIQDMeUMaLMqXeA9Ko2LVX 9mlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689888431; x=1690493231; 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=lIKo9EcCP0/EE0wsG7DngOpzd6LTmJmUdh4Z8P82NNQ=; b=QYCElL6BUbV1sx3fJzK0Kaet2GJ9xuXOnOeeQGWXgx0KVQD/nKj1Ankn9/TFY4BZ7n 1nuNOaGlh0ya1gA7bp09w6TsnBtGne8M1k7Ic2xcOoVfeUrmLOYV0wsZcM1KlIJdzVQj y6elNaUm2QoTaHT7QMAZl4/Yez2G/I7xgcs0d+2RhGBzxpWFZswuE/Q9nTqL7JrucbNM Mllv1a8uAXodjpnnL2q+I6pVutjhco9rYcmfyxykxGxTC/LUtScJ1i+i2S0zrc7cn7Ce wZgray2IWc62zveCtjvXH3zGFwGIHGClHBWNN8OZHLyFUonYzU4xTNdeh36dDdv8Va40 vA1g== X-Gm-Message-State: ABy/qLawLpUzLL+YU8E2mjq2u1nVmeNaEky+Fl2uJe6lsUwFG7dDFne3 xVpafSNR6A8nYHl+dXxX18o= X-Google-Smtp-Source: APBJJlF17OXJMLPiXu/c3gfyjY38k6XRj2B9JtiU+4y4ZlemPV/dsNRbAUpM+G/JOKpM5GvPL+nvHQ== X-Received: by 2002:a05:6a20:144a:b0:133:d15c:b661 with SMTP id a10-20020a056a20144a00b00133d15cb661mr108043pzi.60.1689888430581; Thu, 20 Jul 2023 14:27:10 -0700 (PDT) Received: from [172.31.0.109] ([136.36.130.248]) by smtp.gmail.com with ESMTPSA id i17-20020a17090332d100b001b86dd825e7sm1882135plr.108.2023.07.20.14.27.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Jul 2023 14:27:09 -0700 (PDT) Message-ID: <514e6a6c-b357-f2ca-70ad-7af7cee6bfbe@gmail.com> Date: Thu, 20 Jul 2023 15:27:08 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH-1, combine] Don't widen shift mode when target has rotate/mask instruction on original mode [PR93738] Content-Language: en-US To: HAO CHEN GUI , gcc-patches Cc: Segher Boessenkool , David , "Kewen.Lin" , Peter Bergner References: <531959dd-1342-cbf1-054b-faf620907aea@linux.ibm.com> From: Jeff Law In-Reply-To: <531959dd-1342-cbf1-054b-faf620907aea@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,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 7/18/23 21:06, HAO CHEN GUI via Gcc-patches wrote: > Hi, > The shift mode will be widen in combine pass if the operand has a normal > subreg. But when the target already has rotate/mask/insert instructions on > the narrow mode, it's unnecessary to widen the mode for lshiftrt. As > the lshiftrt is commonly converted to rotate/mask insn, the widen mode > blocks it to be further combined to rotate/mask/insert insn. The PR93738 > shows the case. > > The lshiftrt:SI (subreg:SI (reg:DI)) is converted to > subreg:SI (lshiftrt:DI (reg:DI)) and fails to match rotate/mask pattern. > > Trying 13, 10 -> 14: > 13: r127:SI=r125:SI&0xfffffffffffff0ff > REG_DEAD r125:SI > 10: r124:SI=r129:DI#4 0>>0xc&0xf00 > REG_DEAD r129:DI > 14: r128:SI=r127:SI|r124:SI > > Failed to match this instruction: > (set (reg:SI 128) > (ior:SI (and:SI (reg:SI 125 [+-2 ]) > (const_int -3841 [0xfffffffffffff0ff])) > (and:SI (subreg:SI (zero_extract:DI (reg:DI 129) > (const_int 32 [0x20]) > (const_int 20 [0x14])) 4) > (const_int 3840 [0xf00])))) > Failed to match this instruction: > (set (reg:SI 128) > (ior:SI (and:SI (reg:SI 125 [+-2 ]) > (const_int -3841 [0xfffffffffffff0ff])) > (and:SI (subreg:SI (and:DI (lshiftrt:DI (reg:DI 129) > (const_int 12 [0xc])) > (const_int 4294967295 [0xffffffff])) 4) > (const_int 3840 [0xf00])))) > > If not widen the shift mode, it can be combined to rotate/mask/insert insn > as expected. > > Trying 13, 10 -> 14: > 13: r127:SI=r125:SI&0xfffffffffffff0ff > REG_DEAD r125:SI > 10: r124:SI=r129:DI#4 0>>0xc&0xf00 > REG_DEAD r129:DI > 14: r128:SI=r127:SI|r124:SI > REG_DEAD r127:SI > REG_DEAD r124:SI > Successfully matched this instruction: > (set (reg:SI 128) > (ior:SI (and:SI (reg:SI 125 [+-2 ]) > (const_int -3841 [0xfffffffffffff0ff])) > (and:SI (lshiftrt:SI (subreg:SI (reg:DI 129) 4) > (const_int 12 [0xc])) > (const_int 3840 [0xf00])))) > > > This patch adds a target hook to indicate if rotate/mask instructions are > supported on certain mode. If it's true, widen lshiftrt mode is skipped > and shift is done on original mode. > > The patch fixes the regression of other rs6000 test cases. They're listed > in the second patch. > > The patch passed regression test on Power Linux and x86 platforms. > > Thanks > Gui Haochen > > ChangeLog > combine: Not winden shift mode when target has rotate/mask instruction on > original mode > > To winden shift mode is unnecessary when target already has rotate/mask > instuctions on the original mode. It might blocks the further combine > optimization on the original mode. For instance, further combine the insns > to a rotate/mask/insert instruction on the original mode. > > This patch adds a hook to indicate if a target supports rotate/mask > instructions on the certain mode. If it returns true, the widen shift > mode will be skipped on lshiftrt. > > gcc/ > PR target/93738 > * combine.cc (try_widen_shift_mode): Skip to widen mode for lshiftrt > when the target has rotate/mask instructions on original mode. > * doc/tm.texi: Regenerate. > * doc/tm.texi.in (TARGET_HAVE_ROTATE_AND_MASK): Add. > * target.def (have_rotate_and_mask): New target hook. > * targhooks.cc (default_have_rotate_and_mask): New function. > * targhooks.h (default_have_rotate_and_mask): Declare. Wouldn't it make more sense to just try rotate/mask in the original mode before trying a shift in a widened mode? I'm not sure why we need a target hook here. jeff