From patchwork Tue Aug 20 12:16:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1150081 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-507371-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wYm6KaM0"; 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 46CVC53ZBHz9s3Z for ; Tue, 20 Aug 2019 22:16:31 +1000 (AEST) 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:subject:message-id:mime-version:content-type; q=dns; s= default; b=rLZaKHk0jKgT8/hv7ztiq8ex5AUJHY4Y3Wjc9CP1lE/eP7UQHgANZ 96Cqq4eW/mxL3kU0a2p+Y1mucgxZS5ikJdcLOa24OHWBR2T2euN0C7gU2vAo25NY JIZvw8j710MzT60ChVyqAyDQo0Oa61ObzOzBJxtGxuOJTXq8NNuzss= 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:subject:message-id:mime-version:content-type; s= default; bh=YKQuoNHhYXkxrT9SU2j0WKWaW34=; b=wYm6KaM09bjPQAbCywMM RAo8uojxs/F0hEE0WgwXffd3dO574s13ahR8pzeH4QLWvYeh7YJAb7EKC9Nfg6Y0 SE/H5yu4uZC3cJCLLo9nlviBZzMqkCmbCbLQ/6btSIFRFYGGQUuscvQ9Y110+FAF 4jY+LU5KKHbpkSKYs01efoc= Received: (qmail 53678 invoked by alias); 20 Aug 2019 12:16:24 -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 53303 invoked by uid 89); 20 Aug 2019 12:16:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.1 spammy=barriers X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Aug 2019 12:16:22 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C63B3AE34 for ; Tue, 20 Aug 2019 12:16:20 +0000 (UTC) Date: Tue, 20 Aug 2019 14:16:20 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR91482 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Excessive use of __builtin_assume_aligned can cause missed optimizations because those calls are propagation barriers. The following removes those that are redundant and provide no extra information, on the testcase allowng store-merging to apply. Since the bit lattice and the const/copy lattice are merged we cannot track this during CCP propagation (make a copy out of the redundant call and propagate that out). Thus I apply it in the CCP specific folding routine called during substitute_and_fold only. Bootstrap and regtest running on x86_64-unknown-linux-gnu. Richard. 2019-08-20 Richard Biener PR tree-optimization/91482 * tree-ssa-ccp.c (ccp_folder::fold_stmt): Remove useless BUILT_IN_ASSUME_ALIGNED calls. * gcc.dg/tree-ssa/pr91482.c: New testcase. Index: gcc/tree-ssa-ccp.c =================================================================== --- gcc/tree-ssa-ccp.c (revision 274670) +++ gcc/tree-ssa-ccp.c (working copy) @@ -2315,6 +2315,27 @@ ccp_folder::fold_stmt (gimple_stmt_itera } } + /* If there's no extra info from an assume_aligned call, + drop it so it doesn't act as otherwise useless dataflow + barrier. */ + if (gimple_call_builtin_p (stmt, BUILT_IN_ASSUME_ALIGNED)) + { + tree ptr = gimple_call_arg (stmt, 0); + ccp_prop_value_t ptrval = get_value_for_expr (ptr, true); + ccp_prop_value_t val = bit_value_assume_aligned (stmt, NULL_TREE, + ptrval, false); + unsigned int ptralign = least_bit_hwi (ptrval.mask.to_uhwi ()); + unsigned int align = least_bit_hwi (val.mask.to_uhwi ()); + if (ptralign == align + && ((TREE_INT_CST_LOW (ptrval.value) & (align - 1)) + == (TREE_INT_CST_LOW (val.value) & (align - 1)))) + { + bool res = update_call_from_tree (gsi, ptr); + gcc_assert (res); + return true; + } + } + /* Propagate into the call arguments. Compared to replace_uses_in this can use the argument slot types for type verification instead of the current argument type. We also can safely Index: gcc/testsuite/gcc.dg/tree-ssa/pr91482.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/pr91482.c (nonexistent) +++ gcc/testsuite/gcc.dg/tree-ssa/pr91482.c (working copy) @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ccp1 -fdump-tree-store-merging" } */ + +void write64 (void *p) +{ + unsigned *p1 = (unsigned *) __builtin_assume_aligned (p, 8); + *p1++ = 0; + unsigned *p2 = (unsigned *) __builtin_assume_aligned (p1, 4); + *p2++ = 1; +} + +/* { dg-final { scan-tree-dump-times "__builtin_assume_aligned" 1 "ccp1" } } */ +/* { dg-final { scan-tree-dump "New sequence of 1 stores to replace old one of 2 stores" "store-merging" { target lp64 } } } */