From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id C839C3858C78 for ; Thu, 8 Feb 2024 05:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C839C3858C78 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C839C3858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707370574; cv=none; b=THHW+4IqZ/+lf3V1msZmr0T2Jz2kAL6bTseL66kietVGYgkVjcwyHNUHIsOBubN0HJqhm5P3nRhppx0h7nXjbS88Z23/MgSM94togber5vMAe5cFjjFhjDm6ufUkoGgneZdnoy/62eYPD+nxw1YTPNCh+69T0tSONXA27boT9F4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707370574; c=relaxed/simple; bh=Jl8gEoL+eeFOgCTMhviu1D/+WOvH6wdU9VqnFH+zi/g=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=t4Hzi+fr4B0ResfNS5JsMzdtLCZZ/lRHzkyurmbeRq0yMh6DoafPEVXW/B8RQEvmaf9xTELxLTtR4nxqwHWHNbxeUp9AweWZLB4uC9JeMq5Vl1PYXsf6dMky4pGf4WT/3/SquHAP2prDoJUVWrn0M6ZagZx3G1SqM2V7sBfyXVs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6e055c89dd9so451394b3a.1 for ; Wed, 07 Feb 2024 21:36:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1707370563; x=1707975363; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=oy0VuqVB2QNJShyLzPwGmONu2iroJNLxOD5l9ySFxHg=; b=ad2pVm2MrNPzeBCj2csUnPx1RZb5i8jZWWD5KNCpRAcaoihS7QB+trHUFtH8QWV58W BdU71TuqGYtUG4BpaPilJN4nxEkt+lT9/pLLZYcuTgbAQQVy7+XuxGQGeRAGwsbAk0c/ 0NL/ySFGy9rq/1BwQ5ma4cBXrRq1i8K8gw7/5rGC8nfkjkcMCihlYGE/0r6S6M9VxqRE pRUaRa4kwBaxw5Vw0+tVwonDnNRMVtisg4ASTkVceT2USitoubFsPpliuYgDaubOP7pJ UTZgHl/Z9mLfJy9juxKCYW+6RNBGugX8V8gX+jnMCI3krl573BGD5uzCwB+90cEuB6aW g3ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707370563; x=1707975363; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oy0VuqVB2QNJShyLzPwGmONu2iroJNLxOD5l9ySFxHg=; b=iEnbyYEEQz4xIjKxUMIcxMjdyyzrncjcZ32wCY18ES+3ZrvlkGFwLml/iV9CNd0/GQ W9vLgKMdLZezXcjo2qYdA9Ew30CfINUHXsxPHYtPUwxKPKk9WCFsw2EzhcyhJ1w/PDxk bMospWmUTp9W2MQ86b/xsEUtVjPO/L6mNea33jg2y4KGf9EXWpznvdqZbfe2kimS4VZF nuEaffVjDcD3LHQWxS2ii2FRxf+ifBntZx7bbKlrmWj7Wwdbr2ptjcdp9lt9zk4G8ptG hpI2OELtGtX2YfvBGP02M1CQuqLAqYBnOkCmCsqq5LSIjxMUovUmklTGVBLy653q187T d/2Q== X-Gm-Message-State: AOJu0YyW/RtL07X8KrQ9arzoq/1/LtspZXqQxbUyDr2/NrqSXVmtm7PH Ey37AyPSKhDUXPHnwEzVUyVP4qL1tacMUGL8/4c5HcEzCIw8Znw2jCYzrSex5Y4= X-Google-Smtp-Source: AGHT+IHKwRI+9r0CN+eTCVfQDAOkcwFVTDehzOMEjgyDFz9Mcgxh9+puzJjJYbTTIXJ69HkdtFDncg== X-Received: by 2002:a05:6a00:21cf:b0:6e0:5fa8:a608 with SMTP id t15-20020a056a0021cf00b006e05fa8a608mr2464184pfj.7.1707370562595; Wed, 07 Feb 2024 21:36:02 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVJkpTjZbyp90rfad0z3fsUl9lOebi9nXWzWfVZPNssf2MlhHqSDE46LKLr7CkBxQkPXs23YcmAjBndT7FCTXmmdJFjDEVSZvmaCg== Received: from [192.168.0.2] (67-1-193-123.tcso.qwest.net. [67.1.193.123]) by smtp.gmail.com with ESMTPSA id ei49-20020a056a0080f100b006e042b50c39sm2780501pfb.144.2024.02.07.21.36.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Feb 2024 21:36:02 -0800 (PST) Message-ID: <96135e2f-c6c2-4504-932c-ca64af966fa8@rivosinc.com> Date: Wed, 7 Feb 2024 22:36:00 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] combine: Don't optimize SIGN_EXTEND of MEM on WORD_REGISTER_OPERATIONS targets [PR113010] To: Jeff Law , Richard Biener Cc: gcc-patches@gcc.gnu.org References: <20240116221914.267015-1-gkm@rivosinc.com> <03b351a0-a5f4-48ab-bc67-765eabf5dbcd@rivosinc.com> <3f212170-f555-4f78-aff9-2ebdb8d4cc78@rivosinc.com> <5c564b6d-b74e-4648-a4bd-cc70724863d2@gmail.com> Content-Language: en-US From: Greg McGary In-Reply-To: <5c564b6d-b74e-4648-a4bd-cc70724863d2@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,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 2/4/24 9:58 PM, Jeff Law wrote: > > On 2/2/24 15:48, Greg McGary wrote: >> >> input: (sign_extend:DI (mem/c:SI (symbol_ref:DI ("minus_1") [flags >> 0x86] ) [1 minus_1+0 S4 A32])) >> >> result: (subreg:DI (mem/c:SI (symbol_ref:DI ("minus_1") [flags 0x86] >> ) [1 minus_1+0 S4 A32]) 0) >> >> Later, the high part of the PSoM statically evaluates to 0, the code >> to load and test is elided, and the incorrect alternative is emitted >> unconditionally. > So I think we need to know where that high part gets statically turned > into a zero. > > I'm not happy with the sign_extend->subreg transformation as we > generally want to avoid (subreg (mem)) for various reasons.  So we'll > probably want to do something like your patch as well.   But let's > chase down the static evaluation of the high part to zero first -- > that's clearly wrong given the defined semantics of (subreg (mem)) in > the presence of LOAD_EXTEND_OP. This prevents the buggy evaluation. What think ye? diff --git a/gcc/combine.cc b/gcc/combine.cc index 812553c091e..736206242e1 100644 --- a/gcc/combine.cc +++ b/gcc/combine.cc @@ -12550,9 +12550,15 @@ simplify_comparison (enum rtx_code code, rtx *pop0, rtx *pop1)             }           /* If the inner mode is narrower and we are extracting the low part, -            we can treat the SUBREG as if it were a ZERO_EXTEND. */ +            we can treat the SUBREG as if it were a ZERO_EXTEND ...  */           if (paradoxical_subreg_p (op0)) -           ; +           { +             /* ... except we can't treat as ZERO_EXTEND when a machine +                automatically sign-extends loads. */ +             if (MEM_P (SUBREG_REG (op0)) && WORD_REGISTER_OPERATIONS +                 && load_extend_op (inner_mode) == SIGN_EXTEND) +               break; +           }           else if (subreg_lowpart_p (op0)                    && GET_MODE_CLASS (mode) == MODE_INT                    && is_int_mode (GET_MODE (SUBREG_REG (op0)), &inner_mode)