From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id F339E386546B for ; Wed, 22 May 2024 13:15:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F339E386546B 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 F339E386546B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716383759; cv=none; b=ic4kX7Fh16VIXZZHEDjRQoKKhrHq+isKJoDcY5tPr/oq5bLlI0otMkcdSkmYYacOcnLOmf28DuI5vDagz8LkWslJZatn2Kn6W7py8FBJcg/EEYG5IKwoHALv63pIPA1p1P6sBcFiQ5P5I089jF0yznFiAnNTvoIMEerUhR7GvI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716383759; c=relaxed/simple; bh=9TTbANEXDNUQr7gmBqEKwY/UlXpdEwCzCu0kpUzlmxY=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=I4pW9Gr47/pPwVQhaXtBNUgNeQiL8Ck2Zygk8+fR5hsTlVlzepxazL7WD82WVCTMi+24dGynkQj0Su8ALlsoVWmWOa5kmUjRvpMMywNgZPdom09cK8Iqwf0Abau03l8Yimwttuy4G2to6WkbmLS7v8WWYB7hW5pXu3r286ntoqQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-51f12ccff5eso8224044e87.1 for ; Wed, 22 May 2024 06:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716383755; x=1716988555; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=giGntLLkWVLMYVvIrGgmYMLZ4hCJ1e45vprQN5aFN3A=; b=X/uso9b3Y7tcsR2uz7naZ0L8PPnl94dMRwqszG0+WXUSOGlCesTaxN4fBEfzAguX0z o9CCaR2elEXE7TXqhLfbbKx7n5+47aOwDhqi37Q4YRQ5BoW+MJNgu7YpyVqVrL8h9NU4 3yyxhk20+s7NoOfNkWr81tpVhak0JT2YBOh3gYp9euzF73qu1foxj21m0JaGxJ6AwR6I o2mj1WeATOOW0CFQi1OB7V1Pq5tcS+PIySjcrL3aVCjmtvIply/zpSwVu01t8zMKP0wH sInS4tmORcIfmswhjIUeeJjUwRwASSY0fDFglfUecoTn2QwecXzCYij2W68SOZLzKw1h MWtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716383755; x=1716988555; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=giGntLLkWVLMYVvIrGgmYMLZ4hCJ1e45vprQN5aFN3A=; b=qZQ8ExFuMR4mggR919HUPHQta6kXLHCzJ4/JeJj6PNQp4CiCm03EylLe2rIX07c2Zl R5zI1Xe3Sq+J7ozBfjJK9N/tU//tiguJ66tK8HQA+GXaf2bykD59T9xmtyIUvtMZs6fc bBA8j2T22lmnkhOmKdQE1otfX1WOCfI3p71uJKx153ta+47q36aiLz3z+CqpHwfcMJRf U0LLF/0e8sQzrsEVVe0M3/3pmNYzdP9SmP2TMgZvcWfS+e5RmUxvmhXze5muKBIdeMKl 0pWAjNr4EBrwmbbB2nvtJRxvMCmYYRGy8ypL/wfuexCnXxisK97hdfzuQfQe7hSnk8bf i9tg== X-Gm-Message-State: AOJu0YyvL3yfLaU4nKD3RAAuNEFSDtjIfKU/lv9O/iL7D9GyoBUKic2c 6VAZ2WASJd9GIfXZfh2RGsJdUbcm4rEhMdjDxMUDrrYWrq7z/9uADYOJd/AqYVukItIOQleupF2 VdV6zml3/H3g55t/J5aahmvSlMmw= X-Google-Smtp-Source: AGHT+IHJMevvL/iZ61PQJyI6OC2ob3HkuJWxw5ciVjxEY8R25JTDVjqf4dCIsT614BaGQ+GqhRAT39+fOEZma8eC5ws= X-Received: by 2002:a19:8c4e:0:b0:51e:11d5:bca3 with SMTP id 2adb3069b0e04-526bd59ef13mr1296024e87.18.1716383755078; Wed, 22 May 2024 06:15:55 -0700 (PDT) MIME-Version: 1.0 References: <20240519063708.1847699-1-pan2.li@intel.com> In-Reply-To: <20240519063708.1847699-1-pan2.li@intel.com> From: Richard Biener Date: Wed, 22 May 2024 15:15:44 +0200 Message-ID: Subject: Re: [PATCH v1 1/2] Match: Support __builtin_add_overflow for branchless unsigned SAT_ADD To: pan2.li@intel.com Cc: gcc-patches@gcc.gnu.org, juzhe.zhong@rivai.ai, kito.cheng@gmail.com, tamar.christina@arm.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,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 Sun, May 19, 2024 at 8:37=E2=80=AFAM wrote: > > From: Pan Li > > This patch would like to support the branchless form for unsigned > SAT_ADD when leverage __builtin_add_overflow. For example as below: > > uint64_t sat_add_u(uint64_t x, uint64_t y) > { > uint64_t ret; > uint64_t overflow =3D __builtin_add_overflow (x, y, &ret); > > return (T)(-overflow) | ret; > } > > Before this patch: > > uint64_t sat_add_u (uint64_t x, uint64_t y) > { > long unsigned int _1; > long unsigned int _2; > long unsigned int _3; > __complex__ long unsigned int _6; > uint64_t _8; > > ;; basic block 2, loop depth 0 > ;; pred: ENTRY > _6 =3D .ADD_OVERFLOW (x_4(D), y_5(D)); > _1 =3D REALPART_EXPR <_6>; > _2 =3D IMAGPART_EXPR <_6>; > _3 =3D -_2; > _8 =3D _1 | _3; > return _8; > ;; succ: EXIT > > } > > After this patch: > > uint64_t sat_add_u (uint64_t x, uint64_t y) > { > uint64_t _8; > > ;; basic block 2, loop depth 0 > ;; pred: ENTRY > _8 =3D .SAT_ADD (x_4(D), y_5(D)); [tail call] > return _8; > ;; succ: EXIT > > } > > The below tests suite are passed for this patch. > * The rv64gcv fully regression test. > * The x86 bootstrap test. > * The x86 fully regression test. > > gcc/ChangeLog: > > * match.pd: Add SAT_ADD right part 2 for __builtin_add_overflow. > > Signed-off-by: Pan Li > --- > gcc/match.pd | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/gcc/match.pd b/gcc/match.pd > index b291e34bbe4..5328e846aff 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -3064,6 +3064,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (negate (convert (ne (imagpart (IFN_ADD_OVERFLOW:c @0 @1)) integer_zero= p))) > (if (TYPE_UNSIGNED (type) && integer_types_ternary_match (type, @0, @1)= ))) > > +(match (usadd_right_part_2 @0 @1) > + (negate (imagpart (IFN_ADD_OVERFLOW:c @0 @1))) > + (if (TYPE_UNSIGNED (type) && integer_types_ternary_match (type, @0, @1)= ))) > + Can you merge this with the patch that makes use of the usadd_right_part_2 match? It's difficult to review on its own. > /* We cannot merge or overload usadd_left_part_1 and usadd_left_part_2 > because the sub part of left_part_2 cannot work with right_part_1. > For example, left_part_2 pattern focus one .ADD_OVERFLOW but the > -- > 2.34.1 >