From patchwork Fri Apr 8 14:54:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 608049 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3qhMtm5j2Mz9t5h for ; Sat, 9 Apr 2016 00:54:39 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=m2n5kJEO; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=HDKvAtCgJajNvkeeG4TmKhl6l1mfU eKOoTxmUO4ZpvAtboavvU3rfTzk7XT/WnCCF7gjCHf2g14y6GI+C9QcdGq0msseT qaThHyJX7CnU5wuJ2maIKiOwzegI2xwdFhpb5qTZ1bIdP5dEtd73mGu7zGMpaJZC 4/07damCZjLWWY= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=7Q0pQxop1QfWb50fmNUwCnAOPp0=; b=m2n 5kJEO8Fl/mO0ulfNMeAl35nYuM/FQ99Pte10oOSvphUwz5ab432hJ+8249j4Dq+3 CIq2tCERsmqnmf+sfw3kzpgEF0psL6kIM+aoXga4MaJVyyvCV0uRlhaqz/uDPNtb a2O/ysmINMErl+yHjeDvQTrPnd/XbM6BazjwBl4E= Received: (qmail 47824 invoked by alias); 8 Apr 2016 14:54:32 -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 45054 invoked by uid 89); 8 Apr 2016 14:54:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:4258 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 08 Apr 2016 14:54:28 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8755F64D09; Fri, 8 Apr 2016 14:54:27 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-22.phx2.redhat.com [10.3.113.22]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u38EsPLE023551 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 8 Apr 2016 10:54:26 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u38EsNE7013701; Fri, 8 Apr 2016 16:54:24 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u38EsMRn013700; Fri, 8 Apr 2016 16:54:22 +0200 Date: Fri, 8 Apr 2016 16:54:22 +0200 From: Jakub Jelinek To: Richard Biener , Jeff Law , Bernd Schmidt , Alexandre Oliva Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ssa coalescing with inline asm (PR middle-end/70593) Message-ID: <20160408145422.GU19207@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes Hi! xen is miscompiled since Alex' SSA coalescing changes. The problem is that we have there inline asm that sets more than one SSA_NAME, one of them is dead though (has zero uses) and because of the zero uses coalescing doesn't see any conflicts and puts both the SSA_NAMEs in the two GIMPLE_ASM outputs into the same partition. During expansion we then emit the ASM_OPERANDS followed by copying of the two outputs into DECL_RTL of their SSA_NAMEs. But as both are in the same partition, that is the same pseudo. The first one is what we want, and the second one is for the zero uses SSA_NAME, which then overwrites the right one with unrelated value. (insn 9 6 7 2 (parallel [ (set (reg:DI 89 [ c ]) (asm_operands/v:DI ("xorl %k1, %k1 movl $7, %k0") ("=c") 0 [ (reg/v:DI 87 [ ]) (reg/v:DI 87 [ ]) ] [ (asm_input:DI ("0") pr70593.c:9) (asm_input:DI ("1") pr70593.c:9) ] [] pr70593.c:9)) (set (reg:DI 90 [ a ]) (asm_operands/v:DI ("xorl %k1, %k1 movl $7, %k0") ("=a") 1 [ (reg/v:DI 87 [ ]) (reg/v:DI 87 [ ]) ] [ (asm_input:DI ("0") pr70593.c:9) (asm_input:DI ("1") pr70593.c:9) ] [] pr70593.c:9)) (clobber (mem:BLK (scratch) [0 A8])) (clobber (reg:CCFP 18 fpsr)) (clobber (reg:CC 17 flags)) ]) pr70593.c:9 -1 (nil)) (insn 7 9 8 2 (set (reg/v:DI 87 [ ]) (reg:DI 89 [ c ])) pr70593.c:9 -1 (nil)) (insn 8 7 13 2 (set (reg/v:DI 87 [ ]) (reg:DI 90 [ a ])) pr70593.c:9 -1 (nil)) The following patch handles this by making sure we record conflicts between multiple SSA_NAME outputs of the GIMPLE_ASM, even when some of them are not live, by emulating what really happens during expansion - that they are live in the moves after the asm insn. The live_track_process_def calls later on remove it again from the live partitions and thus undo the live_track_process_use effect, so all the patch changes is that during the processing of e.g. the first SSA_NAME output it sees the second (and perhaps third ...) SSA_NAME output as live and adds conflict, similarly when processing the second one if there are more than two, it again sees the third one and adds conflict etc. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-04-08 Jakub Jelinek PR middle-end/70593 * tree-ssa-coalesce.c (build_ssa_conflict_graph): For GIMPLE_ASM with multiple SSA_NAME defs, force the outputs other than first to be live before calling live_track_process_def on each output. * gcc.target/i386/pr70593.c: New test. Jakub --- gcc/tree-ssa-coalesce.c.jj 2016-03-30 16:00:17.000000000 +0200 +++ gcc/tree-ssa-coalesce.c 2016-04-08 12:36:26.409403204 +0200 @@ -905,6 +905,27 @@ build_ssa_conflict_graph (tree_live_info } else if (is_gimple_debug (stmt)) continue; + else if (gimple_code (stmt) == GIMPLE_ASM + && gimple_asm_noutputs (as_a (stmt)) > 1) + { + /* For GIMPLE_ASM as the only statement which can have + more than one SSA_NAME definition, pretend all the + SSA_NAME outputs but the first one are live at this point, + so that conflicts are added in between all those even + when they are actually not really live after the asm, + because expansion might copy those into pseudos after + the asm and if multiple outputs share the same partition, + it might overwrite those that should be live. E.g. + asm volatile (".." : "=r" (a) : "=r" (b) : "0" (a), "1" (a)); + return a; + See PR70593. */ + bool first = true; + FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF) + if (first) + first = false; + else + live_track_process_use (live, var); + } FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF) live_track_process_def (live, var, graph); --- gcc/testsuite/gcc.target/i386/pr70593.c.jj 2016-04-08 12:59:27.352278471 +0200 +++ gcc/testsuite/gcc.target/i386/pr70593.c 2016-04-08 12:48:27.000000000 +0200 @@ -0,0 +1,19 @@ +/* PR middle-end/70593 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +__attribute__((noinline, noclone)) unsigned long +foo (unsigned x) +{ + unsigned long a, c = x; + asm volatile ("xorl\t%k1, %k1\n\tmovl\t$7, %k0" : "=c" (c), "=a" (a) : "0" (c), "1" (c) : "memory"); + return c; +} + +int +main () +{ + if (foo (3) != 7) + __builtin_abort (); + return 0; +}