From patchwork Mon Feb 21 16:14:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1595660 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=bJDhCXSN; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K2S7Y75G5z9sGP for ; Tue, 22 Feb 2022 03:15:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8EA7B385BF92 for ; Mon, 21 Feb 2022 16:15:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EA7B385BF92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1645460101; bh=emSjnL0XhulgqLVESfaxMlSuOVg8FdqLCw0hrKXSGI0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=bJDhCXSNMWw0GEamcC8AKypP6Q9G3FhifVP3bYG3x2GQo0G+RDdyQt2h+SYHhQvHC SZKX+oFQUAUT7EO/z4FAVPd595XG98Zxg8mffuQKNtuLVJdDcSKA4XdDg50LDeIaUy EHRtG5ykvODEWMlPWxL+PG5mPxY8Ugpiad/R1sQw= 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 238F43858410 for ; Mon, 21 Feb 2022 16:14:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 238F43858410 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-388-oWOZa0CvPc2LNtRB7NM72A-1; Mon, 21 Feb 2022 11:14:40 -0500 X-MC-Unique: oWOZa0CvPc2LNtRB7NM72A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3551B1091DA0 for ; Mon, 21 Feb 2022 16:14:39 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBD8577474; Mon, 21 Feb 2022 16:14:33 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 21LGEUED2865106 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 17:14:31 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 21LGEUD92865105; Mon, 21 Feb 2022 17:14:30 +0100 Date: Mon, 21 Feb 2022 17:14:30 +0100 To: Andrew MacLeod , Aldy Hernandez Subject: [PATCH] ranger: Fix up REALPART_EXPR/IMAGPART_EXPR handling [PR104604] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The following testcase is miscompiled since r12-3328. That change assumed that if rhs1 of a GIMPLE_ASSIGN is COMPLEX_CST, then that is the value of the lhs of the stmt, but that is not the case always, only if it is a GIMPLE_SINGLE_RHS stmt. If it is e.g. GIMPLE_UNARY_RHS or GIMPLE_BINARY_RHS (the latter happens in the testcase), then it can be e.g. __complex__ (3, 0) / var and the REALPART_EXPR of that isn't 3, but the realpart of the division. I assume once the ranger can do complex numbers adjust_*part_expr will just fetch one or the other range from a underlying complex range, but until then, we should limit this to what r12-3328 meant to do. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-02-21 Jakub Jelinek PR tree-optimization/104604 * gimple-range-fold.cc (adjust_imagpart_expr, adjust_realpart_expr): Only check if gimple_assign_rhs1 is COMPLEX_CST if gimple_assign_rhs_code is COMPLEX_CST. * gcc.c-torture/execute/pr104604.c: New test. Jakub --- gcc/gimple-range-fold.cc.jj 2022-02-16 09:19:15.741557607 +0100 +++ gcc/gimple-range-fold.cc 2022-02-21 13:50:56.524481955 +0100 @@ -397,7 +397,8 @@ adjust_imagpart_expr (irange &res, const } return; } - if (is_gimple_assign (def_stmt)) + if (is_gimple_assign (def_stmt) + && gimple_assign_rhs_code (def_stmt) == COMPLEX_CST) { tree cst = gimple_assign_rhs1 (def_stmt); if (TREE_CODE (cst) == COMPLEX_CST) @@ -422,7 +423,8 @@ adjust_realpart_expr (irange &res, const if (!SSA_NAME_DEF_STMT (name)) return; - if (is_gimple_assign (def_stmt)) + if (is_gimple_assign (def_stmt) + && gimple_assign_rhs_code (def_stmt) == COMPLEX_CST) { tree cst = gimple_assign_rhs1 (def_stmt); if (TREE_CODE (cst) == COMPLEX_CST) --- gcc/testsuite/gcc.c-torture/execute/pr104604.c.jj 2022-02-21 14:02:01.190303071 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr104604.c 2022-02-21 14:01:25.941789588 +0100 @@ -0,0 +1,34 @@ +/* PR tree-optimization/104604 */ + +unsigned char g; + +__attribute__((noipa)) +unsigned char +foo (_Complex unsigned c) +{ + unsigned char v = g; + _Complex unsigned t = 3; + t /= c; + return v + t; +} + +__attribute__((noipa)) +unsigned char +bar (_Complex unsigned c) +{ + unsigned char v = g; + _Complex unsigned t = 42; + t /= c; + return v + t; +} + +int +main () +{ + unsigned char x = foo (7); + if (x) + __builtin_abort (); + if (bar (7) != 6) + __builtin_abort (); + return 0; +}