From patchwork Mon Aug 27 20:30:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 962630 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-484535-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="UB9HWSX5"; 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 41zk7t5wf0z9s4V for ; Tue, 28 Aug 2018 06:31:54 +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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=rncqlF4pMJ3Q3bCZvpTJoErUo4I+Z0uoesnXqHpmWPYY/x4fz6 7Ep49P9I+nsWjBtVGyZUStsPn29VNd9/iVaaxOY9gVdMnyV0eyj7C/Fo+jI3p+Pk P0Yxt10M8Fp8tPyZNwgRc7qak1s88JVd8vmiuL47iAEQiGDy1qmdmnOnQ= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=KiH2ZOuuBl6LXq9SdEfy4NTmVn4=; b=UB9HWSX5AZshBZ3zG647 2r/vWcKxQbODnlBB1aVNPjXssduwbr10D8UWWbG+fYfmKH2/DU7F5RqbC0G46U/1 XAUOdOrsnLPvb/F1ADRRXUsrrkq3c6kv7vSfD5jiMBKFTqZUzprkaDR6xNOURovC s0H6mcyd94C4fdmTcMCSMks= Received: (qmail 91605 invoked by alias); 27 Aug 2018 20:31:15 -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 91271 invoked by uid 89); 27 Aug 2018 20:30:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy=66, 2526 X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 27 Aug 2018 20:30:25 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7D81DC3E for ; Mon, 27 Aug 2018 20:30:10 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-8.rdu2.redhat.com [10.10.112.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7469F1012DBA for ; Mon, 27 Aug 2018 20:30:10 +0000 (UTC) To: gcc-patches From: Jeff Law Subject: [committed] Fix minor bug in recently added sanity test in tree-ssa-dse.c Openpgp: preference=signencrypt Message-ID: <7331c16f-3725-c528-8cd6-7f38bc19f0c2@redhat.com> Date: Mon, 27 Aug 2018 14:30:08 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 X-IsSubscribed: yes We recently changes tree-ssa-dse.c to not trim stores outside the bounds of the referenced object. This is generally a good thing. However, there are cases where the object doesn't have a usable size. We see this during kernel builds, at least on the microblaze target. We've got... _1 = p_47(D)->stack; childregs_48 = &MEM[(void *)_1 + 8040B]; [ ... ] memset (childregs_48, 0, 152); [ ... ] MEM[(struct pt_regs *)_1 + 8040B].pt_mode = 1; We want to trim the memset call as the assignment to pt_mode is the last word written by the memset call, thus making the store of that word via memset dead. Our ref->base is: (gdb) p debug_tree ($66) > arg:0 public unsigned SI size unit-size align:32 warn_if_not_align:0 symtab:0 alias-set 8 canonical-type 0x7fffe9e21150 context pointer_to_this reference_to_this > visited def_stmt _1 = p_47(D)->stack; version:1 ptr-info 0x7fffe8f65fa8> arg:1 constant 8040>> Note the void type. Those do not have a suitable TYPE_SIZE_UNIT, thus causing an ICE when we try to reference it within compute_trims: /* But don't trim away out of bounds accesses, as this defeats proper warnings. */ if (*trim_tail && compare_tree_int (TYPE_SIZE_UNIT (TREE_TYPE (ref->base)), last_orig) <= 0) The fix is obvious enough. Don't do the check when the underlying type has no usable TYPE_SIZE_UNIT. I pondered moving the tests into the code that determines whether or not we do byte tracking DSE, but decided the current location was fine. Bootstrapped and regression tested on x86. Also verified the original testfile will build with a microblaze cross compiler. Installing on the trunk momentarily. jeff diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ac46b7422bc..a8ab83580b5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-08-27 Jeff Law + + * tree-ssa-dse.c (compute_trims): Handle case where the reference's + type does not have a TYPE_SIZE_UNIT. + 2018-08-27 Steve Ellcey * config/aarch64/aarch64-speculation.cc: Replace include of cfg.h diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 824372c346a..6410f4638cc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-08-27 Jeff Law + + * gcc.c-torture/compile/dse.c: New test. + 2018-08-27 Jakub Jelinek PR c++/86993 diff --git a/gcc/testsuite/gcc.c-torture/compile/dse.c b/gcc/testsuite/gcc.c-torture/compile/dse.c new file mode 100644 index 00000000000..908e6503eb4 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/dse.c @@ -0,0 +1,19 @@ +typedef unsigned long microblaze_reg_t; +struct pt_regs +{ + microblaze_reg_t msr; + int pt_mode; +}; +struct task_struct +{ + void *stack; +}; +int +copy_thread (struct task_struct *p) +{ + struct pt_regs *childregs = + (((struct pt_regs *) ((1 << 13) + ((void *) (p)->stack))) - 1); + memset (childregs, 0, sizeof (struct pt_regs)); + childregs->pt_mode = 1; +} + diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c index 016aa6cc97c..bddbbe8377a 100644 --- a/gcc/tree-ssa-dse.c +++ b/gcc/tree-ssa-dse.c @@ -252,6 +252,7 @@ compute_trims (ao_ref *ref, sbitmap live, int *trim_head, int *trim_tail, /* But don't trim away out of bounds accesses, as this defeats proper warnings. */ if (*trim_tail + && TYPE_SIZE_UNIT (TREE_TYPE (ref->base)) && compare_tree_int (TYPE_SIZE_UNIT (TREE_TYPE (ref->base)), last_orig) <= 0) *trim_tail = 0;