From patchwork Mon Feb 10 14:53:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffrey Law X-Patchwork-Id: 106256 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 982293858424 for ; Mon, 10 Feb 2025 14:54:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 982293858424 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=l3SnvxYv 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 BE4B43858D21 for ; Mon, 10 Feb 2025 14:53:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE4B43858D21 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BE4B43858D21 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=1739199220; cv=none; b=J9iu7IY9rdiw0OG67Wb71CSKqTkjSz8CynDAM4IZUdluiOv7GhgtagNq+QUW4YtKgtfCDhiNzfchFh9OnEvq3tSTYwV687XtauOkh9I2EQ4+DtGa2Qcdq/5v3RAydPON1H5WucB/HjlnTJd3X4UQ8AREZzOe1sfpxCl2gXfz/+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739199220; c=relaxed/simple; bh=+iUUK6r/Ug8dHVAnX/7fTiqfS7HTpmpnmjpmfErPFko=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=Bm1+i9TfZ+MMVQdFgXYcJ+HiPsbWIyiIWHHoRTFNXF2h8bvsIBzQE9WBoT3VnYaAc+EU/jo6q3OBkCzQjPKW2EyYJDOkqu0DQfEksHzAAgQXBrKfENDuFGVCh4fuw87GN0/cyBU9Wkb527LmxMdJJUUjRVfOclzIEHGXj6nti5g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE4B43858D21 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-21f2339dcfdso70772235ad.1 for ; Mon, 10 Feb 2025 06:53:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739199218; x=1739804018; darn=gcc.gnu.org; h=cc:to:subject:from:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=6zasp7laYEdBZygJ0jWB5mfZexlJUk7y236Q1DEJTDc=; b=l3SnvxYvDXFxshB/htUATXNHzIdAP4pIXqobXkspePAOfw+WhpDxH0PTNBo0FTaW1f tZjA5VRroXNyT+3maGp+oGYoM67Gujig21rcFX1TKife961Nyc4PKcIbfASsCyjcF2Le AKxcah3FZlJb3EGHM/N2z7lGkr6O2BZ7z9TBXm2FDGxRGpIdxdFqdccGG3ZNf0SHG5Tk 7fWPOWvzu98wNzg0a8Ezz64w/ErvVk7p2tQOUAhoZceJaTrgVn5Rhc7QS3k5Wd2Ei4lg 3PJuvJF/mtOQSCgzzeSRBY9X8vpFAo+9Dqn8Nz+piiZxE65bdCII6GqYD6GMTAgDXVHd n2Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739199218; x=1739804018; h=cc:to:subject:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6zasp7laYEdBZygJ0jWB5mfZexlJUk7y236Q1DEJTDc=; b=ZFE8SxrOxQhf3N8BuAovwxMz46naWEa7LrO+MLy5rCSaSaO2IsClo1eMLZJFk0IcZm KWZ06dYGx1bSG8nBweyoNEPd3rx3L992ltUvJf3WNSdmxIT/rEj0c9xt8TEMO4IqLNVw hhc4YezAXMxwJuUkCpV5Pggf0janebiU4kSPJ9/sV48ZGWbjK1Gi+JJZl57WQaNgPvNP it2da99rAWgV6IsCVe11bV/8EDtGuERVxtKIjE9gtLYMunZWmNnkO1Th0Z5IyUoUD0uN EsQIGlJnDTQHA6OV0tO/1GJGvAIpW1815Abo4vW27xKBJ2vBMuGmP1SSNq18hNd5tNTs 3VPw== X-Gm-Message-State: AOJu0YxHyTKf2ADDoTc1xr5x0RkTL/0Lm+Fpuj34YC+9xsdJYcmZyxUb 3GZfdW9T5Ol3Ufa9zjIgT43AW9jcQfilceI3WCpBtrF0kE2NBUWlGs/a9w== X-Gm-Gg: ASbGnctzDExFeXvXHOwaY7REtqbaBTniksvZiSFveREPhjxCWRrhA/EBljxniIdOrKE DUsFL4mpCNQEDRoUKJ+nnpfMSysWbZbZZR5jlgYKHcHB5NzzYx0PlJJLkkGLj7oUJKPR1fSZGU3 8XP/mMGqUg9NKSU6+1JLFnUg3WiFZPOno6XbPsFdHIYIWvpfPONZZpKXVgBOez2RDWWeiOftRGh ozDsRbqv69tiVp2+fBGflKF3hwh3B5wqvdDcWQUVFbbzIxF6MFEZgtGRA++zjpfLZkM1YFAeed4 iKu0yzLL09HW1e9LUMk= X-Google-Smtp-Source: AGHT+IGGjSlj2SqDnUZzzbwChKDpZxi5babkheHtmHIy+z1EsSmW+wZNWaJ4jgiYAEVjsqOIgi10QA== X-Received: by 2002:a17:902:f68f:b0:21f:5e6f:a406 with SMTP id d9443c01a7336-21f5e6ffcbamr170148875ad.20.1739199217416; Mon, 10 Feb 2025 06:53:37 -0800 (PST) Received: from [172.31.0.17] ([136.60.141.45]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21f3653bfb2sm79899065ad.67.2025.02.10.06.53.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Feb 2025 06:53:36 -0800 (PST) Message-ID: <3bcca05d-fd48-41d6-8106-2dcd255b3c3f@gmail.com> Date: Mon, 10 Feb 2025 07:53:35 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Jeff Law Subject: [RFA][PR target/115478] Accept ADD, IOR or XOR when combining objects with no bits in common To: "gcc-patches@gcc.gnu.org" Cc: Richard Sandiford , Roger Sayle X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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 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 So the change to prefer ADD over IOR for combining two objects with no bits in common is (IMHO) generally good. It has some minor fallout. In particular the aarch64 port (and I suspect others) have patterns that recognize IOR, but not PLUS or XOR for these cases and thus tests which expected to optimize with IOR are no longer optimizing. Roger suggested using a code iterator for this purpose. Richard S. suggested a new match operator to cover those cases. I really like the match operator idea, but as Richard S. notes in the PR it would require either not validating the "no bits in common", which dramatically reduces the utility IMHO or we'd need some work to allow consistent results without polluting the nonzero bits cache. So this patch goes back to Roger's idea of just using a match iterator in the aarch64 backend (and presumably anywhere else we see this popping up). Bootstrapped and regression tested on aarch64-linux-gnu where it fixes bitint-args.c (as expected). OK for the trunk? Jeff PR target/115478 gcc/ * config/aarch64/iterators.md (any_or_plus): New code iterator. * config/aarch64/aarch64.md (extr5_insn): Use any_or_plus. (extr5_insn_alt, extrsi5_insn_uxtw): Likewise. (extrsi5_insn_uxtw_alt, extrsi5_insn_di): Likewise. gcc/testsuite/ * gcc.target/aarch64/bitint-args.c: Update expected output. diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index 071058dbeb3..cfe730f3732 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -6194,10 +6194,11 @@ (define_insn "*extr5_insn" [(set (match_operand:GPI 0 "register_operand" "=r") - (ior:GPI (ashift:GPI (match_operand:GPI 1 "register_operand" "r") - (match_operand 3 "const_int_operand" "n")) - (lshiftrt:GPI (match_operand:GPI 2 "register_operand" "r") - (match_operand 4 "const_int_operand" "n"))))] + (any_or_plus:GPI + (ashift:GPI (match_operand:GPI 1 "register_operand" "r") + (match_operand 3 "const_int_operand" "n")) + (lshiftrt:GPI (match_operand:GPI 2 "register_operand" "r") + (match_operand 4 "const_int_operand" "n"))))] "UINTVAL (operands[3]) < GET_MODE_BITSIZE (mode) && (UINTVAL (operands[3]) + UINTVAL (operands[4]) == GET_MODE_BITSIZE (mode))" "extr\\t%0, %1, %2, %4" @@ -6208,10 +6209,11 @@ ;; so we have to match both orderings. (define_insn "*extr5_insn_alt" [(set (match_operand:GPI 0 "register_operand" "=r") - (ior:GPI (lshiftrt:GPI (match_operand:GPI 2 "register_operand" "r") - (match_operand 4 "const_int_operand" "n")) - (ashift:GPI (match_operand:GPI 1 "register_operand" "r") - (match_operand 3 "const_int_operand" "n"))))] + (any_or_plus:GPI + (lshiftrt:GPI (match_operand:GPI 2 "register_operand" "r") + (match_operand 4 "const_int_operand" "n")) + (ashift:GPI (match_operand:GPI 1 "register_operand" "r") + (match_operand 3 "const_int_operand" "n"))))] "UINTVAL (operands[3]) < GET_MODE_BITSIZE (mode) && (UINTVAL (operands[3]) + UINTVAL (operands[4]) == GET_MODE_BITSIZE (mode))" @@ -6223,10 +6225,11 @@ (define_insn "*extrsi5_insn_uxtw" [(set (match_operand:DI 0 "register_operand" "=r") (zero_extend:DI - (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "r") - (match_operand 3 "const_int_operand" "n")) - (lshiftrt:SI (match_operand:SI 2 "register_operand" "r") - (match_operand 4 "const_int_operand" "n")))))] + (any_or_plus:SI + (ashift:SI (match_operand:SI 1 "register_operand" "r") + (match_operand 3 "const_int_operand" "n")) + (lshiftrt:SI (match_operand:SI 2 "register_operand" "r") + (match_operand 4 "const_int_operand" "n")))))] "UINTVAL (operands[3]) < 32 && (UINTVAL (operands[3]) + UINTVAL (operands[4]) == 32)" "extr\\t%w0, %w1, %w2, %4" @@ -6236,10 +6239,11 @@ (define_insn "*extrsi5_insn_uxtw_alt" [(set (match_operand:DI 0 "register_operand" "=r") (zero_extend:DI - (ior:SI (lshiftrt:SI (match_operand:SI 2 "register_operand" "r") - (match_operand 4 "const_int_operand" "n")) - (ashift:SI (match_operand:SI 1 "register_operand" "r") - (match_operand 3 "const_int_operand" "n")))))] + (any_or_plus:SI + (lshiftrt:SI (match_operand:SI 2 "register_operand" "r") + (match_operand 4 "const_int_operand" "n")) + (ashift:SI (match_operand:SI 1 "register_operand" "r") + (match_operand 3 "const_int_operand" "n")))))] "UINTVAL (operands[3]) < 32 && (UINTVAL (operands[3]) + UINTVAL (operands[4]) == 32)" "extr\\t%w0, %w1, %w2, %4" @@ -6248,13 +6252,13 @@ (define_insn "*extrsi5_insn_di" [(set (match_operand:SI 0 "register_operand" "=r") - (ior:SI (ashift:SI (match_operand:SI 1 "register_operand" "r") - (match_operand 3 "const_int_operand" "n")) - (match_operator:SI 6 "subreg_lowpart_operator" - [(zero_extract:DI - (match_operand:DI 2 "register_operand" "r") - (match_operand 5 "const_int_operand" "n") - (match_operand 4 "const_int_operand" "n"))])))] + (any_or_plus:SI (ashift:SI (match_operand:SI 1 "register_operand" "r") + (match_operand 3 "const_int_operand" "n")) + (match_operator:SI 6 "subreg_lowpart_operator" + [(zero_extract:DI + (match_operand:DI 2 "register_operand" "r") + (match_operand 5 "const_int_operand" "n") + (match_operand 4 "const_int_operand" "n"))])))] "UINTVAL (operands[3]) < 32 && UINTVAL (operands[3]) + UINTVAL (operands[4]) == 32 && INTVAL (operands[3]) == INTVAL (operands[5])" diff --git a/gcc/config/aarch64/iterators.md b/gcc/config/aarch64/iterators.md index 9fbd7493988..5bfd6e7d362 100644 --- a/gcc/config/aarch64/iterators.md +++ b/gcc/config/aarch64/iterators.md @@ -2657,6 +2657,10 @@ ;; Code iterator for logical operations (define_code_iterator LOGICAL [and ior xor]) +;; Code iterator for operations that are equivalent when the +;; two input operands are known have disjoint bits set. +(define_code_iterator any_or_plus [plus ior xor]) + ;; LOGICAL with plus, for when | gets converted to +. (define_code_iterator LOGICAL_OR_PLUS [and ior xor plus]) diff --git a/gcc/testsuite/gcc.target/aarch64/bitint-args.c b/gcc/testsuite/gcc.target/aarch64/bitint-args.c index e7e1099c303..06b47246fa5 100644 --- a/gcc/testsuite/gcc.target/aarch64/bitint-args.c +++ b/gcc/testsuite/gcc.target/aarch64/bitint-args.c @@ -69,7 +69,7 @@ CHECK_ARG(65) ** f65: ** extr (x[0-9]+), x3, x2, 1 ** and (x[0-9]+), x2, 1 -** orr (x[0-9]+), \2, \1, lsl 1 +** add (x[0-9]+), \2, \1, lsl 1 ** asr (x[0-9]+), \1, 63 ** stp \3, \4, \[x0\] ** ret @@ -80,7 +80,7 @@ CHECK_ARG(127) ** f127: ** extr (x[0-9]+), x3, x2, 63 ** and (x[0-9]+), x2, 9223372036854775807 -** orr (x[0-9]+), \2, \1, lsl 63 +** add (x[0-9]+), \2, \1, lsl 63 ** asr (x[0-9]+), \1, 1 ** stp \3, \4, \[x0\] ** ret