From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 965EF3858C32 for ; Sat, 23 Mar 2024 10:16:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 965EF3858C32 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 965EF3858C32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::632 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711188963; cv=none; b=XCJfGNSrxnmbyg2TCf0dJYkMUjdu5HCFknlsKMzcV5CaAQlF2BOdsyCh+IYjarIg1688nDZa2hRK537t1w6omDZhRc6hFUp/0WQcinO9eainkiPBvxmkwfwccewXCJCfhsR1s2AuVJb6CpS7m4QevttTbwfhyp4tr6iUULzIg80= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711188963; c=relaxed/simple; bh=S0MGp9JBAOLdESFegB/227EYAlIx3xc91ibTq6dDPsI=; h=DKIM-Signature:From:Mime-Version:Subject:Date:Message-Id:To; b=HGUkMfY+FtF5tK+gI7xf0/+8Z2G95k5GsIzXPAKEmOmTSz4NE1kN6UUWXMr/g7bnP6685Rjocxu0uN2nUSyVz2sJ7znFWzIo0p4NSF5AyvyHKKB/9BC+gjSdGG8IVD4IoUvqBt9ekhoqtYTrtaK9BKFnT7ijUZCjRWjivgDw+O4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a4702457ccbso388990166b.3 for ; Sat, 23 Mar 2024 03:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711188959; x=1711793759; darn=gcc.gnu.org; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=msRJmZdGAIa7kE2VtgczDDF4yg7FA5qwVL9s09ryekQ=; b=UqHDgVViWobWxUaNAMxNsUBQZaiI6QzUeWaPPSfFIvSi3aXY4k5+SXh7oM0FI2LOb/ EnOQixI/pPE66nAzrjdqW+AIPV5w4NgwPlgMbDItM4Bmd4m999M761X2W3nxi0gOJuFu yDcdAlkZIu8saG3U64VHK1gdUX2mBcKDCDOi/6rzXdDlKcnpK3Nxa5qEdbJZkNhTPa2G hG4G6lZ+uL0shltS0mgLwKMd47NWCZKjsNH+ZhPPFdequyHokKEWcdY6/77uXVDS/saY mbNBOq5jRcfpM0691BLiGU0i0O/iF9pB1jh6dQtSq1hSvh7UlmjRTm3CM1/fJG+YMqSe czQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711188959; x=1711793759; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=msRJmZdGAIa7kE2VtgczDDF4yg7FA5qwVL9s09ryekQ=; b=TDgR5zaKj2AdK8jV1+zyEZPzHj928pQ55MHkdj7UItliWMGF6ppArhm7GXPWZ4syrr yIqFashWkeC56tZWZFpE7NZuY7+P8iP9fPjEeDTVSEow0L+Vh5E+YyskhQlJ25BJIb4q ZOle5lwCCLt/69WFMFpuS6Wad/gEzDKyuloR2fX0eeuxLIgPTEzekSiik9c9nDXkvwAJ rWJAPmHqElMqE5b5KVXu60D5J7yQ/9h0JpdYk5tM0UVIkw0LLihhDhumtW6tBKtFAxpe 312XB72Xp+nFwqXgXpS6CVJsUjeijWUowfcv4J7w+PznyJfljZlYAA54PLlFQpfk1Urv +FLA== X-Forwarded-Encrypted: i=1; AJvYcCUK2J1MvSOwNE+oNYEdGKGBJ7/slKnFRILVI8wTwsDwS8d4zZrrr4ySWA7zfQbKzKD+KMWhXY/VgIya0PVwVVw+fEwmrWWLjg== X-Gm-Message-State: AOJu0YwSCG2Q2rKzI9iaphV9z9phsitDaQ8ZEIx0Z0OwYWx50xKnIDof YEzClYtNiVMy97ZnEzw1qm9SHj9n09fbIW/naH4qs5JnCjciDiXBcAjvKMj2 X-Google-Smtp-Source: AGHT+IEH4EZK7JwspPGnue2YPWteyDSJ8mIG5yv4ZuDoCIw+Uf8ruw4yODIdkrWPy23UMI21W7QHfg== X-Received: by 2002:a17:906:128d:b0:a47:11a9:9038 with SMTP id k13-20020a170906128d00b00a4711a99038mr1459320ejb.58.1711188958615; Sat, 23 Mar 2024 03:15:58 -0700 (PDT) Received: from smtpclient.apple (dynamic-077-009-127-100.77.9.pool.telefonica.de. [77.9.127.100]) by smtp.gmail.com with ESMTPSA id m23-20020a1709062ad700b00a46dd1f7dc1sm760428eje.92.2024.03.23.03.15.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 23 Mar 2024 03:15:58 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Richard Biener Mime-Version: 1.0 (1.0) Subject: Re: [PATCH] bitint: Handle complex types in build_bitint_stmt_ssa_conflicts [PR114425] Date: Sat, 23 Mar 2024 11:15:47 +0100 Message-Id: <1DB79DCD-6D7E-4DBC-8218-3801A90A5F5D@gmail.com> References: Cc: Richard Biener , gcc-patches@gcc.gnu.org In-Reply-To: To: Jakub Jelinek X-Mailer: iPhone Mail (21E236) X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > Am 23.03.2024 um 08:56 schrieb Jakub Jelinek : >=20 > =EF=BB=BFHi! >=20 > The task of the build_bitint_stmt_ssa_conflicts hook for > tree-ssa-coalesce.cc next to special casing the > multiplication/division/modulo is to ignore statements with > large/huge _BitInt lhs which isn't in names bitmap and on the > other side pretend all uses of the stmt are used in a later stmt > (single user of that SSA_NAME or perhaps single user of lhs of > the single user etc.) where the lowering will actually emit the > code. >=20 > Unfortunately the function wasn't handling COMPLEX_TYPE of the large/huge > BITINT_TYPE, while the FE doesn't really support such types, they are > used under the hood for __builtin_{add,sub,mul}_overflow{,_p}, they are > also present or absent from the names bitmap and should be treated the sam= e. >=20 > Without this patch, the operands of .ADD_OVERFLOW were incorrectly pretend= ed > to be used right in that call statement rather than on the cast stmt from > IMAGPART_EXPR of .ADD_OVERFLOW return value to some integral type. >=20 > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Ok Richard=20 > 2024-03-23 Jakub Jelinek >=20 > PR tree-optimization/114425 > * gimple-lower-bitint.cc (build_bitint_stmt_ssa_conflicts): Handle > _Complex large/huge _BitInt types like the large/huge _BitInt types. >=20 > * gcc.dg/torture/bitint-67.c: New test. > =20 > --- gcc/gimple-lower-bitint.cc.jj 2024-03-22 09:21:28.350087044 +0100 > +++ gcc/gimple-lower-bitint.cc 2024-03-22 14:54:41.767972684 +0100 > @@ -5902,20 +5902,25 @@ build_bitint_stmt_ssa_conflicts (gimple > if (is_gimple_assign (stmt)) > { > lhs =3D gimple_assign_lhs (stmt); > - if (TREE_CODE (lhs) =3D=3D SSA_NAME > - && TREE_CODE (TREE_TYPE (lhs)) =3D=3D BITINT_TYPE > - && bitint_precision_kind (TREE_TYPE (lhs)) >=3D bitint_prec_large) > + if (TREE_CODE (lhs) =3D=3D SSA_NAME) > { > - if (!bitmap_bit_p (names, SSA_NAME_VERSION (lhs))) > - return; > - switch (gimple_assign_rhs_code (stmt)) > + tree type =3D TREE_TYPE (lhs); > + if (TREE_CODE (type) =3D=3D COMPLEX_TYPE) > + type =3D TREE_TYPE (type); > + if (TREE_CODE (type) =3D=3D BITINT_TYPE > + && bitint_precision_kind (type) >=3D bitint_prec_large) > { > - case MULT_EXPR: > - case TRUNC_DIV_EXPR: > - case TRUNC_MOD_EXPR: > - muldiv_p =3D true; > - default: > - break; > + if (!bitmap_bit_p (names, SSA_NAME_VERSION (lhs))) > + return; > + switch (gimple_assign_rhs_code (stmt)) > + { > + case MULT_EXPR: > + case TRUNC_DIV_EXPR: > + case TRUNC_MOD_EXPR: > + muldiv_p =3D true; > + default: > + break; > + } > } > } > } > @@ -5947,27 +5952,37 @@ build_bitint_stmt_ssa_conflicts (gimple >=20 > auto_vec worklist; > FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE) > - if (TREE_CODE (TREE_TYPE (var)) =3D=3D BITINT_TYPE > - && bitint_precision_kind (TREE_TYPE (var)) >=3D bitint_prec_large) > - { > - if (bitmap_bit_p (names, SSA_NAME_VERSION (var))) > - use (live, var); > - else > - worklist.safe_push (var); > - } > + { > + tree type =3D TREE_TYPE (var); > + if (TREE_CODE (type) =3D=3D COMPLEX_TYPE) > + type =3D TREE_TYPE (type); > + if (TREE_CODE (type) =3D=3D BITINT_TYPE > + && bitint_precision_kind (type) >=3D bitint_prec_large) > + { > + if (bitmap_bit_p (names, SSA_NAME_VERSION (var))) > + use (live, var); > + else > + worklist.safe_push (var); > + } > + } >=20 > while (worklist.length () > 0) > { > tree s =3D worklist.pop (); > FOR_EACH_SSA_TREE_OPERAND (var, SSA_NAME_DEF_STMT (s), iter, SSA_OP_= USE) > - if (TREE_CODE (TREE_TYPE (var)) =3D=3D BITINT_TYPE > - && bitint_precision_kind (TREE_TYPE (var)) >=3D bitint_prec_large= ) > - { > - if (bitmap_bit_p (names, SSA_NAME_VERSION (var))) > - use (live, var); > - else > - worklist.safe_push (var); > - } > + { > + tree type =3D TREE_TYPE (var); > + if (TREE_CODE (type) =3D=3D COMPLEX_TYPE) > + type =3D TREE_TYPE (type); > + if (TREE_CODE (type) =3D=3D BITINT_TYPE > + && bitint_precision_kind (type) >=3D bitint_prec_large) > + { > + if (bitmap_bit_p (names, SSA_NAME_VERSION (var))) > + use (live, var); > + else > + worklist.safe_push (var); > + } > + } > } >=20 > if (muldiv_p) > --- gcc/testsuite/gcc.dg/torture/bitint-67.c.jj 2024-03-22 14:53:52.929= 642342 +0100 > +++ gcc/testsuite/gcc.dg/torture/bitint-67.c 2024-03-22 14:54:29.205144= 953 +0100 > @@ -0,0 +1,29 @@ > +/* PR tree-optimization/114425 */ > +/* { dg-do run { target bitint } } */ > +/* { dg-options "-std=3Dc23" } */ > +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } *= / > +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ > + > +#if __BITINT_MAXWIDTH__ >=3D 2000 > +_BitInt(8) a; > +_BitInt(300) b; > +_BitInt(2000) c; > + > +__attribute__((noipa)) unsigned > +foo (_BitInt(2000) d) > +{ > + int o =3D __builtin_add_overflow_p (d, 0, b); > + _BitInt(2000) m =3D c * a; > + unsigned u =3D m; > + return u + o; > +} > +#endif > + > +int > +main () > +{ > +#if __BITINT_MAXWIDTH__ >=3D 2000 > + if (foo (0xfa7ac16f2613255eeb217e871c1f02221e26ce11f82d6a33206ec0ad5d44= 14722019933c0e2wb) !=3D 1) > + __builtin_abort (); > +#endif > +} >=20 > Jakub >=20