From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 0A75A3858D32 for ; Wed, 19 Oct 2022 02:09:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0A75A3858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pg1-x52b.google.com with SMTP id bh13so14952979pgb.4 for ; Tue, 18 Oct 2022 19:09:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; 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=k7sqJEQ/YdO276IDx9Oiy6VyfUgNFRL50b4ZtsmxCZc=; b=DbO5rZ3UnEVEr6M6wRU7zs1YnjAf6thijXZOT9HjIcg0GPtjBnPmeX4WNmoRpWL0Fc 8JE5xsUBg1bbByvyu3NSTPgzstTekAYeK0gb5mMdQ8x1/xcIKN/A/E/Vy/x9/2CZOKDm ngcq9QErh4rv93GP5WE/ttDi19GV5yziFCSIisVrHYGkCrLWja9ecIz5oz6TMhonEKlu hwZgRLlWe4S/89QqXRKuGG49m1mLRVdpbwZF8mmUJNAd98laj6FtM/hu7lYdqltLqAFF SQX/yh/KKmp6Pk19C2kgR/W+cVHGlNm/rR+u7YHgRlkKxBFqS96vHQ82vqwqczbiUOGi k89w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=k7sqJEQ/YdO276IDx9Oiy6VyfUgNFRL50b4ZtsmxCZc=; b=H+zYL6t5+j7w3RVWRjcq+wMXv+bOwcPFgcKsTEj/LdJ/Ueia6ja3e9/H+q6NRcZh/s bNiZFX9HL/4vfkNkIzeIMwcfzMpw4NnK61wzaL3r49G4vzlDzFB0tTRJOLPzQfr+64l6 KwiU10dUqd0ev8YSmKov5SIO5IFprChuzdt588nbzRt05DurN0V29XwGebdeswSZmF0N chfYSxiIEFqtE2yTKeASv76GSPtWjo44jRERIHlL4N/9yU7K8YMY4W0cr6gPhfVIFqug JlUhc+og47h9Nbb+SzllvzQLyPYAoHuEwsLPGJFXsxg4PBuVfIPOtFDMT19wy+CHEGJy JygA== X-Gm-Message-State: ACrzQf37ba9BePykcjoCTTHkfBH+muJb+DJTSj4icj+gLepOauSyVr1I EGBH2MGTu7t0edQRrsfLKXKCTw== X-Google-Smtp-Source: AMsMyM4o8gluxvxe3uvOjbelEt83jd3qdV6ebFcQunzvUzvdLWbDbOkKdqqtqGEtuyZanOzaubNO2w== X-Received: by 2002:a63:d54a:0:b0:454:395a:73d6 with SMTP id v10-20020a63d54a000000b00454395a73d6mr5177898pgi.531.1666145392893; Tue, 18 Oct 2022 19:09:52 -0700 (PDT) Received: from [192.168.50.116] (c-24-4-73-83.hsd1.ca.comcast.net. [24.4.73.83]) by smtp.gmail.com with ESMTPSA id 2-20020a620602000000b0052d4cb47339sm9923242pfg.151.2022.10.18.19.09.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Oct 2022 19:09:52 -0700 (PDT) Message-ID: Date: Tue, 18 Oct 2022 19:09:50 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: Redundant constants in coremark crc8 for RISCV/aarch64 (no-if-conversion) Content-Language: en-US To: Jeff Law , gcc@gcc.gnu.org Cc: Kito Cheng , Philipp Tomsich References: <1a636f1e-31be-1735-5d8f-649df3c5e018@gmail.com> <1e118c0c-5d9a-4fca-9fe9-12e2baa34019@rivosinc.com> <53dcbef4-7aef-5f63-9bd8-e11c614b0be8@gmail.com> From: Vineet Gupta In-Reply-To: <53dcbef4-7aef-5f63-9bd8-e11c614b0be8@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,NICE_REPLY_A,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no 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 10/18/22 16:36, Jeff Law wrote: >>> There isn't a great place in GCC to handle this right now.  If the >>> constraints were relaxed in PRE, then we'd have a chance, but >>> getting the cost model right is going to be tough. >> >> It would have been better (for this specific case) if loop unrolling >> was not being done so early. The tree pass cunroll is flattening it >> out and leaving for rest of the all tree/rtl passes to pick up the >> pieces and remove any redundancies, if at all. It obviously needs to >> be early if we are injecting 7x more instructions, but seems like a >> lot to unravel. > > Yup.  If that loop gets unrolled, it's going to be a mess.  It will > almost certainly make this problem worse as each iteration is going to > have a pair of constants loaded and no good way to remove them. Thats the original problem that I started this thread with. I'd snipped the disassembly as it would have been too much text but basically on RV, Coremark crc8 loop of const 8 iterations gets unrolled including extraneous 8 insns pairs to load the same constant - which is preposterous. Other arches side-step by using if-conversion / cond moves, latter currently WIP in RV International. x86 w/o if-convert seems OK since the const can be encoded in the xor insn. OTOH given that gimple/tree-pass cunroll is doing the culprit loop unrolling and introducing redundant const 8 times, can it ne addressed there somehow. tree_estimate_loop_size() seems to identify constant expression, not just an operand. Can it be taught to identify a "non-trivial const" and hoist/code-move the expression. Sorry just rambling here, most likely non-sense. > >> >> FWIW -fno-unroll-loops only seems to work at -O2. At -O3 it always >> unrolls. Is that expected ? > > The only case I'm immediately aware of where this wouldn't work would > be if -O3 came after -fno-unroll-oops. Weird that gcc-12, gcc-11, gcc-10 all seem to be silently ignoring -funroll-loops despite following -O3. Perhaps a different toggle is needed to supress the issue. Thx, -Vineet