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.133.124]) by sourceware.org (Postfix) with ESMTPS id D5DD33858D1E for ; Wed, 4 Jan 2023 11:12:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D5DD33858D1E 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=1672830765; 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: in-reply-to:in-reply-to:references:references; bh=dleq6JdTQZzkciGSdWzr6xPaCfBcw7amw1TKtAYnn7U=; b=VrQIG1EuOdKsUNsLkUB0Q9LivVhvZdHZSfi2lhJYjfk5VcSgh3vvHDUsDJR7bDVML1GrpY AQlLS/800N6RrMahgL1DnNfzthL6KhwgJMkpFoR/CSeW/rBNybjihxOtaMFc9j0n6vce0A Fr1OwcyC31+60YW8iB5lq5Rzj7C5tr8= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-468-pL5fIiiYPYyCNDiCgJi8Bw-1; Wed, 04 Jan 2023 06:12:44 -0500 X-MC-Unique: pL5fIiiYPYyCNDiCgJi8Bw-1 Received: by mail-ej1-f71.google.com with SMTP id hr34-20020a1709073fa200b0083a60c1d7abso21043616ejc.13 for ; Wed, 04 Jan 2023 03:12:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=dleq6JdTQZzkciGSdWzr6xPaCfBcw7amw1TKtAYnn7U=; b=c91/IBsAHlvaKZkFaKNCAuPTFUvKPplQQ9sSmlokAvP2teTSFqv26raMUGv458cIID tJ/Bcc9Ath8icUKEjanPMLzwbAqq7c71RBNsXDBFpoAkMMUl3rjrqb8wm6pQv3ax4q2k 0dAgdoz7rzz/uZHHDBXgU2tJH6Fp/VaYL3MjxdK6Lav/hGynAzzrF/2MAr3NPDd1uk3e a5pwNf7K82KLly7mFCpN85WBPMno412UelGVoeTgdjwvuAMfOHGBccsmhh8r/lcw+085 MrxB9Nu8eXMlilLbkb1gfYJbBrDsXZx67ZbMPoo7cSh0e8sXltvBGt+9EhhkuAnaIgEF HNaA== X-Gm-Message-State: AFqh2kqdvZuQ9Fcm4GKa7THtHlp9GUq5g4+mfXgKIaKq49xIAqGMOoIa evDadbAqviRlXbPLiHvGeBTCBnxj9d+UlibAxMcqDJUSUSZ/IF6UZeuRyDrw2aUPljc/ugTPUWU 3vpKwURx8zU5zIkq2LDp+7fOXN6edNxYd0A== X-Received: by 2002:a17:906:1153:b0:7ff:796b:93ee with SMTP id i19-20020a170906115300b007ff796b93eemr5592632eja.582.1672830762708; Wed, 04 Jan 2023 03:12:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXslNIeisJws+27mSJE7S+PlLOMeYFfw4B255TqbaGyko9+AaPdoY2dTWTOeRTv2Zj1x2fCfLGlTbcUa9vNFXgs= X-Received: by 2002:a17:906:1153:b0:7ff:796b:93ee with SMTP id i19-20020a170906115300b007ff796b93eemr5592628eja.582.1672830762448; Wed, 04 Jan 2023 03:12:42 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Aldy Hernandez Date: Wed, 4 Jan 2023 12:12:30 +0100 Message-ID: Subject: Re: [PATCH] vrp: Handle pointers in maybe_set_nonzero_bits [PR108253] To: Jakub Jelinek Cc: Andrew MacLeod , gcc-patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="0000000000005d8ecc05f16e4322" X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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: --0000000000005d8ecc05f16e4322 Content-Type: text/plain; charset="UTF-8" OK. On Wed, Jan 4, 2023, 10:13 Jakub Jelinek wrote: > Hi! > > maybe_set_nonzero_bits calls set_nonzero_bits which asserts that > var doesn't have pointer type. While we could punt for those > cases, I think we can handle at least some easy cases. > Earlier in maybe_set_nonzero_bits we've checked this is on > (var & cst) == 0 > edge and the other edge is __builtin_unreachable, so if cst > is say 3 as in the testcase, we want to turn it into 4 byte alignment > of the pointer. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2023-01-04 Jakub Jelinek > > PR tree-optimization/108253 > * tree-vrp.cc (maybe_set_nonzero_bits): Handle var with pointer > types. > > * g++.dg/opt/pr108253.C: New test. > > --- gcc/tree-vrp.cc.jj 2023-01-02 09:32:53.634833769 +0100 > +++ gcc/tree-vrp.cc 2023-01-03 15:57:51.613239761 +0100 > @@ -789,8 +789,22 @@ maybe_set_nonzero_bits (edge e, tree var > return; > } > cst = gimple_assign_rhs2 (stmt); > - set_nonzero_bits (var, wi::bit_and_not (get_nonzero_bits (var), > - wi::to_wide (cst))); > + if (POINTER_TYPE_P (TREE_TYPE (var))) > + { > + struct ptr_info_def *pi = SSA_NAME_PTR_INFO (var); > + if (pi && pi->misalign) > + return; > + wide_int w = wi::bit_not (wi::to_wide (cst)); > + unsigned int bits = wi::ctz (w); > + if (bits == 0 || bits >= HOST_BITS_PER_INT) > + return; > + unsigned int align = 1U << bits; > + if (pi == NULL || pi->align < align) > + set_ptr_info_alignment (get_ptr_info (var), align, 0); > + } > + else > + set_nonzero_bits (var, wi::bit_and_not (get_nonzero_bits (var), > + wi::to_wide (cst))); > } > > /* Searches the case label vector VEC for the index *IDX of the CASE_LABEL > --- gcc/testsuite/g++.dg/opt/pr108253.C.jj 2023-01-03 > 16:02:16.366438488 +0100 > +++ gcc/testsuite/g++.dg/opt/pr108253.C 2023-01-03 16:02:33.549191780 +0100 > @@ -0,0 +1,48 @@ > +// PR tree-optimization/108253 > +// { dg-do compile { target c++11 } } > +// { dg-options "-O2" } > + > +struct S > +{ > + int *s; > + S () : s (new int) {} > + S (const S &r) noexcept : s (r.s) { __atomic_fetch_add (r.s, 1, 4); } > +}; > +struct T > +{ > + explicit T (const S &x) : t (x) {} > + const S t; > +}; > +struct U > +{ > + operator int () const { new T (u); return 0; } > + S u; > +}; > +bool foo (int matcher); > +unsigned long bar (unsigned long pos, unsigned long end_pos); > +struct V > +{ > + alignas (4) char v[4]; > +}; > +struct W > +{ > + void baz () > + { > + if (!w) __builtin_abort (); > + if (reinterpret_cast <__UINTPTR_TYPE__> (w->v) % 4 != 0) > __builtin_abort (); > + __builtin_unreachable (); > + } > + [[gnu::noinline]] void qux (unsigned long) { if (!w) bar (0, x); } > + V *w = nullptr; > + unsigned x = 0; > +}; > + > +void > +test () > +{ > + W w; > + U t; > + if (!foo (t)) > + w.baz (); > + w.qux (0); > +} > > Jakub > > --0000000000005d8ecc05f16e4322--