From patchwork Fri Apr 16 07:49:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1466891 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=2620:52:3:1:0:246e:9693:128c; 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=FIyJ3034; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4FM7dm1t4wz9sVv for ; Fri, 16 Apr 2021 17:49:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E358E3890427; Fri, 16 Apr 2021 07:49:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E358E3890427 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1618559368; bh=b/npl+64JWdid1ztmyqapqwKorePBvg8G2bA6cqGHBM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=FIyJ3034oNLwRmarEpmm5/PbXaIS1sKwZBzBy5RutNo6ZAZ49fmEQsrNfVj1L+h2j owibVLAlWxPFyAAmBm1fXrz2skyglN4QCFvkRfgMJv7NAzk0HRKRqemEHljAH+fmmz 6m6oaaXYesRuzndoK8G5WNiookOijhdtmEKqbTpk= 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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id EA7A6388E828 for ; Fri, 16 Apr 2021 07:49:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EA7A6388E828 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-140-v_ffsvxgMqqaFwN_AMicOw-1; Fri, 16 Apr 2021 03:49:22 -0400 X-MC-Unique: v_ffsvxgMqqaFwN_AMicOw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7E9F107ACCD; Fri, 16 Apr 2021 07:49:21 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-115-183.ams2.redhat.com [10.36.115.183]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A99E62951; Fri, 16 Apr 2021 07:49:21 +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 13G7nIgY3207560 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 16 Apr 2021 09:49:18 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 13G7nHxY3207559; Fri, 16 Apr 2021 09:49:17 +0200 Date: Fri, 16 Apr 2021 09:49:17 +0200 To: Richard Biener , Richard Sandiford Subject: [PATCH] vectorizer: Remove dead scalar .COND_* calls from vectorized loops [PR99767] Message-ID: <20210416074917.GL1179226@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.8 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 ICEs because disabling of DCE means there are dead stmts in the loop (though, in theory they could become dead only shortly before if-conv through some optimization), ifcvt which goes through all stmts in the loop if-converts them into .COND_DIV etc. internal fn calls in the copy of the loop meant for vectorization only, the loop is successfully vectorized but the particular .COND_* call is not because it isn't a live statement and the scalar .COND_* remains in the IL until expansion where it ICEs because these ifns only support vectors and not scalars. These ifns are similar to .MASK_{LOAD,STORE} in this behavior. One possible fix could be to expand scalar versions of them during expansion, basically undoing what if-conv did to create them, i.e. expand them as the lhs = else; if (mask) { lhs = statement; } or so. For .MASK_LOAD we have code to replace them in vect_transform_loop already though (not needed for .MASK_STORE, as stores should be always live and thus always vectorized), so this patch instead replaces .COND_* similarly to .MASK_LOAD in that loop, with the small difference that lhs = .MASK_LOAD (...); is replaced by lhs = 0; while lhs = .COND_* (..., else_arg); is replaced by lhs = else_arg. The statement must be dead, otherwise it would be vectorized, so I think it is not a big deal we don't turn it back into multiple basic blocks etc. (and it might be not possible to do that at that point). Bootstrapped/regtested on {x86_64,i686,aarch64}-linux, ok for trunk? 2021-04-16 Jakub Jelinek PR target/99767 * tree-vect-loop.c (vect_transform_loop): Don't remove just dead scalar .MASK_LOAD calls, but also dead .COND_* calls - replace them by their last argument. * gcc.target/aarch64/pr99767.c: New test. Jakub --- gcc/tree-vect-loop.c.jj 2021-04-07 12:35:13.000000000 +0200 +++ gcc/tree-vect-loop.c 2021-04-15 17:21:58.750101894 +0200 @@ -9676,7 +9676,10 @@ vect_transform_loop (loop_vec_info loop_ !gsi_end_p (gsi); gsi_next (&gsi)) { gcall *call = dyn_cast (gsi_stmt (gsi)); - if (call && gimple_call_internal_p (call, IFN_MASK_LOAD)) + if (!call || !gimple_call_internal_p (call)) + continue; + internal_fn ifn = gimple_call_internal_fn (call); + if (ifn == IFN_MASK_LOAD) { tree lhs = gimple_get_lhs (call); if (!VECTOR_TYPE_P (TREE_TYPE (lhs))) @@ -9686,6 +9689,17 @@ vect_transform_loop (loop_vec_info loop_ gsi_replace (&gsi, new_stmt, true); } } + else if (conditional_internal_fn_code (ifn) != ERROR_MARK) + { + tree lhs = gimple_get_lhs (call); + if (!VECTOR_TYPE_P (TREE_TYPE (lhs))) + { + tree else_arg + = gimple_call_arg (call, gimple_call_num_args (call) - 1); + gimple *new_stmt = gimple_build_assign (lhs, else_arg); + gsi_replace (&gsi, new_stmt, true); + } + } } } /* BBs in loop */ --- gcc/testsuite/gcc.target/aarch64/pr99767.c.jj 2021-04-15 17:28:10.466928380 +0200 +++ gcc/testsuite/gcc.target/aarch64/pr99767.c 2021-04-15 17:28:45.653533566 +0200 @@ -0,0 +1,16 @@ +/* PR target/99767 */ +/* { dg-do compile } */ +/* { dg-options " -O1 -fopenmp-simd -fno-tree-dce -march=armv8-a+sve" } */ + +int a[1024], b[1024]; + +void +foo (void) +{ + #pragma omp simd + for (int i = 0; i < 1024; i++) + if (b[i] > 23) { + a[i] = b[i] + 1; + int v = 1 / 0; /* { dg-warning "division by zero" } */ + } +}