From patchwork Tue Jul 3 07:59:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 938493 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-480890-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="YAj9Nhf1"; 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 41Kc6t6DyJz9s1B for ; Tue, 3 Jul 2018 18:02:44 +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:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=Uzuq8IItLYxUOW7xpwVOwb7QhNEBsm6XVzYLy9cqf7xswTANQH8PH lw3rwBkeg/pjhmI5y1Nwe7m8yzKTV0EAMsCBaeCWKzt4wjmuWEz5Ys/10rZgXqd/ rw5NBgYsQuOcjYreqvEH2d4NY5jM/opYWHFXFbExg2kH6H9n8xnk10= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=qwvKLmIKI3iKrt24CM+DYgT4v8k=; b=YAj9Nhf1fWwEmHigMu8z pTqydP+xDi56tD0Ix8MHavQhfmiwkGv8Z9PR9wFw7u9L0yOoLR+5urbwcUu8/YR9 Um9or5W17GEimQrdowa83wB7eNJmCQTdxzOZNrk4r6GpRfDEeQ4d/npUU/Nsahvz f/O5ighfGy3f0vIhAo+j8Vs= Received: (qmail 54840 invoked by alias); 3 Jul 2018 08:01:41 -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 53153 invoked by uid 89); 3 Jul 2018 07:59:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:vect_ma X-HELO: foss.arm.com Received: from usa-sjc-mx-foss1.foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Jul 2018 07:59:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 89F2818A for ; Tue, 3 Jul 2018 00:59:52 -0700 (PDT) Received: from localhost (unknown [10.32.98.107]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 12AE13F5A0 for ; Tue, 3 Jul 2018 00:59:51 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Avoid matching the same pattern statement twice Date: Tue, 03 Jul 2018 08:59:50 +0100 Message-ID: <87h8lg92bt.fsf@arm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 r262275 allowed pattern matching on pattern statements. Testing for SVE on more benchmarks showed a case where this interacted badly with 14/n. The new over-widening detection could narrow a COND_EXPR A to another COND_EXPR B, which mixed_size_cond could then match. This was working as expected. However, we left B (now dead) in the pattern definition sequence with a non-null PATTERN_DEF_SEQ. mask_conversion also matched B, and unlike most recognisers, didn't clear PATTERN_DEF_SEQ before adding statements to it. This meant that the statements created by mixed_size_cond appeared in two supposedy separate sequences, causing much confusion. This patch removes pattern statements that are replaced by further pattern statements. As a belt-and-braces fix, it also nullifies PATTERN_DEF_SEQ on failure, in the same way Richard B. did recently for RELATED_STMT. I have patches to clean up the PATTERN_DEF_SEQ handling, but they only apply after the complete PR85694 sequence, whereas this needs to go in before 14/n. Tested on aarch64-linux-gnu, arm-linux-gnueabihf and x86_64-linux-gnu. OK to install? Richard 2018-07-03 Richard Sandiford gcc/ * tree-vect-patterns.c (vect_mark_pattern_stmts): Remove pattern statements that have been replaced by further pattern statements. (vect_pattern_recog_1): Clear STMT_VINFO_PATTERN_DEF_SEQ on failure. gcc/testsuite/ * gcc.dg/vect/vect-mixed-size-cond-1.c: New test. Index: gcc/tree-vect-patterns.c =================================================================== --- gcc/tree-vect-patterns.c 2018-07-02 14:34:45.857732632 +0100 +++ gcc/tree-vect-patterns.c 2018-07-03 08:56:56.610251460 +0100 @@ -4295,6 +4295,9 @@ vect_mark_pattern_stmts (gimple *orig_st gimple_stmt_iterator gsi = gsi_for_stmt (orig_stmt, orig_def_seq); gsi_insert_seq_before_without_update (&gsi, def_seq, GSI_SAME_STMT); gsi_insert_before_without_update (&gsi, pattern_stmt, GSI_SAME_STMT); + + /* Remove the pattern statement that this new pattern replaces. */ + gsi_remove (&gsi, false); } else vect_set_pattern_stmt (pattern_stmt, orig_stmt_info, pattern_vectype); @@ -4358,6 +4361,8 @@ vect_pattern_recog_1 (vect_recog_func *r if (!is_pattern_stmt_p (stmt_info)) STMT_VINFO_RELATED_STMT (stmt_info) = NULL; } + /* Clear any half-formed pattern definition sequence. */ + STMT_VINFO_PATTERN_DEF_SEQ (stmt_info) = NULL; return; } Index: gcc/testsuite/gcc.dg/vect/vect-mixed-size-cond-1.c =================================================================== --- /dev/null 2018-06-13 14:36:57.192460992 +0100 +++ gcc/testsuite/gcc.dg/vect/vect-mixed-size-cond-1.c 2018-07-03 08:56:56.610251460 +0100 @@ -0,0 +1,14 @@ +/* { dg-do compile } */ + +int +f (unsigned char *restrict x, short *restrict y) +{ + for (int i = 0; i < 100; ++i) + { + unsigned short a = (x[i] + 11) >> 1; + unsigned short b = (x[i] + 42) >> 2; + unsigned short cmp = y[i] == 0 ? a : b; + int res = cmp + 1; + x[i] = res; + } +}