From patchwork Sat Dec 14 08:21:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1209700 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515983-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ehltEtA/"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="PmE3UW/K"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47ZgVh1sSNz9sPJ for ; Sat, 14 Dec 2019 19:21:45 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=wij yIMdHmOOZ9ZGi74+GnongD+hBxSzR60YzoOcPoidwKWXzzePzn5Ape5rR13N/jvj R7fi8mi7YvjDrK9CAVVR81bFCCnbyFolHLdIwIFJPulrPMAhvB6NUfDHItob/7hc W8PTfiCFzL2yzhOQHznxCVFWwQkvtIL+WZBPbDYc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; s=default; bh=bfe8JIjDQ 1+KnS4wSbhfqAjbM70=; b=ehltEtA/yC5xxxzBlIkGz55sQ4iqodIimkkYYAxHd aDqCXIau3l/n/M/1Kx/T2lOqIwPvgMouXXmDqtaYjoUAqakOdHWzkGPmP2k2fDJG YKiCTQJCJ5stFov6k47C2tsmsTiLDLxuhjvf4IGqheedXZHgMH/8xIQP1baqOiXA Vo= Received: (qmail 129191 invoked by alias); 14 Dec 2019 08:21:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 129183 invoked by uid 89); 14 Dec 2019 08:21:38 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=51135, cared, reformatting X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 14 Dec 2019 08:21:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576311695; 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: content-transfer-encoding:content-transfer-encoding; bh=Z/M7rdWu3x3qk1JFaP3YDNlQFa6ork2WbmFGsqJBORk=; b=PmE3UW/KRZfavu4n32/IWscAiLNZKHkFhQHp+T0048Gnf5vsZQd3NEU468vZXS/h2lRa5k +XnTmBxxxM75CBercS5S5u4sO0ooJ2Xt88xXDd3fFiL9Tgq5D87sNRcjCndWItowRjlUai KGV0tE0v9ruHWu3iqfgoA7KZaWlwPFo= 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-127-KKrgJSpnNP2N-B7E89AZaw-1; Sat, 14 Dec 2019 03:21:29 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 36C18DBA3; Sat, 14 Dec 2019 08:21:28 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-59.ams2.redhat.com [10.36.117.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6F0C35C1D6; Sat, 14 Dec 2019 08:21:27 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id xBE8LOee023568; Sat, 14 Dec 2019 09:21:25 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id xBE8LLPt023389; Sat, 14 Dec 2019 09:21:21 +0100 Date: Sat, 14 Dec 2019 09:21:21 +0100 From: Jakub Jelinek To: Richard Biener , Jan Hubicka Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up handling of __builtin_apply in ipa-pure-const (PR tree-optimization/92930) Message-ID: <20191214082121.GS10088@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-IsSubscribed: yes Hi! __builtin_apply calls some other function, so whether it is const, pure or none of that, whether it can throw or not etc. depends on whether that called function is const or pure or none of that, whether it can throw etc. So, assuming __builtin_apply is const is wrong. The following patch looks larger due to reformatting, but basically took the case BUILT_IN_APPLY: line out. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? If we really cared that much about a builtin almost nobody uses, we could analyze the called function, but this stuff is called from two different spots and I think from the other one the arguments of the __builtin_apply call aren't available. 2019-12-14 Jakub Jelinek PR tree-optimization/92930 * ipa-pure-const.c (special_builtin_state): Don't handle BUILT_IN_APPLY. Formatting fixes. (check_call): Formatting fixes. * gcc.dg/tree-ssa/pr92930.c: New test. Jakub --- gcc/ipa-pure-const.c.jj 2019-10-30 10:49:35.075045961 +0100 +++ gcc/ipa-pure-const.c 2019-12-13 18:52:53.822632062 +0100 @@ -511,35 +511,34 @@ worse_state (enum pure_const_state_e *st but function using them is. */ static bool special_builtin_state (enum pure_const_state_e *state, bool *looping, - tree callee) + tree callee) { if (DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL) switch (DECL_FUNCTION_CODE (callee)) { - case BUILT_IN_RETURN: - case BUILT_IN_UNREACHABLE: - CASE_BUILT_IN_ALLOCA: - case BUILT_IN_STACK_SAVE: - case BUILT_IN_STACK_RESTORE: - case BUILT_IN_EH_POINTER: - case BUILT_IN_EH_FILTER: - case BUILT_IN_UNWIND_RESUME: - case BUILT_IN_CXA_END_CLEANUP: - case BUILT_IN_EH_COPY_VALUES: - case BUILT_IN_FRAME_ADDRESS: - case BUILT_IN_APPLY: - case BUILT_IN_APPLY_ARGS: - case BUILT_IN_ASAN_BEFORE_DYNAMIC_INIT: - case BUILT_IN_ASAN_AFTER_DYNAMIC_INIT: - *looping = false; - *state = IPA_CONST; - return true; - case BUILT_IN_PREFETCH: - *looping = true; - *state = IPA_CONST; - return true; - default: - break; + case BUILT_IN_RETURN: + case BUILT_IN_UNREACHABLE: + CASE_BUILT_IN_ALLOCA: + case BUILT_IN_STACK_SAVE: + case BUILT_IN_STACK_RESTORE: + case BUILT_IN_EH_POINTER: + case BUILT_IN_EH_FILTER: + case BUILT_IN_UNWIND_RESUME: + case BUILT_IN_CXA_END_CLEANUP: + case BUILT_IN_EH_COPY_VALUES: + case BUILT_IN_FRAME_ADDRESS: + case BUILT_IN_APPLY_ARGS: + case BUILT_IN_ASAN_BEFORE_DYNAMIC_INIT: + case BUILT_IN_ASAN_AFTER_DYNAMIC_INIT: + *looping = false; + *state = IPA_CONST; + return true; + case BUILT_IN_PREFETCH: + *looping = true; + *state = IPA_CONST; + return true; + default: + break; } return false; } @@ -624,9 +623,10 @@ check_call (funct_state local, gcall *ca case BUILT_IN_LONGJMP: case BUILT_IN_NONLOCAL_GOTO: if (dump_file) - fprintf (dump_file, " longjmp and nonlocal goto is not const/pure\n"); + fprintf (dump_file, + " longjmp and nonlocal goto is not const/pure\n"); local->pure_const_state = IPA_NEITHER; - local->looping = true; + local->looping = true; break; default: break; @@ -1532,7 +1532,7 @@ propagate_pure_const (void) } } else if (special_builtin_state (&edge_state, &edge_looping, - y->decl)) + y->decl)) ; else state_from_flags (&edge_state, &edge_looping, --- gcc/testsuite/gcc.dg/tree-ssa/pr92930.c.jj 2019-12-13 18:59:19.651732842 +0100 +++ gcc/testsuite/gcc.dg/tree-ssa/pr92930.c 2019-12-13 19:00:34.829582072 +0100 @@ -0,0 +1,19 @@ +/* PR tree-optimization/92930 */ +/* { dg-do compile { target untyped_assembly } } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump "__builtin_apply " "optimized" } } */ +/* { dg-final { scan-tree-dump "__builtin_apply_args" "optimized" } } */ + +void foo (int a, int b, int c, int d, int e, int f, int g); + +static void bar (int a, ...) +{ + __builtin_apply (foo, __builtin_apply_args (), 20); +} + +int +main () +{ + bar (1024, 1025, 1026, 1027, 1028, 1029, 1030); + return 0; +}