From patchwork Fri Apr 9 07:49:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1464201 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=TJFfp8JM; 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 4FGqzM31Qqz9sPf for ; Fri, 9 Apr 2021 17:49:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7CDDA3989CA9; Fri, 9 Apr 2021 07:49:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CDDA3989CA9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1617954582; bh=ZBpDlmQDWgujJAzCfKEccn++8VPzx77/Y8BBpmugNds=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=TJFfp8JMlyVV3RlAXQlwUGSQOGno0KeDLJpVIjlP5T0LwlV6u1GUk8YSYQiKSqvpa tOOA/19koUb4gK8udCAw9Ek2PE2OkSM1h3BSHAGQXFGo/BcqlzhyyEGfb3+UuKWPh6 uoxKVtLSfZY/DwF7R123qvYvXfU3U4OVI/tZ9/tk= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 0F12B3989C9F for ; Fri, 9 Apr 2021 07:49:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0F12B3989C9F 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-23-snyWLGg-P_ekCQ2qG2TM-A-1; Fri, 09 Apr 2021 03:49:37 -0400 X-MC-Unique: snyWLGg-P_ekCQ2qG2TM-A-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 D1DEC801814; Fri, 9 Apr 2021 07:49:35 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-35.ams2.redhat.com [10.36.112.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 69CB75D71D; Fri, 9 Apr 2021 07:49:35 +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 1397nW0g798219 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 9 Apr 2021 09:49:32 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1397nUdu798218; Fri, 9 Apr 2021 09:49:30 +0200 Date: Fri, 9 Apr 2021 09:49:30 +0200 To: Segher Boessenkool Subject: [PATCH] combine: Avoid propagation of (clobber (const_int 0)) into DEBUG_INSNs [PR99830] Message-ID: <20210409074930.GB1179226@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.9 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! On the following testcase on aarch64 the combiner propagates (clobber:TI (const_int 0)) into a DEBUG_INSN. Such clobbers are specific to the combiner, created by gen_lowpart_for_combine: fail: return gen_rtx_CLOBBER (omode, const0_rtx); which can be embedded anywhere and the combiner hopes they never match anything. That is hopefully the case of all instructions that go through recog, but for DEBUG_INSNs we don't have any strict rules on what matches and what doesn't and so if combiner calls propagate_for_debug with src containing such clobbers embedded in it, it will happily propagate it into DEBUG_INSNs and cause problems later (in this case ICEs during LRA). The following patch ensures that if such clobbers would be propagated into some DEBUG_INSNs that such DEBUG_INSNs are reset to the unknown state. propagate_for_debug uses volatile_insn_p check to determine if something needs to be reset after propagation and the patch replaces the combiner specific clobbers with UNSPEC_VOLATILE that volatile_insn_p will return true on and thus valtrack.c reset those DEBUG_INSNs. Bootstrapped/regtested on x86_64-linux and i686-linux and tested in cross to aarch64-linux on the testcase, ok for trunk? 2021-04-09 Jakub Jelinek PR debug/99830 * combine.c (combine_propagate_for_debug): New function. (try_combine): Use combine_propagate_for_debug instead of propagate_for_debug. * gcc.dg/pr99830.c: New test. Jakub --- gcc/combine.c.jj 2021-04-07 12:35:03.060224972 +0200 +++ gcc/combine.c 2021-04-08 16:22:17.851459742 +0200 @@ -2610,6 +2610,30 @@ count_auto_inc (rtx, rtx, rtx, rtx, rtx, return 0; } +/* Wrapper around propagate_for_debug to deal with gen_lowpart_for_combine + (clobber (const_int 0)). In normal insns a clobber of const0_rtx nested + somewhere will cause the pattern not to be recognized, but in debug insns + it doesn't, one needs to use something on which volatile_insn_p is true + instead. */ + +static void +combine_propagate_for_debug (rtx_insn *insn, rtx_insn *last, rtx dest, rtx src, + basic_block this_basic_block) +{ + subrtx_iterator::array_type array; + FOR_EACH_SUBRTX (iter, array, src, ALL) + { + const_rtx x = *iter; + if (GET_CODE (x) == CLOBBER && XEXP (x, 0) == const0_rtx) + { + src = gen_rtx_UNSPEC_VOLATILE (GET_MODE (dest), + gen_rtvec (1, const0_rtx), -1); + break; + } + } + propagate_for_debug (insn, last, dest, src, this_basic_block); +} + /* Try to combine the insns I0, I1 and I2 into I3. Here I0, I1 and I2 appear earlier than I3. I0 and I1 can be zero; then we combine just I2 into I3, or I1 and I2 into @@ -4200,8 +4224,8 @@ try_combine (rtx_insn *i3, rtx_insn *i2, i2src while its original mode is temporarily restored, and then clear i2scratch so that we don't do it again later. */ - propagate_for_debug (i2, last_combined_insn, reg, i2src, - this_basic_block); + combine_propagate_for_debug (i2, last_combined_insn, reg, + i2src, this_basic_block); i2scratch = false; /* Put back the new mode. */ adjust_reg_mode (reg, new_mode); @@ -4235,12 +4259,13 @@ try_combine (rtx_insn *i3, rtx_insn *i2, with this copy we have created; then, replace the copy with the SUBREG of the original shared reg, once again changed to the new mode. */ - propagate_for_debug (first, last, reg, tempreg, - this_basic_block); + combine_propagate_for_debug (first, last, reg, tempreg, + this_basic_block); adjust_reg_mode (reg, new_mode); - propagate_for_debug (first, last, tempreg, - lowpart_subreg (old_mode, reg, new_mode), - this_basic_block); + combine_propagate_for_debug (first, last, tempreg, + lowpart_subreg (old_mode, reg, + new_mode), + this_basic_block); } } } @@ -4499,16 +4524,16 @@ try_combine (rtx_insn *i3, rtx_insn *i2, if (newi2pat) { if (MAY_HAVE_DEBUG_BIND_INSNS && i2scratch) - propagate_for_debug (i2, last_combined_insn, i2dest, i2src, - this_basic_block); + combine_propagate_for_debug (i2, last_combined_insn, i2dest, i2src, + this_basic_block); INSN_CODE (i2) = i2_code_number; PATTERN (i2) = newi2pat; } else { if (MAY_HAVE_DEBUG_BIND_INSNS && i2src) - propagate_for_debug (i2, last_combined_insn, i2dest, i2src, - this_basic_block); + combine_propagate_for_debug (i2, last_combined_insn, i2dest, i2src, + this_basic_block); SET_INSN_DELETED (i2); } @@ -4517,8 +4542,8 @@ try_combine (rtx_insn *i3, rtx_insn *i2, LOG_LINKS (i1) = NULL; REG_NOTES (i1) = 0; if (MAY_HAVE_DEBUG_BIND_INSNS) - propagate_for_debug (i1, last_combined_insn, i1dest, i1src, - this_basic_block); + combine_propagate_for_debug (i1, last_combined_insn, i1dest, i1src, + this_basic_block); SET_INSN_DELETED (i1); } @@ -4527,8 +4552,8 @@ try_combine (rtx_insn *i3, rtx_insn *i2, LOG_LINKS (i0) = NULL; REG_NOTES (i0) = 0; if (MAY_HAVE_DEBUG_BIND_INSNS) - propagate_for_debug (i0, last_combined_insn, i0dest, i0src, - this_basic_block); + combine_propagate_for_debug (i0, last_combined_insn, i0dest, i0src, + this_basic_block); SET_INSN_DELETED (i0); } --- gcc/testsuite/gcc.dg/pr99830.c.jj 2021-04-08 16:39:44.243774333 +0200 +++ gcc/testsuite/gcc.dg/pr99830.c 2021-04-08 16:28:40.463175738 +0200 @@ -0,0 +1,10 @@ +/* PR debug/99830 */ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O2 -fno-expensive-optimizations -fno-split-wide-types -g" } */ + +int foo (long a, __int128 b, short c, int d, unsigned e, __int128 f) +{ + __builtin_memmove (2 + (char *) &f, foo, 1); + c >>= (char) f; + return c; +}