From patchwork Wed Jan 5 09:39:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1575552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=QF0/JrYb; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JTPc06vBGz9sSs for ; Wed, 5 Jan 2022 20:40:32 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BD25A385843D for ; Wed, 5 Jan 2022 09:40:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD25A385843D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641375630; bh=gGt1Wh0iDkp1WsMiw0bA/wobAE4otBBpm/3oczyAX5A=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=QF0/JrYbSfxM49VpssZdZ59ULzfFmEod39POt75g7thYna+HmIWhsq1xr6TcOKn2f X2CP15xFRHhVfu74b6tFytu9Fk82jVcg/5MjlCXSIJgtuLA6DOFWrhAgJscgcFMPkr prJpY4bfZG+H7Tntlcfbr/0VKq997jJ5OEUjJnkE= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id C62DE385840A for ; Wed, 5 Jan 2022 09:39:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C62DE385840A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-553-I1oBTAEiMyeyaBgdKH9Cyw-1; Wed, 05 Jan 2022 04:39:46 -0500 X-MC-Unique: I1oBTAEiMyeyaBgdKH9Cyw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ED63E1018720; Wed, 5 Jan 2022 09:39:44 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.2.16.169]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C5831059146; Wed, 5 Jan 2022 09:39:44 +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 2059dgVB1798461 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 5 Jan 2022 10:39:42 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 2059dfKJ1798460; Wed, 5 Jan 2022 10:39:41 +0100 Date: Wed, 5 Jan 2022 10:39:41 +0100 To: Richard Biener , Jeff Law Subject: [PATCH] ifcvt: Check for asm goto at the end of then_bb/else_bb in ifcvt [PR103908] Message-ID: <20220105093941.GR2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi! On the following testcase, RTL ifcvt sees then_bb (note 7 6 8 3 [bb 3] NOTE_INSN_BASIC_BLOCK) (insn 8 7 9 3 (set (mem/c:SI (symbol_ref:DI ("b") [flags 0x2] ) [1 b+0 S4 A32]) (const_int 1 [0x1])) "pr103908.c":6:7 81 {*movsi_internal} (nil)) (jump_insn 9 8 13 3 (parallel [ (asm_operands/v ("# insn 1") ("") 0 [] [] [ (label_ref:DI 21) ] pr103908.c:7) (clobber (reg:CC 17 flags)) ]) "pr103908.c":7:5 -1 (expr_list:REG_UNUSED (reg:CC 17 flags) (nil)) -> 21) and similarly else_bb (just with a different asm_operands template). It checks that those basic blocks have a single successor and uses last_active_insn which intentionally skips over JUMP_INSNs, sees both basic blocks contain the same set and merges them (or if the sets are different, attempts some other noce optimization). But we can't assume that the jump, even when it has only a single successor, has no side-effects. The following patch fixes it by checking specially for asm goto, but I wonder if it wouldn't be better to if (JUMP_P (BB_END (test_bb)) && !onlyjump_p (BB_END (test_bb))) return false; and give up on any other hypothetical single successor jumps. The patch below has been bootstrapped/regtested on x86_64-linux and i686-linux, I could bootstrap the !onlyjump_p version too... 2022-01-05 Jakub Jelinek PR rtl-optimization/103908 * ifcvt.c (bb_valid_for_noce_process_p): Punt on bbs ending with asm goto. * gcc.target/i386/pr103908.c: New test. Jakub --- gcc/ifcvt.c.jj 2022-01-03 10:40:42.919140216 +0100 +++ gcc/ifcvt.c 2022-01-04 23:50:40.962529052 +0100 @@ -3064,6 +3064,13 @@ bb_valid_for_noce_process_p (basic_block if (!insn_valid_noce_process_p (last_insn, cc)) return false; + + /* Punt for blocks ending with asm goto, last_active_insn + ignores JUMP_INSNs. */ + if (JUMP_P (BB_END (test_bb)) + && asm_noperands (PATTERN (BB_END (test_bb))) >= 0) + return false; + last_set = single_set (last_insn); rtx x = SET_DEST (last_set); --- gcc/testsuite/gcc.target/i386/pr103908.c.jj 2022-01-04 23:58:02.992341275 +0100 +++ gcc/testsuite/gcc.target/i386/pr103908.c 2022-01-04 23:57:39.399671539 +0100 @@ -0,0 +1,24 @@ +/* PR rtl-optimization/103908 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdisable-tree-cselim -fno-tree-sink" } */ +/* { dg-final { scan-assembler "# insn 1" } } */ +/* { dg-final { scan-assembler "# insn 2" } } */ + +int a, b; + +void +foo (void) +{ + if (a) + { + b = 1; + asm goto ("# insn 1" : : : : lab1); + lab1:; + } + else + { + b = 1; + asm goto ("# insn 2" : : : : lab2); + lab2:; + } +}