From patchwork Tue Feb 27 00:17:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg McGary X-Patchwork-Id: 86408 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5ABD1385840A for ; Tue, 27 Feb 2024 00:19:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 3CC1D3858C5E for ; Tue, 27 Feb 2024 00:17:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CC1D3858C5E 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 3CC1D3858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708993088; cv=none; b=mMePY9VN3qmYroTyNeNxKIIsnYqdd5mMIa8a5CuWQ0oNCZ4UQ+yQS2ncWrfwS0OGbrT7IknLR3yU5xjhs9ue3yYgY0taXsfmGI6U21Vqw+PiKfupXK+QDyTD1Dv0ueqIQF3jIid1u969NZsalByoKAmJzLrHKWx7LmG3fnbIdCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708993088; c=relaxed/simple; bh=XryxaPjM6Jhn0EHB5ZvpnqUDJWO6flDR5f1+AuOjVIA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=KEfjrPUROUKIv6H8EXPJ2bJ5UQyqINqtBJfTDjEPii7ukmO8LURu2MgvvtB9t6znhgizHmYO+mz9Vc3HMvL3oCDm02LVFfjca5C/OO1iBrxY+JZH3Emtd9Z2JpypZXwlc65LA/YekPkrru9IlVBaxycH8XZQdz2mmrk8PTN3EOo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-3657dbe2008so12166205ab.1 for ; Mon, 26 Feb 2024 16:17:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708993059; x=1709597859; 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=MZLqyvdVHp59aPW8zD+Dxd0tGCymHFmImMMqy8XbMEg=; b=YqT1CqOvT/w6FFDL8CEQPCxIK3I/hkB4Ycr0DGHZNCeTgpEh4Ee9vX6ve/rApMJnEn ZxZ7ACJW5BgQ/spyCrMZrWBGhAdS6I630LvSRao6p7eU7E/O/YpiwPp+c7Dl6mhzD6JV 5YhGtR2EcVr+SyL9jeZ0rOOPB0zahmB6TTUQQptNYLvTSq4NTgD9AW36rIAhYAD78bIH T/9Ccu0QB3MgKKj26ZKaWBM9E1XRg0ueUJBeLElu6SFkMy0NxwirWr0DsPiZtmTvG3fO STNNt9ncnyjFEcvvZa86L0ovPii2vdyG0Nyx0N1U9ZUeu7kRiZP4H+XOcjoZTvt3rq/9 /6qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708993059; x=1709597859; 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=MZLqyvdVHp59aPW8zD+Dxd0tGCymHFmImMMqy8XbMEg=; b=KFbtbg6ES8Dv+h4ThKbfJL6quc+dNiuOh9cusMSIvGZHYr84P4Asosg9vQKNbLWCsw DTEQtmoKIeKAuJk+2fpfKgjH5exRfVxgF1aFTYgNXt0J66bcFnFHr8P0zpuvsNhs2FFs HwybnYryeAWBoypTYiUOxclLbwkvxS3kvhXYVFW0KG1HR37Jh7pKCNcZTmQuFWMlyGvL Dg6qnzh0QX5wazO+6bB4bIkvwu1dZmxZUwezFUy7wFhDAO15uHWfksVWKtD1+O/K7Ndp iQgjnrN2kIynfGCFdDFLSNNDPxmgAdDM4th8GRxC7YQsRHxsdSRsQDqJ28GN96e6VAXb kRiw== X-Gm-Message-State: AOJu0YxElgbFnnx61IhcR1IFYJp11luvWR+S0DACS0X4XXn0YCWqHuxh FLuWQLKmaZCAxr+PTTeGfGKBtucpVAPugFcp2PBtALVg4pkp0YHZ+/vq2th/+MBClKlcyJgo743 w X-Google-Smtp-Source: AGHT+IGyYIfpBAxKh8/6h1jxFUseLfnNMb0jagU1Elxqk1uOKXGX03bOl8WQFllXKHgC9CVrN0OmYQ== X-Received: by 2002:a92:dacf:0:b0:363:d9e0:c9e2 with SMTP id o15-20020a92dacf000000b00363d9e0c9e2mr10466923ilq.2.1708993059189; Mon, 26 Feb 2024 16:17:39 -0800 (PST) Received: from gkm.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id l9-20020a635709000000b005ce998b9391sm3871380pgb.67.2024.02.26.16.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 16:17:38 -0800 (PST) From: Greg McGary To: gcc-patches@gcc.gnu.org Cc: Greg McGary Subject: [PATCH] combine: Don't simplify paradoxical SUBREG on WORD_REGISTER_OPERATIONS [PR113010] Date: Mon, 26 Feb 2024 16:17:36 -0800 Message-Id: <20240227001736.3690294-1-gkm@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org The sign-bit-copies of a sign-extending load cannot be known until runtime on WORD_REGISTER_OPERATIONS targets, except in the case of a zero-extending MEM load. See the fix for PR112758. 2024-02-22 Greg McGary PR rtl-optimization/113010 * combine.cc (simplify_comparison): Simplify a SUBREG on WORD_REGISTER_OPERATIONS targets only if it is a zero-extending MEM load. * gcc.c-torture/execute/pr113010.c: New test. --- gcc/combine.cc | 15 +++++++++++++-- gcc/testsuite/gcc.c-torture/execute/pr113010.c | 9 +++++++++ 2 files changed, 22 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 76543d85b7c..b09200d757e 100644 --- a/gcc/combine.cc +++ b/gcc/combine.cc @@ -12550,9 +12550,20 @@ 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)) - ; + { + if (WORD_REGISTER_OPERATIONS + && GET_MODE_PRECISION (inner_mode) < BITS_PER_WORD + /* On WORD_REGISTER_OPERATIONS targets the bits + beyond sub_mode aren't considered undefined, + so optimize only if it is a MEM load when MEM loads + zero extend, because then the upper bits are all zero. */ + && !(MEM_P (SUBREG_REG (op0)) + && load_extend_op (inner_mode) == ZERO_EXTEND)) + break; + /* FALLTHROUGH to case ZERO_EXTEND */ + } 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; +}