Message ID | ZcKZz7PBdlnJxzOM@tucnak |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1812338dyb; Tue, 6 Feb 2024 12:43:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcJ5S7AjbnkBcW7JOKhmFZj+1jp8RTO06rEkq74rIRdQxObG/+7XYDOwZMdsmZdHK+D8AL X-Received: by 2002:a05:620a:24c7:b0:783:f898:40f with SMTP id m7-20020a05620a24c700b00783f898040fmr4619076qkn.35.1707252223729; Tue, 06 Feb 2024 12:43:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707252223; cv=pass; d=google.com; s=arc-20160816; b=PtHbqr3mXripFugkW+H24XbGq+WSjV3SpxfyTtiemEa1t78UBpBKSzLVWmnurle2YJ WYpj6YMwIXlLxewMFKsosmnRqducANKTMkM67D72QFfl6645j/t+Z09S7QTgInuA8WTi 9qURs0nT7eqdFHxNQvKT/fKfRcqyiPM58zh4/G/udJz8yPzKHVE7+Xx3M7G0/yjNmdAf n1yHfl8rFI6d0hCnNpVTQNGU1uYZNHefF8CFUfdjGR+DF8EuqTUQG6QhVM5bRaOtYAXZ YplminApw7gd7rSZja6KyjUJs2BSxnB3aT/9LElCtxymSN3aVOO0/3e4cXY+78tmpFbL apUg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=cJmkTi0kO0QJZDax+zM5U7G2jHyZzDkdflsQMwC/lb0=; fh=StHa4rLF+uSw9jB4ZEBRbIwr4XJfaznTgFV3NpQLUQ0=; b=RVOMVlsGLgCv0y+jnmDkgLMbodJlPOTKnbmZ85W8xOhhtIzFBgnS9IFzy8NK6RucWf 0Nmh8EfS6j7o/8kPYKo44Qseem8FZ6TcvIbEBBl4Ui+U7I59Ox7SagQ8MrXyqsi5mypf /1a2Yy6/fWywOZGoPCEEmRaCL4S2H5XfP3WmTmltqO/Ppq6nI+k4PSsbggZ3FoUvys8V OXEyu7XSt3UTkVxTSwW5SzcnAzPIrnCrUnIDYskqHupcY1NzzONIHdxojLK9amOgJyDi rU2EgICmZSc3MP8zM/w3jKc9uzsfokKwzLxLrwUXhluOLjQgT7jroWqKSYCNG7bNq8i9 VnkQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MpqK76lf; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCVWMn2S+6bKifOOw9HULjOyRCt55Lf+Qpq8kJ/EGYrbdNxHRGMcKWjVxr5mHsSvoY7dDn5963hEoN9o6T72mJpMmbZU/w== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h1-20020a05620a21c100b007834b7bf527si3020854qka.351.2024.02.06.12.43.43 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 12:43:43 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MpqK76lf; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68EC33858439 for <ouuuleilei@gmail.com>; Tue, 6 Feb 2024 20:43:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 4C76F3858D33 for <gcc-patches@gcc.gnu.org>; Tue, 6 Feb 2024 20:43:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C76F3858D33 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 4C76F3858D33 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=1707252183; cv=none; b=xRPZWrz3w9Pz4cgLVTY923Jqr/i1b5TiaF2+D0L8xgSV+Q1Ba77NmeC/fb6OlAnOxvoHK0OjhAHrDW981nktZQ4zyTcqtFcnWK2wcKxSZ5W0MKyAMRvDdWpushGvQzrWkMBmRTKSu+V5COXg/Bz2apBkl2/J94cRYK+aLNcR5lw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707252183; c=relaxed/simple; bh=phNRoC1Gl47PiF1nYRiL4c6wlkvNIRHM/4WLr1cimwM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=SjVQzAsRZgXb6RhBkuR9S5agN095F8briuFoL7a+c2GHBt2eF2rroRHWxBQyVPHw6cWKY8Wrj/BvyEu5LP8gTGCa/9E5pP1PDL/kjUXHAT5VLXyMd632sKWMnlkfvx3c/vJMoh0+stIJ1tgsz6nrU4AeNeu1aK/HOCPHzMP+Qfw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707252181; 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; bh=cJmkTi0kO0QJZDax+zM5U7G2jHyZzDkdflsQMwC/lb0=; b=MpqK76lf3LN4bQJOCQd00gYox+4k/8VLlRpHZ17/fDKSWyXCBBkcnUqFUB2MgSeFAdNVv4 ZqCZA6m6jocimMKrDMVlCy78o8bbDpcPv3sFUOXe8H/o9fJdtawQ9lM6F8/v1G0RUDg4TA tVEPGsj/zrz91ZAw24fsYOvoQnUSOfs= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-596-AvGuk8V3OA-nqDcEFqO0mg-1; Tue, 06 Feb 2024 15:43:00 -0500 X-MC-Unique: AvGuk8V3OA-nqDcEFqO0mg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 32FD638130A9 for <gcc-patches@gcc.gnu.org>; Tue, 6 Feb 2024 20:43:00 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E66AA1C060AF; Tue, 6 Feb 2024 20:42:58 +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 416KguKb1961326 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 6 Feb 2024 21:42:57 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 416Kgu8H1961325; Tue, 6 Feb 2024 21:42:56 +0100 Date: Tue, 6 Feb 2024 21:42:55 +0100 From: Jakub Jelinek <jakub@redhat.com> To: Aldy Hernandez <aldyh@redhat.com>, Andrew MacLeod <amacleod@redhat.com> Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] range-op: Fix up ABSU_EXPR handling [PR113756] Message-ID: <ZcKZz7PBdlnJxzOM@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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.8 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Reply-To: Jakub Jelinek <jakub@redhat.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790183707656003665 X-GMAIL-MSGID: 1790183707656003665 |
Series |
range-op: Fix up ABSU_EXPR handling [PR113756]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jakub Jelinek
Feb. 6, 2024, 8:42 p.m. UTC
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 <jakub@redhat.com> 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. Jakub
Comments
LGTM. Up to the release managers. Thanks for tracking this down. Aldy On Tue, Feb 6, 2024 at 9:43 PM Jakub Jelinek <jakub@redhat.com> wrote: > > 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 <jakub@redhat.com> > > 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 +0100 > +++ gcc/testsuite/gcc.dg/pr113756.c 2024-02-06 17:00:31.159980326 +0100 > @@ -0,0 +1,36 @@ > +/* PR tree-optimization/113756 */ > +/* { dg-do run { target int32plus } } */ > +/* { dg-options "-O2" } */ > + > +int d, e, i, k, l = -8; > +signed char h, j; > + > +int > +bar (int n, int o, int p3) > +{ > + int a = o - p3, b = n - p3, c = a + b, f = -b, g = c < 0 ? -c : c; > + return a <= f && a <= g ? o : p3; > +} > + > +void > +foo (int *n, unsigned short o) > +{ > + unsigned p = 8896; > + for (; e >= 0; e--) > + p = 5377; > + for (; h <= 0; h++) > + for (; j <= 0; j++) > + { > + *n = 1611581749; > + i = bar (34, p - 5294, *n - 1611581687); > + k = i + p + 65535 + o + *n - 1611718251; > + if (k != 0) > + __builtin_abort (); > + } > +} > + > +int > +main () > +{ > + foo (&l, l); > +} > > Jakub >
--- 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 +0100 +++ gcc/testsuite/gcc.dg/pr113756.c 2024-02-06 17:00:31.159980326 +0100 @@ -0,0 +1,36 @@ +/* PR tree-optimization/113756 */ +/* { dg-do run { target int32plus } } */ +/* { dg-options "-O2" } */ + +int d, e, i, k, l = -8; +signed char h, j; + +int +bar (int n, int o, int p3) +{ + int a = o - p3, b = n - p3, c = a + b, f = -b, g = c < 0 ? -c : c; + return a <= f && a <= g ? o : p3; +} + +void +foo (int *n, unsigned short o) +{ + unsigned p = 8896; + for (; e >= 0; e--) + p = 5377; + for (; h <= 0; h++) + for (; j <= 0; j++) + { + *n = 1611581749; + i = bar (34, p - 5294, *n - 1611581687); + k = i + p + 65535 + o + *n - 1611718251; + if (k != 0) + __builtin_abort (); + } +} + +int +main () +{ + foo (&l, l); +}