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 4C76F3858D33 for ; 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 ; 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 To: Aldy Hernandez , Andrew MacLeod Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] range-op: Fix up ABSU_EXPR handling [PR113756] Message-ID: Reply-To: Jakub Jelinek 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 List-Id: 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 +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