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 0FA8B3858C53 for ; Wed, 7 Feb 2024 09:40:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0FA8B3858C53 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 0FA8B3858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707298833; cv=none; b=TbNQBoGPYetNA1eMNsEcLaqeKycbsdNQFqLhEIWQ7Kge4EhT6K2PtppW38hGde2/QN7xKbBp1XdJTwrjmYuKLOj7gD7/snI1GwfKksLZbe10TMrriGpNuEjJwRZvoNoCBnVFKczm8p+jX7b9mKNR4DGiB1HqDlrK9VZG8p1pfl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707298833; c=relaxed/simple; bh=wOCLG4ux+RORHXANTD5hUe7RjvYrXCDcsMmmSQyRMmg=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=mimqx1oUc7C7mXyoYstcIYi09rfEHqPxGkuWgyX9HEA4L56Nn+wj5RZjzGWE8RZkCKUBW+LWeFH9b4GUm/BJcvq2F4mhextimaQsjYiQ2fEHlplhv6I9Px9dbVssacBt413AqNvqzki1Z0CPTM3AWkBojysR8aiQBXnrq+nuj2I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707298830; 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=yHLfnCWivFM4E6SQiSKHF+BKMYOezvTxntp4NXUkFHY=; b=VNMYSfvNteqJ7mvOoNotYG/24kIGNaTIFHY8cB2dsp5u2VVcLb/w6e/a7So9OhW5/Q5Coo deOcKytr4eXx48Jd9tZUYIJIbUnaK/pZgbhdA1mdKOB9MGq2Hh0COMH891ZRXWH9G39RD7 V5Dv9OperFUKliufpffa0fMTZEN5vCw= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-184-S9fWQtv0OfKVKHHzPLQdjQ-1; Wed, 07 Feb 2024 04:40:29 -0500 X-MC-Unique: S9fWQtv0OfKVKHHzPLQdjQ-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a27eddc1c27so25967066b.3 for ; Wed, 07 Feb 2024 01:40:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707298828; x=1707903628; 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=yHLfnCWivFM4E6SQiSKHF+BKMYOezvTxntp4NXUkFHY=; b=tSJ2i6TnvKZgEc7rL46SljbB7wZaKlDTLuHdHZhjO8njIAvjH+XDmqvaaPxwzoTBmv yhjLOOwKdSYKjQPZkhMrOtPU9Y9kgENDWAQ896OEdWO36ti3mW8IpNatIlwLeeV+o1Sv UqtiihZQYfN0cpRXdl/vXyt11tKWmwd+V/iYUzkZYlTi/a8hLmTUMxiEV5SlHQbt3TG9 0CgiwxkAOQtXcF80LcFDwXtKsy+QTXNxJgHf2t0JIh2iTfY3ljatxjDp+CFNVVQ6Q2SU 0oKntKeXUDbp/c/Fhs1ESuV/xAWdTCF004TsUj6Ec3++/J9mAeMntm8JG+EXQtI0FpnG ZF1A== X-Forwarded-Encrypted: i=1; AJvYcCVfQbXplggxv4IB3KdQGq2DvzMiK4OY3lQJcoMnQ7iYtfDWynra6aNowrX1IYqhD+VqqFbvu6CezZ/X98OHEg87FRYEMwhgrw== X-Gm-Message-State: AOJu0Yyp1jnK9BbvQT8wQ732mGwkTE68h79JNTzgQRDGkAC66Rj2vdkJ JX6JPeHLJ1owyNmxlY8uwc/DkcxPJhX08iffBh+8CWJcv9SP94a8SuCgyvN4rS3CKmn67GqQJPN PUOgo98tUAXS+HN+AJGPpRhPVBstiJMYrxFnE3vAvL1nvrYALsR/SXHY77xl0ONc84CupX3pvu2 Asi1vaaVsIw5oChKyhU7+GDX0RjG+dDw== X-Received: by 2002:aa7:c41a:0:b0:560:4e74:9cf8 with SMTP id j26-20020aa7c41a000000b005604e749cf8mr3658910edq.34.1707298828222; Wed, 07 Feb 2024 01:40:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNVLdrUD50N3XEosW1DH2Sjx2PWbtd3+Tcbl6f+lHdOdeCuhsiNbee1CK9u19ZZvgb3Ju70Q5SQmQhrasLRp4= X-Received: by 2002:aa7:c41a:0:b0:560:4e74:9cf8 with SMTP id j26-20020aa7c41a000000b005604e749cf8mr3658891edq.34.1707298827861; Wed, 07 Feb 2024 01:40:27 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Aldy Hernandez Date: Wed, 7 Feb 2024 10:40:16 +0100 Message-ID: Subject: Re: [PATCH] range-op: Fix up ABSU_EXPR handling [PR113756] To: Jakub Jelinek Cc: Andrew MacLeod , gcc-patches@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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: LGTM. Up to the release managers. Thanks for tracking this down. Aldy On Tue, Feb 6, 2024 at 9:43=E2=80=AFPM Jakub Jelinek wro= te: > > Hi! > > ABSU_EXPR unary expr is special because it has a signed integer > argument and unsigned integer result (of the same precision). > > The following testcase is miscompiled since ABSU_EXPR handling has > been added to range-op because it uses widest_int::from with the > result sign (i.e. UNSIGNED) rather than the operand sign (i.e. SIGNED), > so e.g. for the 32-bit int argument mask ends up 0xffffffc1 or something > similar and even when it has most significant bit in the precision set, > in widest_int (tree-ssa-ccp.cc really should stop using widest_int, but > that is I think stage1 task) it doesn't appear to be negative and so > bit_value_unop ABSU_EXPR doesn't set the resulting mask/value from > oring of the argument and its negation. > > Fixed thusly, not doing that for GIMPLE_BINARY_RHS because I don't know > about a binary op that would need something similar. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2024-02-06 Jakub Jelinek > > PR tree-optimization/113756 > * range-op.cc (update_known_bitmask): For GIMPLE_UNARY_RHS, > use TYPE_SIGN (lh.type ()) instead of sign for widest_int::from > of lh_bits value and mask. > > * gcc.dg/pr113756.c: New test. > > --- gcc/range-op.cc.jj 2024-01-03 11:51:28.199777434 +0100 > +++ gcc/range-op.cc 2024-02-06 16:51:55.549127825 +0100 > @@ -435,8 +435,10 @@ update_known_bitmask (irange &r, tree_co > bit_value_unop (code, sign, prec, &widest_value, &widest_mask, > TYPE_SIGN (lh.type ()), > TYPE_PRECISION (lh.type ()), > - widest_int::from (lh_bits.value (), sign), > - widest_int::from (lh_bits.mask (), sign)); > + widest_int::from (lh_bits.value (), > + TYPE_SIGN (lh.type ())), > + widest_int::from (lh_bits.mask (), > + TYPE_SIGN (lh.type ()))); > break; > case GIMPLE_BINARY_RHS: > bit_value_binop (code, sign, prec, &widest_value, &widest_mask, > --- gcc/testsuite/gcc.dg/pr113756.c.jj 2024-02-06 17:00:52.835679796 +01= 00 > +++ gcc/testsuite/gcc.dg/pr113756.c 2024-02-06 17:00:31.159980326 +01= 00 > @@ -0,0 +1,36 @@ > +/* PR tree-optimization/113756 */ > +/* { dg-do run { target int32plus } } */ > +/* { dg-options "-O2" } */ > + > +int d, e, i, k, l =3D -8; > +signed char h, j; > + > +int > +bar (int n, int o, int p3) > +{ > + int a =3D o - p3, b =3D n - p3, c =3D a + b, f =3D -b, g =3D c < 0 ? -= c : c; > + return a <=3D f && a <=3D g ? o : p3; > +} > + > +void > +foo (int *n, unsigned short o) > +{ > + unsigned p =3D 8896; > + for (; e >=3D 0; e--) > + p =3D 5377; > + for (; h <=3D 0; h++) > + for (; j <=3D 0; j++) > + { > + *n =3D 1611581749; > + i =3D bar (34, p - 5294, *n - 1611581687); > + k =3D i + p + 65535 + o + *n - 1611718251; > + if (k !=3D 0) > + __builtin_abort (); > + } > +} > + > +int > +main () > +{ > + foo (&l, l); > +} > > Jakub >