From patchwork Thu Mar 11 08:41:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1451008 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: 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=F6feaf2f; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4Dx2Vx4Lkxz9sRN for ; Thu, 11 Mar 2021 19:42:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 07B253840C0A; Thu, 11 Mar 2021 08:41:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07B253840C0A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1615452119; bh=AFSYMvdoeT6n/4Z3PQpYuMtAiQ1JrsdkLjT81p4RCJc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=F6feaf2fQfwIxwGn/hlNw7DXHAfTAIcWxF2l9lZjRX3PhwrffTMr64Km09E+HUSdP Ue+iJNYQy5f13eFbSa7QW/Irv02S6woqHSkdu+p+93uxDywoDtOIlfB/pBTxJyFEuk ZkCg7P+GQrtGnhkKQOZ4PuWjuzW6YqjHKcms5fro= 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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 18FF83870860 for ; Thu, 11 Mar 2021 08:41:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 18FF83870860 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-390-9D5r9XmJNXu9Batw388s8Q-1; Thu, 11 Mar 2021 03:41:53 -0500 X-MC-Unique: 9D5r9XmJNXu9Batw388s8Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 546D58015BA; Thu, 11 Mar 2021 08:41:52 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-238.ams2.redhat.com [10.36.113.238]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC4C860C66; Thu, 11 Mar 2021 08:41:51 +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 12B8fmoE3928120 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 11 Mar 2021 09:41:49 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 12B8fmIN3928119; Thu, 11 Mar 2021 09:41:48 +0100 Date: Thu, 11 Mar 2021 09:41:47 +0100 To: Richard Biener , Jan Hubicka Subject: [PATCH] icf: Check return type of internal fn calls [PR99517] Message-ID: <20210311084147.GG745611@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" Hi! The following testcase is miscompiled, because IPA-ICF considers the two functions identical. They aren't, the types of the .VEC_CONVERT call lhs is different. But for calls to internal functions, there is no fntype nor callee with a function type to compare, so all we compare is just the ifn, arguments and some call flags. The following patch fixes it by checking the internal fn calls like e.g. gimple assignments where the type of the lhs is checked too. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2021-03-11 Jakub Jelinek PR ipa/99517 * ipa-icf-gimple.c (func_checker::compare_gimple_call): For internal function calls with lhs fail if the lhs don't have compatible types. * gcc.target/i386/avx2-pr99517-1.c: New test. * gcc.target/i386/avx2-pr99517-2.c: New test. Jakub --- gcc/ipa-icf-gimple.c.jj 2021-01-04 10:25:38.752234741 +0100 +++ gcc/ipa-icf-gimple.c 2021-03-10 15:02:06.287502784 +0100 @@ -667,7 +667,7 @@ func_checker::compare_gimple_call (gcall tree fntype1 = gimple_call_fntype (s1); tree fntype2 = gimple_call_fntype (s2); - /* For direct calls we verify that types are comopatible so if we matced + /* For direct calls we verify that types are compatible so if we matched callees, callers must match, too. For indirect calls however verify function type. */ if (!gimple_call_fndecl (s1)) @@ -703,6 +703,14 @@ func_checker::compare_gimple_call (gcall t1 = gimple_get_lhs (s1); t2 = gimple_get_lhs (s2); + /* For internal calls, lhs types need to be verified, as neither fntype nor + callee comparisons can catch that. */ + if (gimple_call_internal_p (s1) + && t1 + && t2 + && !compatible_types_p (TREE_TYPE (t1), TREE_TYPE (t2))) + return return_false_with_msg ("GIMPLE internal call LHS type mismatch"); + return compare_operand (t1, t2, get_operand_access_type (&map, t1)); } --- gcc/testsuite/gcc.target/i386/avx2-pr99517-1.c.jj 2021-03-10 15:28:33.175959797 +0100 +++ gcc/testsuite/gcc.target/i386/avx2-pr99517-1.c 2021-03-10 15:28:57.117695186 +0100 @@ -0,0 +1,25 @@ +/* PR ipa/99517 */ +/* { dg-do run { target avx2 } } */ +/* { dg-additional-sources "avx2-pr99517-2.c" } */ +/* { dg-options "-O2 -mavx2" } */ + +#include "avx2-check.h" + +typedef signed char v32qi __attribute__((vector_size(32))); +typedef int v4si __attribute__((vector_size(16))); +typedef long long int v4di __attribute__((vector_size(32))); +typedef double v4df __attribute__((vector_size(32))); +extern v32qi foo (v4si); +extern v32qi bar (v4si); + +static void +avx2_test (void) +{ + v4si a = { 1, -2, 3, -4 }; + __asm ("" : "+x" (a)); + v4di b = (v4di) bar (a); + v4df c = (v4df) foo (a); + if (b[0] != 1 || c[0] != 1.0 || b[1] != -2 || c[1] != -2.0 + || b[2] != 3 || c[2] != 3.0 || b[3] != -4 || c[3] != -4.0) + __builtin_abort (); +} --- gcc/testsuite/gcc.target/i386/avx2-pr99517-2.c.jj 2021-03-10 15:30:33.974624677 +0100 +++ gcc/testsuite/gcc.target/i386/avx2-pr99517-2.c 2021-03-10 15:30:28.529684856 +0100 @@ -0,0 +1,20 @@ +/* PR ipa/99517 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mavx2" } */ + +typedef signed char v32qi __attribute__((vector_size(32))); +typedef int v4si __attribute__((vector_size(16))); +typedef long long int v4di __attribute__((vector_size(32))); +typedef double v4df __attribute__((vector_size(32))); + +v32qi +foo (v4si x) +{ + return (v32qi) __builtin_convertvector (x, v4df); +} + +v32qi +bar (v4si x) +{ + return (v32qi) __builtin_convertvector (x, v4di); +}