From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 630B33858D35 for ; Thu, 7 Mar 2024 00:00:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 630B33858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 630B33858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709769635; cv=none; b=WDJXBu3oePCPXzV7ynRxp5wgxidTDUeUdzN2oUgTBwYa4lm/0XetsA07yCUJhmIDBX0wIXsUFn/qHatER1S5L4H41f5o01uw17Yx+RfIyLqVRJI7dWqS5atDJ2uJhFcprheKS/okX6Ty35nCFFXyxv0FcJtyyPfLa01bu+QwOyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709769635; c=relaxed/simple; bh=TPAIoZMWL+eqCqYZiXWc/UQyDwaBoaGCtqXzQ71OnVU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=BsIAcxM6I5iHnCErFPk2lPx33Wwq++jDUtGhshf3fXEnDKcsMafnOxVjdtvJ5dKayU4owbfJrk7rPZyZdcH5T5g6PrtUAoQgroDOr66tWy6pklZgw2XXejRK+5wjFYnVbTvpWunjOV7EHLztkFvdrTeV5khf8O4nQvIFlJ0TFIo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709769621; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DwQVcPpL4tDGSmA7GGDEnV+sL39Qz844fg17HNa4ehE=; b=ZdnbrqEqAUHXDMVki3GoNH+a6J11b1+H7w59FONrkRAtTiCwzwLEDi6oLlDa8uBjWELgFJ xcoEMCNgzvb4bb8+dmm72UM6T1Tei5bdWZc1BAdXoK33X/1YfuccM8mUHVwD10/6s5yXOV /6bA0PvRdlyfxrNvCvzFKPClfO+q5/g= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-drxjesgnNZih6j_GhPqxeg-1; Wed, 06 Mar 2024 19:00:19 -0500 X-MC-Unique: drxjesgnNZih6j_GhPqxeg-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-787ce91a4e0so271955385a.0 for ; Wed, 06 Mar 2024 16:00:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709769619; x=1710374419; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DwQVcPpL4tDGSmA7GGDEnV+sL39Qz844fg17HNa4ehE=; b=iwsGcDrYgfRJzlSCKpyDJg+Oip731j4RFlZtkN34Y8U6XXppcjRbtYJIy2doOXs3PB qbEYPWZHYeuCNqjC9MplLuQaHGm7KJnyfkCi9OcKVlYZM8lawo2GuvbhDCNgJSO2ZnBk UEFOqjL87ScwYfcyGEu7VLrtuXCCRJxtg2DUt3MSPINz8WHZM1DATSarsYJsLoNzm5du J5YvY9EeiN1hl3clvPbcsYaSveHtIi8LAbdRUXBajWvBz5nWVS84y7N0ARVjMG2BWV2R gr5QZc0daiZaahmQQFr4T+z58LfoqADxJpc2BWbSOQlciZxJ7mWeoNuS1zL1JrwSheOU yUNQ== X-Gm-Message-State: AOJu0YxHJTvsj3QPQ1vfdRsFXgD7eaupl5H7lwaLa5sPY0FW+BVKM/o9 lo53Lkkp4qCPSrFxhIQ0RiiV47N11i1mNI/qnoFeNUN7TeklThFLAIlsOIOQFpSJU4/k53EblC0 ecFYIw/tzNFDE6P0qvVYqU4wZQARfzt0wTm7lK/Y0OFgi0aDnGdIORuSuYRFfZI0= X-Received: by 2002:a05:620a:29d2:b0:788:421b:6904 with SMTP id s18-20020a05620a29d200b00788421b6904mr3874760qkp.8.1709769619014; Wed, 06 Mar 2024 16:00:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5vrAenwp/428hhqnmo8dCNrw1VGukmEl5RVESmYcAypuWM6SOC6+RGGUU/016BLXdqFWofA== X-Received: by 2002:a05:620a:29d2:b0:788:421b:6904 with SMTP id s18-20020a05620a29d200b00788421b6904mr3874720qkp.8.1709769618708; Wed, 06 Mar 2024 16:00:18 -0800 (PST) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id 25-20020a05620a04d900b007882528475dsm4077732qks.49.2024.03.06.16.00.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 Mar 2024 16:00:18 -0800 (PST) Message-ID: Date: Wed, 6 Mar 2024 19:00:17 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c-family, c++, v2: Fix up handling of types which may have padding in __atomic_{compare_}exchange To: Jakub Jelinek , Richard Biener Cc: gcc-patches@gcc.gnu.org, Jonathan Wakely References: <5988812a-3f21-4ef4-9205-fe267c356d58@redhat.com> <39q9r137-3884-67oq-2334-70q42so2sp22@fhfr.qr> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,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 List-Id: On 2/20/24 05:02, Jakub Jelinek wrote: > On Tue, Feb 20, 2024 at 09:01:10AM +0100, Richard Biener wrote: >> I'm not sure those would be really equivalent (MEM_REF vs. V_C_E >> as well as combined vs. split). It really depends how RTL expansion >> handles this (as you can see padding can be fun here). >> >> So I'd be nervous for a match.pd rule here (also we can't match >> memory defs). > > Ok. Perhaps forwprop then; anyway, that would be an optimization. > >> As for your patch I'd go with a MEM_REF unconditionally, I don't >> think we want different behavior whether there's padding or not ... > > I've made it conditional so that the MEM_REFs don't appear that often in the > FE trees, but maybe that is fine. > > The unconditional patch would then be: OK. > 2024-02-20 Jakub Jelinek > > gcc/c-family/ > * c-common.cc (resolve_overloaded_atomic_exchange): Instead of setting > p1 to VIEW_CONVERT_EXPR (*p1), set it to MEM_REF with p1 and > (typeof (p1)) 0 operands and I_type type. > (resolve_overloaded_atomic_compare_exchange): Similarly for p2. > gcc/cp/ > * pt.cc (tsubst_expr): Handle MEM_REF. > gcc/testsuite/ > * g++.dg/ext/atomic-5.C: New test. > > --- gcc/c-family/c-common.cc.jj 2024-02-17 16:40:42.831571693 +0100 > +++ gcc/c-family/c-common.cc 2024-02-20 10:58:56.599865656 +0100 > @@ -7793,9 +7793,14 @@ resolve_overloaded_atomic_exchange (loca > /* Convert object pointer to required type. */ > p0 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p0); > (*params)[0] = p0; > - /* Convert new value to required type, and dereference it. */ > - p1 = build_indirect_ref (loc, p1, RO_UNARY_STAR); > - p1 = build1 (VIEW_CONVERT_EXPR, I_type, p1); > + /* Convert new value to required type, and dereference it. > + If *p1 type can have padding or may involve floating point which > + could e.g. be promoted to wider precision and demoted afterwards, > + state of padding bits might not be preserved. */ > + build_indirect_ref (loc, p1, RO_UNARY_STAR); > + p1 = build2_loc (loc, MEM_REF, I_type, > + build1 (VIEW_CONVERT_EXPR, I_type_ptr, p1), > + build_zero_cst (TREE_TYPE (p1))); > (*params)[1] = p1; > > /* Move memory model to the 3rd position, and end param list. */ > @@ -7873,9 +7878,14 @@ resolve_overloaded_atomic_compare_exchan > p1 = build1 (VIEW_CONVERT_EXPR, I_type_ptr, p1); > (*params)[1] = p1; > > - /* Convert desired value to required type, and dereference it. */ > - p2 = build_indirect_ref (loc, p2, RO_UNARY_STAR); > - p2 = build1 (VIEW_CONVERT_EXPR, I_type, p2); > + /* Convert desired value to required type, and dereference it. > + If *p2 type can have padding or may involve floating point which > + could e.g. be promoted to wider precision and demoted afterwards, > + state of padding bits might not be preserved. */ > + build_indirect_ref (loc, p2, RO_UNARY_STAR); > + p2 = build2_loc (loc, MEM_REF, I_type, > + build1 (VIEW_CONVERT_EXPR, I_type_ptr, p2), > + build_zero_cst (TREE_TYPE (p2))); > (*params)[2] = p2; > > /* The rest of the parameters are fine. NULL means no special return value > --- gcc/cp/pt.cc.jj 2024-02-17 16:40:42.868571182 +0100 > +++ gcc/cp/pt.cc 2024-02-20 10:57:36.646973603 +0100 > @@ -20088,6 +20088,14 @@ tsubst_expr (tree t, tree args, tsubst_f > RETURN (r); > } > > + case MEM_REF: > + { > + tree op0 = RECUR (TREE_OPERAND (t, 0)); > + tree op1 = RECUR (TREE_OPERAND (t, 0)); > + tree new_type = tsubst (TREE_TYPE (t), args, complain, in_decl); > + RETURN (build2_loc (EXPR_LOCATION (t), MEM_REF, new_type, op0, op1)); > + } > + > case NOP_EXPR: > { > tree type = tsubst (TREE_TYPE (t), args, complain, in_decl); > --- gcc/testsuite/g++.dg/ext/atomic-5.C.jj 2024-02-20 10:57:36.647973589 +0100 > +++ gcc/testsuite/g++.dg/ext/atomic-5.C 2024-02-20 10:57:36.647973589 +0100 > @@ -0,0 +1,42 @@ > +// { dg-do compile { target c++14 } } > + > +template > +void > +foo (long double *ptr, long double *val, long double *ret) > +{ > + __atomic_exchange (ptr, val, ret, __ATOMIC_RELAXED); > +} > + > +template > +bool > +bar (long double *ptr, long double *exp, long double *des) > +{ > + return __atomic_compare_exchange (ptr, exp, des, false, > + __ATOMIC_RELAXED, __ATOMIC_RELAXED); > +} > + > +bool > +baz (long double *p, long double *q, long double *r) > +{ > + foo<0> (p, q, r); > + foo<1> (p + 1, q + 1, r + 1); > + return bar<0> (p + 2, q + 2, r + 2) || bar<1> (p + 3, q + 3, r + 3); > +} > + > +constexpr int > +qux (long double *ptr, long double *val, long double *ret) > +{ > + __atomic_exchange (ptr, val, ret, __ATOMIC_RELAXED); > + return 0; > +} > + > +constexpr bool > +corge (long double *ptr, long double *exp, long double *des) > +{ > + return __atomic_compare_exchange (ptr, exp, des, false, > + __ATOMIC_RELAXED, __ATOMIC_RELAXED); > +} > + > +long double a[6]; > +const int b = qux (a, a + 1, a + 2); > +const bool c = corge (a + 3, a + 4, a + 5); > > > Jakub >