From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by sourceware.org (Postfix) with ESMTPS id 285D13858D32 for ; Mon, 4 Sep 2023 23:16:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 285D13858D32 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-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-26f3e26e55aso1016149a91.3 for ; Mon, 04 Sep 2023 16:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693869379; x=1694474179; 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=r5Xz1THSlOWFSUQmP/vczyIyyx2c+Q/ZFHWykeeTGEk=; b=KL9J8wElb8JNsVdABs7nEoftbpsNYwKkxWJYhVQHQbpR+L/vUFkMjl2yEyfw0kJJVE in1MDHHDyv3bta1aQ+Wc7C2LRdYil7O9PzVanQ3NmE+noVBXSogUQ9VBUyG63dBrLrUZ UDRbY6024llZ/VHeOj/WG8JpXEktRjqRLEARmXJQw1nZAe8dfNe/kjaUg8NG8kIRn3Jd hNDjLICv8IqCqM0EniUsG7U4y8vxNea/J0SdEBf+pwoGwovzmRjVqF4TUu1MJJy1PC9s NHr9XXeOrxBos2Bg8Jds8iAZVAa0za0vEgSjkgZFqHSJroX2QmuHCu5SCMznuTm13SMW nubw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693869379; x=1694474179; 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=r5Xz1THSlOWFSUQmP/vczyIyyx2c+Q/ZFHWykeeTGEk=; b=bmXSHw8K1Euo79wPNJdUWDP4ktRKc81rMHrQs4JC4O31/GKoqzSlxGQ/MM5hQm9RMp LuRmm+0bGNCLFAVWY6j6CmTw96HoGrd0dIDBAeHg6xVuF4l5gZJoOGfWpdnXv3/oCnv9 NVwyIGJG8pqKUej4Xp7WyXWzqa/QxaTdA/8vs5Jx0LZIo2AVmroYG47SweRiXdCZRC0s 1ztquxcDOOm5VG+DM2C1lX8ePTqqAcuadf4DAbNM+R02wjWKeAAC9z26qP5l5GJrTw+V zZC4Rl0Ggr01/l1g55rJt7bytpzc8S/W6uE9x5UawfxAa+umGlw0W6CLxBrZAx9upq72 hGPw== X-Gm-Message-State: AOJu0YxpGQOnMWw8EBrsS5JW9HhLA5QTYP+D/0StRBTYmYo2lLfSFwnO wIit8rxtLstAWan6McIG6QQ= X-Google-Smtp-Source: AGHT+IEqIbQg1srOEJNKAGSkpUhpOzQcm+/cUiMfehH0bpMzWLFAZ7Tj1clb/LwaOLn8OaRxh4GPYg== X-Received: by 2002:a17:90a:1117:b0:268:5e70:508a with SMTP id d23-20020a17090a111700b002685e70508amr8523510pja.43.1693869378960; Mon, 04 Sep 2023 16:16:18 -0700 (PDT) Received: from [172.31.0.109] ([136.36.130.248]) by smtp.gmail.com with ESMTPSA id iw9-20020a170903044900b001bc2831e1a8sm8040243plb.80.2023.09.04.16.16.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Sep 2023 16:16:18 -0700 (PDT) Message-ID: <629c9a26-a12e-46f8-b8aa-1d1f125cf116@gmail.com> Date: Mon, 4 Sep 2023 17:16:12 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] RISC-V: zicond: Fix opt2 pattern Content-Language: en-US To: Vineet Gupta , gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, Palmer Dabbelt , gnu-toolchain@rivosinc.com References: <20230901195311.761131-1-vineetg@rivosinc.com> From: Jeff Law In-Reply-To: <20230901195311.761131-1-vineetg@rivosinc.com> 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,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 List-Id: On 9/1/23 13:53, Vineet Gupta wrote: > This was tripping up gcc.c-torture/execute/pr60003.c at -O1 since in > failing case, pattern's asm czero.nez gets both rs2 and rs1 as non zero. > > We start with the following src code snippet: > > if (a == 0) > return 0; > else > return x; > } > > which is equivalent to: "x = (a != 0) ? x : a" where x is NOT 0. > ^^^^^^^^^^^^^^^^ > > and matches define_insn "*czero.nez..opt2" > > | (insn 41 20 38 3 (set (reg/v:DI 136 [ x ]) > | (if_then_else:DI (ne (reg/v:DI 134 [ a ]) > | (const_int 0 [0])) > | (reg/v:DI 136 [ x ]) > | (reg/v:DI 134 [ a ]))) {*czero.nez.didi.opt2} > > The corresponding asm pattern generates > czero.nez x, x, a ; %0, %2, %1 > > which implies > "x = (a != 0) ? 0 : a" > > clearly not what the pattern wants to do. > > Essentially "(a != 0) ? x : a" cannot be expressed with CZERO.nez if X > is not guaranteed to be 0. > > However this can be fixed with a small tweak > > "x = (a != 0) ? x : a" > > is same as > > "x = (a == 0) ? a : x" since middle operand is 0 when a == 0. > > which can be expressed with CZERO.eqz > > before fix after fix > ----------------- ----------------- > li a5,1 li a5,1 > ld a4,8(sp) ld a4,8(sp) # a4 is runtime non zero > czero.nez a0,a4,a5 # a0=0 NOK czero.eqz a0,a4,a5 # a0=a4!=0 OK > > The issue only happens at -O1 as at higher optimization levels, the > whole conditional move gets optimized away. > > This fixes 4 testsuite failues in a zicond build: > > FAIL: gcc.c-torture/execute/pr60003.c -O1 execution test > FAIL: gcc.dg/setjmp-3.c execution test > FAIL: gcc.dg/torture/stackalign/setjmp-3.c -O1 execution test > FAIL: gcc.dg/torture/stackalign/setjmp-3.c -O1 -fpic execution test > > gcc/ChangeLog: > * config/riscv/zicond.md: Fix op2 pattern. > > Fixes: 1d5bc3285e8a ("[committed][RISC-V] Fix 20010221-1.c with zicond") > Signed-off-by: Vineet Gupta OK. Still not sure why I didn't trip over it in my own testing (execute.exp runs pr60003.c), but regardless, glad to have it fixed. jeff