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 947743858D38 for ; Fri, 14 Oct 2022 21:20:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 947743858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665782441; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=ni1GuSeIdf8+GejvOk0U+uAc+wrpiodeYG5ErGbV2NQ=; b=ewYWoFp31FJ1ME+2lVBR+4apBe6PeA3tFUoxPhzvWx78xK4LMHup/I7dRq6ttqZrHHgQeq BIuDTTB0H9OYz2uaQsh835fXgSjKexUDxVedQDHo5eftxFG2Zrtxi333DBubvVAitVyDbn tqFFCwW7dgafcO4J+jaobVWg1vlKjuw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-567-zpwlZc-KOf6UYSLuNaTKTQ-1; Fri, 14 Oct 2022 17:20:39 -0400 X-MC-Unique: zpwlZc-KOf6UYSLuNaTKTQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7635080280D; Fri, 14 Oct 2022 21:20:39 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 33CF785798; Fri, 14 Oct 2022 21:20:39 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 29ELKao43592844 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 14 Oct 2022 23:20:37 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 29ELKagM3592131; Fri, 14 Oct 2022 23:20:36 +0200 Date: Fri, 14 Oct 2022 23:20:35 +0200 From: Jakub Jelinek To: Martin Uecker Cc: "gcc-patches@gcc.gnu.org" Subject: Re: [PATCH] middle-end IFN_ASSUME support [PR106654] Message-ID: Reply-To: Jakub Jelinek References: <4dcc975beb8b39ab4d57b28334c6ab3348855bd9.camel@gmail.com> MIME-Version: 1.0 In-Reply-To: <4dcc975beb8b39ab4d57b28334c6ab3348855bd9.camel@gmail.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.6 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 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 Fri, Oct 14, 2022 at 10:43:16PM +0200, Martin Uecker wrote: > Am Montag, den 10.10.2022, 10:54 +0200 schrieb Jakub Jelinek: > > Hi! > > > > My earlier patches gimplify the simplest non-side-effects assumptions > > into if (cond) ; else __builtin_unreachable (); and throw the rest > > on the floor. > > The following patch attempts to do something with the rest too. > > My recommendation would be to only process side-effect-free > assumptions and warn about the rest (clang does this for > __builtin_assume). I do not think this is worth the I think that is bad choice and makes it useless. > complexity and I am not so sure the semantics of a > hypothetical evaluation are terribly well defined. I think the C++23 paper is quite clear. Yes, you can't verify it in debug mode, but there are many other UBs that are hard to verify through runtime instrumentation. And, OpenMP has a similar feature (though, in that case it is even a stronger guarantee where something is guaranteed to hold across a whole region rather than just on its entry. > That you can not verify this properly by turning it > into traps in debug mode (as this would execute the > side effects) also makes this a terrible feature IMHO. > > MSVC which this feature was based does not seem to make > much to sense to me: https://godbolt.org/z/4Ebar3G9b So maybe their feature is different from what is in C++23, or is badly implemented? I think with what we have in the works for GCC we'll be able to optimize in int f(int i) { [[assume(1 == i++)]]; return (1 == i++); } int g(int i) { [[assume(1 == ++i)]]; return (1 == ++i); } extern int i; int h(void) { [[assume(1 == ++i)]]; return (1 == ++i); } int k(int i) { [[assume(42 == ++i)]]; return i; } at least f/g to return 1; and k to return 41; The h case might take a while to take advantage of. Jakub