combine: Don't simplify high part of paradoxical-SUBREG-of-MEM on machines that sign-extend loads [PR113010]
Message ID | 20240222205918.3871954-1-gkm@rivosinc.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp206129dyb; Thu, 22 Feb 2024 13:00:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXonnsaX54CQTSlT4uie1D4rLPr1PBn00uknawnxord83eKJmohw1pzjO4HfCu8Muv6Eu4KSlnlDGycyDIsNmyNQHn6xg== X-Google-Smtp-Source: AGHT+IEEHu8w/vl/25sr0g0MJo+8C2E8+0Mxru7L9MwryHumq5ts86EfY7lPtaZF5F7QS1HDWK/N X-Received: by 2002:ad4:5c64:0:b0:68f:b9b7:9c53 with SMTP id i4-20020ad45c64000000b0068fb9b79c53mr461211qvh.28.1708635623582; Thu, 22 Feb 2024 13:00:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708635623; cv=pass; d=google.com; s=arc-20160816; b=RNkuOpDRxV7CVk4LIwOpYGKxFa13xzUrf+L2MXX1hJ54hJ7O5qO9r0Q7Ommt6ZH4nk WwrJjmREF7E27MnhT+90fDiXiMigvpkdup9Ji/fdbdyaDcgeLhAIw+NHhxeZyIX6yoAM 5XxxnjbH7p2yD5FBSxIc9fRSNziZiWGIIEGtW0k+LpPKa+4Abun1bEWcS5FS1VKXysS0 30OKOGKTrGVqJsCcOEL+FJaPhAXrpVvHIpl3lcz1QRPcPfP8rsT1d6DRRCGLfqEo3yaN zpuDG5Qto0aq+ydIy7EHrDyEy5t/9Y7hKmo6FcKJsIwfilVqAzY//zSopwSYECnomnNS VZUg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=iFNYtwVMBIGobs/mPw2V7S1A3E+vwYW1JQfv4iQVOKQ=; fh=TT2UGic3SyrhPrntaWj5lO8yGR2kSdlEE+dehkLQj6k=; b=E3WHEx2IQNBJLxrI7yBQjWYUIsI7RtiSWoxLJKms8tHltYQ/dTBUU++5w1HLH/ajWb tXfmqd9BRIccykdSVnE4aEiJ+H7lEvrUQWu0VCUdxiWv5IWZNO+Q/Dcpmh9qX3eqVy6I eJYaw8xI0BTBdE1pGDzNnl2OwptHtxO0zNMEggjapJtkuxIwMHEfme5WTlpMgZVT2zu+ vC3+h2J+PRIl6nn2mE73IA/YmBuxatM8NB6PViu2THR3RYet5oMfyRNvRZB8T8r9Mt/i KKfkorfq426IapWrU9bzUa+h/u2xO7eNagayfiQ6xPXnIvlVKsO5O6luokM4UL2+Wpw0 8mjw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=cRYMkHxq; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id m12-20020a0562141bcc00b0068f305eed02si13638554qvc.67.2024.02.22.13.00.23 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:00:23 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=cRYMkHxq; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4577F3858C52 for <ouuuleilei@gmail.com>; Thu, 22 Feb 2024 21:00:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 6609C3858D39 for <gcc-patches@gcc.gnu.org>; Thu, 22 Feb 2024 20:59:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6609C3858D39 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 6609C3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::636 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708635572; cv=none; b=S3IDOYrePIH93smpaLJGLihFNh1gRgvXfSLN3ZZiS0TRtpgejuvjBShjciSUSsNGQ7+NIvVVwtpMWw2ZfytaH2mLrVb640/33A+c1UmH8UhREG0+EE1v6yAU0EA7QjtQVwQow3qT+SdtgFjfx9Q6yWGzmdSP9Opxql3/B+21uOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708635572; c=relaxed/simple; bh=6CElOFDGbEwaIV9wqMesmZ2GutVu6uNkb1oAVS+eK2U=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=HfNLdCvGUIT+P3y1c2yiTV94HKq0wRyMDFdr0jj1qNQZ3nNwq41xWEAeBm7rdL3u2dMBzgtKtLbZYGLAjtk6q6evc5rrFmoNNPMH7xzvyFuhbK4oKiGnucg6DU66+cYCSYhHn7ci1YWwNjs8Ku+7nhT8hUip7qrlkPpuX/sa8oA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1d731314e67so570695ad.1 for <gcc-patches@gcc.gnu.org>; Thu, 22 Feb 2024 12:59:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708635568; x=1709240368; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=iFNYtwVMBIGobs/mPw2V7S1A3E+vwYW1JQfv4iQVOKQ=; b=cRYMkHxq2xQAQAvdljcQndLazlz04mLJ04LuVvJBHN3W69/es2/DiBHb+ejJl/n2js AEfNT5FMe9XepGR47n++KE5v20JFstE5MuUG7VB0oBYy+xpYmTyz4zKm7TlhsvMGDNV1 AjJ1BvvDsq+VCfJ/kLa1Ss2SWFdwtb9APXYpYQgbFx0k3VzBkA3+7U827YGC2R53PYD5 l3HYSdnM5Z0VALnNXluBHtFuV2QE58t+nBVpliq0zyEmIs/NyQcANKExL2YuqS9/Gs8/ /pTGLmX3hTZotNzJ/vIFlCTnD/63CqMqCaaf1e0I5h0tBAf48eTPykZuRfQMWZlGNyRp LE1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708635568; x=1709240368; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iFNYtwVMBIGobs/mPw2V7S1A3E+vwYW1JQfv4iQVOKQ=; b=lUO9Zq2cNcaKCqltWmoDc/uRdXLieeRLyMPaBnQcDFRBkvY9san/l5X5RaCC98JIed OQR6Me7ailEpyinrghPiH9veY8L31fDFWPubnuEMxhigJXWcabzvtgluTZH3LBXzvabp jG6t6TjPAzc5XyWMKMNvogjWKRszHkwM0K6k0ZEVqml09ZDrZD52IcMs4m4ck9ER7BoQ az5njmOZm7ihN0YDPQ+f2t0zPrvHaaayiwphA119WnpqiDyXqal5Xpbl3fydbSlQEYuw xp/OFcMSLMYoxXLYKmfE5ene3MreVmPcl97haR7aHVjkbwcw2Ly9zGHDouqQw2jBdvcb Kz5w== X-Gm-Message-State: AOJu0YzH8scXdlM7827lV+Neo0gr7tAV7lKLKWGvV8wn/zKJrLqrM3QK F5R4m2z9kFPtc1l+rQ2MQs5Rrju9u2zn1ZC+MsryojwcqMcnLjDeJH1Z3pR1Oxa6WNfxHQv7q7O w X-Received: by 2002:a17:90a:3486:b0:299:398e:5cee with SMTP id p6-20020a17090a348600b00299398e5ceemr14795476pjb.13.1708635567902; Thu, 22 Feb 2024 12:59:27 -0800 (PST) Received: from gkm.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id rs11-20020a17090b2b8b00b0029a4db713b9sm1932801pjb.39.2024.02.22.12.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:59:27 -0800 (PST) From: Greg McGary <gkm@rivosinc.com> To: gcc-patches@gcc.gnu.org Cc: Greg McGary <gkm@rivosinc.com> Subject: [PATCH] combine: Don't simplify high part of paradoxical-SUBREG-of-MEM on machines that sign-extend loads [PR113010] Date: Thu, 22 Feb 2024 12:59:18 -0800 Message-Id: <20240222205918.3871954-1-gkm@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791634307848947943 X-GMAIL-MSGID: 1791634307848947943 |
Series |
combine: Don't simplify high part of paradoxical-SUBREG-of-MEM on machines that sign-extend loads [PR113010]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Greg McGary
Feb. 22, 2024, 8:59 p.m. UTC
The sign bit of a sign-extending load cannot be known until runtime, so don't attempt to simplify it in the combiner. 2024-02-22 Greg McGary <gkm@rivosinc.com> PR rtl-optimization/113010 * combine.cc (simplify_comparison): Don't simplify high part of paradoxical-SUBREG-of-MEM on machines that sign-extend loads * gcc.c-torture/execute/pr113010.c: New test. --- gcc/combine.cc | 10 ++++++++-- gcc/testsuite/gcc.c-torture/execute/pr113010.c | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr113010.c
Comments
On Thu, Feb 22, 2024 at 12:59:18PM -0800, Greg McGary wrote: > The sign bit of a sign-extending load cannot be known until runtime, > so don't attempt to simplify it in the combiner. > > 2024-02-22 Greg McGary <gkm@rivosinc.com> > > PR rtl-optimization/113010 > * combine.cc (simplify_comparison): Don't simplify high part > of paradoxical-SUBREG-of-MEM on machines that sign-extend loads > > * gcc.c-torture/execute/pr113010.c: New test. > --- > gcc/combine.cc | 10 ++++++++-- > gcc/testsuite/gcc.c-torture/execute/pr113010.c | 9 +++++++++ > 2 files changed, 17 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr113010.c > > 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; That doesn't feel sufficient. Like in the PR112758 patch, I believe for WORD_REGISTER_OPERATIONS you should treat it as a ZERO_EXTEND only if MEM_P (SUBREG_REG (op0)) && load_extend_op (inner_mode) == ZERO_EXTEND or if GET_MODE_PRECISION (inner_mode) is known to be >= BITS_PER_WORD. Jakub
On 2/22/24 2:08 PM, Jakub Jelinek wrote: > On Thu, Feb 22, 2024 at 12:59:18PM -0800, Greg McGary wrote: >> The sign bit of a sign-extending load cannot be known until runtime, >> so don't attempt to simplify it in the combiner. >> >> 2024-02-22 Greg McGary <gkm@rivosinc.com> >> >> PR rtl-optimization/113010 >> * combine.cc (simplify_comparison): Don't simplify high part >> of paradoxical-SUBREG-of-MEM on machines that sign-extend loads >> >> * gcc.c-torture/execute/pr113010.c: New test. >> --- >> gcc/combine.cc | 10 ++++++++-- >> gcc/testsuite/gcc.c-torture/execute/pr113010.c | 9 +++++++++ >> 2 files changed, 17 insertions(+), 2 deletions(-) >> create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr113010.c >> >> 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; > That doesn't feel sufficient. Like in the PR112758 patch, I believe > for WORD_REGISTER_OPERATIONS you should treat it as a ZERO_EXTEND only > if MEM_P (SUBREG_REG (op0)) && load_extend_op (inner_mode) == ZERO_EXTEND > or if GET_MODE_PRECISION (inner_mode) is known to be >= BITS_PER_WORD. > > Jakub The gist of your comment is that my patch was missing the test for width of inner_mode vs. BITS_PER_WORD. Here's a revision. Looks good to you? diff --git a/gcc/combine.cc b/gcc/combine.cc index 812553c091e..4626f2edae9 100644 --- a/gcc/combine.cc +++ b/gcc/combine.cc @@ -12550,9 +12550,17 @@ 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 do that for loads on machines + that don't automatically zero-extend loads. */ + if (WORD_REGISTER_OPERATIONS + && GET_MODE_PRECISION (inner_mode) < BITS_PER_WORD + && MEM_P (SUBREG_REG (op0)) + && load_extend_op (inner_mode) != ZERO_EXTEND) + break; + } else if (subreg_lowpart_p (op0) && GET_MODE_CLASS (mode) == MODE_INT && is_int_mode (GET_MODE (SUBREG_REG (op0)), &inner_mode)
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) diff --git a/gcc/testsuite/gcc.c-torture/execute/pr113010.c b/gcc/testsuite/gcc.c-torture/execute/pr113010.c new file mode 100644 index 00000000000..a95c613c1df --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr113010.c @@ -0,0 +1,9 @@ +int minus_1 = -1; + +int +main () +{ + if ((0, 0xfffffffful) >= minus_1) + __builtin_abort (); + return 0; +}