From patchwork Sat Nov 21 20:52:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11923641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CC04C63777 for ; Sat, 21 Nov 2020 20:53:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F5D620738 for ; Sat, 21 Nov 2020 20:53:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="u0lHCGdI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728503AbgKUUxP (ORCPT ); Sat, 21 Nov 2020 15:53:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728402AbgKUUxP (ORCPT ); Sat, 21 Nov 2020 15:53:15 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9FC8C0613CF for ; Sat, 21 Nov 2020 12:53:14 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id p8so14506685wrx.5 for ; Sat, 21 Nov 2020 12:53:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6qwa4aVnaJ+MYhsDmxRUQRMbkKnrRNCkuUNPaMQ349g=; b=u0lHCGdIJT0IH4Aw7K/Vu2EO2hhYu8jmH1EekiofCdOfDTcOor9bkQyz+VobXSawPt LqPMD8Pz4erczZRPNCE0AjIvJ6Y6LOX4c+deti22x3vAQ8eNzEaRdz4V8pt5SZEBxRUj RaR7r77BWEhP91+H7aS0fMDBXML4itxX85Sw66tFNHjgNe9wWwQWtEBISHNn8t04Pkpi dUSExhZI7eoGRsP73RE2fwL5Z3B9Ojgyb48KnagQFOQuv1tn6LFNzcKNxriH7pz1bKpq xkvV+B4qNlb6fN7lwPFVDx5vOjatb59W12qcg/SPF8flMK2oxPFWQhUgrbw3JAuFd6te Ol+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6qwa4aVnaJ+MYhsDmxRUQRMbkKnrRNCkuUNPaMQ349g=; b=ne5Nt44qzGojW6zhpc1nGjkx+rM7HhTKMmvvwkNG0hg1xGvCZ6X/tT5a4uR/02mU2l fGUePuX+Nr0dwtlLTAQN8BWBnXDsmN6Aa8l6lUUw7/e4N1C7pNRcgloIrgromg94TLER vfsiQyAMyHQ89d1/Fm38GR6Jf3YXBs1mORVS7YXL042a7rkOp3DNksQgxumSX0KPrpgy PjPY47xU6jB1ir1bSFS9NASuuIriPg33emdNIKRGx8nAk5X55yO4riAOKSemzKCGgXpB ILrYLpWQxLrPwaP+dzU7uLwhtvQWSuSsK39wdMVSiYRiEIzoWyQIAddekFJeoks3AZa/ EkOA== X-Gm-Message-State: AOAM532Hk+hAoohJW5ENcn6t1NT0/kqfBIau7Sl5C3F+mFlWSDcyDTTK 09Z2lyzuEeeVX06ML1eFkwzwS8CZniU= X-Google-Smtp-Source: ABdhPJwFjmUC+mllhyfP3a+wrsTpdFD7NQqopdkVZjorhfdWcoqm44umbav3LMy/xebVHubnCk6+3g== X-Received: by 2002:a5d:5342:: with SMTP id t2mr21946201wrv.243.1605991993237; Sat, 21 Nov 2020 12:53:13 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:dcb6:7e9c:ccbf:c450]) by smtp.gmail.com with ESMTPSA id p4sm9369815wmc.46.2020.11.21.12.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 12:53:12 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 1/4] add testcases for COMPUTEDGOTO simplification Date: Sat, 21 Nov 2020 21:52:57 +0100 Message-Id: <20201121205300.94642-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201121205300.94642-1-luc.vanoostenryck@gmail.com> References: <20201121205300.94642-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Signed-off-by: Luc Van Oostenryck --- validation/optim/cgoto01.c | 25 +++++++++++++++++++++++++ validation/optim/cgoto02.c | 18 ++++++++++++++++++ validation/optim/cse-label.c | 14 ++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 validation/optim/cgoto01.c create mode 100644 validation/optim/cgoto02.c create mode 100644 validation/optim/cse-label.c diff --git a/validation/optim/cgoto01.c b/validation/optim/cgoto01.c new file mode 100644 index 000000000000..350c6cd99f08 --- /dev/null +++ b/validation/optim/cgoto01.c @@ -0,0 +1,25 @@ +void abort(void) __attribute__((__noreturn__)); + +int foo(int a) +{ + void *label; + + if (a == a) + label = &&L1; + else + label = &&L2; + goto *label; +L1: return 0; +L2: abort(); +} + +/* + * check-name: cgoto01 + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-excludes: set\\. + * check-output-excludes: jmp + * check-output-excludes: call + */ diff --git a/validation/optim/cgoto02.c b/validation/optim/cgoto02.c new file mode 100644 index 000000000000..5869d5b4a24d --- /dev/null +++ b/validation/optim/cgoto02.c @@ -0,0 +1,18 @@ +int foo(int a) +{ + void *label = a ? &&l1 : &&l2; + goto *label; +l1: + return a; +l2: + return 0; +} + +/* + * check-name: cgoto02 + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-returns: %arg1 + */ diff --git a/validation/optim/cse-label.c b/validation/optim/cse-label.c new file mode 100644 index 000000000000..e42968204615 --- /dev/null +++ b/validation/optim/cse-label.c @@ -0,0 +1,14 @@ +int foo(void) +{ +label: + return &&label == &&label; +} + +/* + * check-name: cse-label + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-returns: 1 + */ From patchwork Sat Nov 21 20:52:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11923645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA97BC5519F for ; Sat, 21 Nov 2020 20:53:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5948A20727 for ; Sat, 21 Nov 2020 20:53:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LBa8Lx+A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728507AbgKUUxQ (ORCPT ); Sat, 21 Nov 2020 15:53:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728402AbgKUUxQ (ORCPT ); Sat, 21 Nov 2020 15:53:16 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7AE1C0613CF for ; Sat, 21 Nov 2020 12:53:15 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id a3so13651264wmb.5 for ; Sat, 21 Nov 2020 12:53:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9sWbOXCAlsRJ29Zj/2fPeyjIAWIaMpzqTdBLgnXDtso=; b=LBa8Lx+AnerB/GlwHniocK5TdSCdCS4NguP5sYcPEz+j8/WSPd+ALagfRNKECzDGdD q/ha2GjC/tvKVyfw23JGjA7+3jK+cduKaYn8ThZrLBEaADn2nb6mQ2BgnVXlQoLq+4x2 v5RoOlDvuppydcmlddgsEgP8ve5d0Oc6umAT+iKfsCA2bvzrhNPjXOsji3CqqrsiaE4a tmSwlqhMkrSz4ANjcjhzxUg1HlwHJBwRpIolANylqd58H6E6tQGM5hRQDDtYmwfR3OOi lypDSzETJOcpMvs7inTtODiHSeBlhSLZeta5KIUwHwjyfN+uf7CRVWdlguW+aJWBQRMV DtWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9sWbOXCAlsRJ29Zj/2fPeyjIAWIaMpzqTdBLgnXDtso=; b=S170gKpyroqBLDrL1T09sKib7cTR55K8HQMEHGL6bNNBJVWWNjId7Pms54+PkTq85K JvqnFtTSW6xUOeORolPqmbEmJsbv5Ww010eVLqIJUxy7BjeGmGW9pV+apAETSxsTBYDt KnyVOlCiuLcUA0mwVFNqT4++bRL9t/4RjidKKh1rcngX5GDRMnZc6zqnqB3KwPHN8+58 toED6woWPdTp/iPp32VBXExxjeTzZS4KHiGQ+bSGCO+4buEBAOI9Ddv6VHDydMFojmUD DJ7B2T+QSDcQbknZxOTnBv5I4zrLBk8iYGF8jUvNjYPwiusvSAGmBjt8vACDa0B3Blds AbYw== X-Gm-Message-State: AOAM532RKHjVCBJ4cJNKzAO93OccfHmp7ifJKU9/2yrNuf4r7dRp2KQS QcOLQRHhlyvtEchR442UoasWbhVrFLU= X-Google-Smtp-Source: ABdhPJwPc+pgPmTmWoMHHDIR+9RctSVLZ8ThNlNwpTMwFDePj9NlsaapVCqQL/ctEFeiE9O1U7D0+A== X-Received: by 2002:a1c:2b03:: with SMTP id r3mr15466695wmr.184.1605991994271; Sat, 21 Nov 2020 12:53:14 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:dcb6:7e9c:ccbf:c450]) by smtp.gmail.com with ESMTPSA id p4sm9369815wmc.46.2020.11.21.12.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 12:53:13 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 2/4] simplify OP_COMPUTEDGOTO with unique and known target Date: Sat, 21 Nov 2020 21:52:58 +0100 Message-Id: <20201121205300.94642-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201121205300.94642-1-luc.vanoostenryck@gmail.com> References: <20201121205300.94642-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org If the OP_COMPUTEDGOTO's source pseudo is defined by a single OP_SETVAL/EXPR_LABEL, then the corresponding basic block is the only possible destination and the computed goto can then be simplified into a simple branch. So, convert such computed goto into a simple OP_BR which may then participate in other flow simplifications. Signed-off-by: Luc Van Oostenryck --- simplify.c | 30 ++++++++++++++++++++++++++++++ validation/optim/cgoto01.c | 1 - 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/simplify.c b/simplify.c index e58fb6cf3941..132d408f59f1 100644 --- a/simplify.c +++ b/simplify.c @@ -2112,6 +2112,34 @@ found: return REPEAT_CSE; } +static int simplify_cgoto(struct instruction *insn) +{ + struct basic_block *target, *bb = insn->bb; + struct instruction *def; + struct multijmp *jmp; + + switch (DEF_OPCODE(def, insn->src)) { + case OP_SETVAL: + if (def->val->type != EXPR_LABEL) + break; + target = def->val->symbol->bb_target; + if (!target->ep) + return 0; + FOR_EACH_PTR(insn->multijmp_list, jmp) { + if (jmp->target == target) + continue; + remove_bb_from_list(&jmp->target->parents, bb, 1); + remove_bb_from_list(&bb->children, jmp->target, 1); + MARK_CURRENT_DELETED(jmp); + } END_FOR_EACH_PTR(jmp); + kill_use(&insn->src); + insn->opcode = OP_BR; + insn->bb_true = target; + return REPEAT_CSE|REPEAT_CFG_CLEANUP; + } + return 0; +} + int simplify_instruction(struct instruction *insn) { unsigned flags; @@ -2190,6 +2218,8 @@ int simplify_instruction(struct instruction *insn) return simplify_branch(insn); case OP_SWITCH: return simplify_switch(insn); + case OP_COMPUTEDGOTO: + return simplify_cgoto(insn); case OP_RANGE: return simplify_range(insn); case OP_FADD: diff --git a/validation/optim/cgoto01.c b/validation/optim/cgoto01.c index 350c6cd99f08..94b2c2c429db 100644 --- a/validation/optim/cgoto01.c +++ b/validation/optim/cgoto01.c @@ -16,7 +16,6 @@ L2: abort(); /* * check-name: cgoto01 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-excludes: set\\. From patchwork Sat Nov 21 20:52:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11923643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0758C63798 for ; Sat, 21 Nov 2020 20:53:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 93B7F20771 for ; Sat, 21 Nov 2020 20:53:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f6vM3apJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728511AbgKUUxR (ORCPT ); Sat, 21 Nov 2020 15:53:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728402AbgKUUxR (ORCPT ); Sat, 21 Nov 2020 15:53:17 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0640C0613CF for ; Sat, 21 Nov 2020 12:53:16 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id p22so14245159wmg.3 for ; Sat, 21 Nov 2020 12:53:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T1X2PIa+ZvMWoHd+u1U+/PKDh8K41btoB+fUbSkfK0k=; b=f6vM3apJdOfkTG6lCq25STb7uuEcxJ6AJI/G++eWcfs5z5IKt+cyEweOVLM7h0LS0v y0OIy8yKKKy7CK1SMCYSQHZxhbETjrtsgzgFh1yDBQU5kjznGiCKrjg0A1ElcVRh9Viz n5pNUtZ+JJsY31JK/mM2lbEDMXDfaUz3pU/xeUEnV9SlEMbyoh9gtTjIBm9skOb+QZ7C IdQSDh2YPSCVPXX7/TG3iApT/gUp5HAjwkFFo+O7jEUfZJDNUtiWs/zycqN62HDTm7c7 1yjuBOOtYbovKHeK+BY/8oHukNt3X8rzmHXf8NyIV3aAAA4Uu+0VUS6oq/PrlLPxibRm cwKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T1X2PIa+ZvMWoHd+u1U+/PKDh8K41btoB+fUbSkfK0k=; b=D26s8eHMteThb0NZo8mHxSKmwkMgX7uOgxpEt5XQDTfUtfuPoY9T7dAaHRhukLj/EP OZ9KqWwkU9eTcgJ+EEHNTyEMcVIbwBGtbDDOsdjJxjBDXkFMYUrKHVPHE2yBI6dSzwEE z+y5DPg3u2m4b/+cGEo08VhO4TDzIk3sdvjxhxWt1yTbrQTCvfM+HediwU5tZBheZuy3 OMY6rJYHbrpDSMqc3AS4yTXCUgNyEac+8Viilz3/NevaLH5j6b3Nugdu9HhCAPT5KcSq +1x2Gsy3yMI5BkepEpe+nILymlw+Y2IEFIROcyXkiNUwm0fGhkcQ+Qn+Hi6mzAtWgSfT Oa0g== X-Gm-Message-State: AOAM530c8cpOBXOlvtSE49EFxgyhJlqVGSWUAa84mgOHMC50caGhEWDv KPK8EvVB9Lc9LnsrDv/d3X2fF1HYcf4= X-Google-Smtp-Source: ABdhPJxShR91r+tU1gGYdwY4UVXRdik7xjjvzVFKflUJBYpM6v5hf8RN/0kfrX9yjZwy1FdTfmZihA== X-Received: by 2002:a7b:ca43:: with SMTP id m3mr16418947wml.25.1605991995300; Sat, 21 Nov 2020 12:53:15 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:dcb6:7e9c:ccbf:c450]) by smtp.gmail.com with ESMTPSA id p4sm9369815wmc.46.2020.11.21.12.53.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 12:53:14 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 3/4] simplify CGOTO(SEL(x, L1, L2)) into CBR x, L1, L2 Date: Sat, 21 Nov 2020 21:52:59 +0100 Message-Id: <20201121205300.94642-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201121205300.94642-1-luc.vanoostenryck@gmail.com> References: <20201121205300.94642-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org A computed goto having as operand a select of 2 statically known addresses (OP_SETVAL/EXPR_LABEL) is equivalent to a simple conditional branch. Simplify such computed goto into the corresponding OP_CBR Signed-off-by: Luc Van Oostenryck --- simplify.c | 22 ++++++++++++++++++++++ validation/optim/cgoto02.c | 1 - 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/simplify.c b/simplify.c index 132d408f59f1..24ecf074206e 100644 --- a/simplify.c +++ b/simplify.c @@ -2112,13 +2112,35 @@ found: return REPEAT_CSE; } +static struct basic_block *is_label(pseudo_t pseudo) +{ + struct expression *expr; + struct instruction *def; + + if (DEF_OPCODE(def, pseudo) != OP_SETVAL) + return NULL; + expr = def->val; + if (expr->type != EXPR_LABEL) + return NULL; + return expr->symbol->bb_target; +} + static int simplify_cgoto(struct instruction *insn) { struct basic_block *target, *bb = insn->bb; + struct basic_block *bbt, *bbf; struct instruction *def; struct multijmp *jmp; switch (DEF_OPCODE(def, insn->src)) { + case OP_SEL: // CGOTO(SEL(x, L1, L2)) --> CBR x, L1, L2 + if ((bbt = is_label(def->src2)) && (bbf = is_label(def->src3))) { + insn->opcode = OP_CBR; + insn->bb_true = bbt; + insn->bb_false = bbf; + return replace_pseudo(insn, &insn->src1, def->cond); + } + break; case OP_SETVAL: if (def->val->type != EXPR_LABEL) break; diff --git a/validation/optim/cgoto02.c b/validation/optim/cgoto02.c index 5869d5b4a24d..932c3164e5ee 100644 --- a/validation/optim/cgoto02.c +++ b/validation/optim/cgoto02.c @@ -11,7 +11,6 @@ l2: /* * check-name: cgoto02 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: %arg1 From patchwork Sat Nov 21 20:53:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11923647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F80EC6379D for ; Sat, 21 Nov 2020 20:53:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4FDD20727 for ; Sat, 21 Nov 2020 20:53:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DsGseyQ6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728514AbgKUUxT (ORCPT ); Sat, 21 Nov 2020 15:53:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728402AbgKUUxT (ORCPT ); Sat, 21 Nov 2020 15:53:19 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7A36C0613CF for ; Sat, 21 Nov 2020 12:53:17 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id s13so13652607wmh.4 for ; Sat, 21 Nov 2020 12:53:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0OoHEIvq++HatUS799FbIS8kFE9qdJKTvlS1kpCyc0M=; b=DsGseyQ6bb1IYtx81Vt9Z0y1LEwYZ4VqycYNd37d8YG1XHGr7Xmod0shS0bKZQ2U5Z Eg6DeFsVZPZEnxg/t1doWhTp5HZXS+7Ju8vcecHF2LeCyI891/vZWHeZ3dC2xBP9Bshs NnL0/VSKCrWCNyCm0YoVqk80+KkodWJNFsciCSV7n/TeOLWHXawrS/553WbK8CjJaZ/d ckqfgGITe/lkL279V84eU0Lhdzz/iOt+/fi1Fr2cewHuOo7jvVik9BE1voTamxIDL7VY QQe2yzcjVP3o4B8luQG4sNb1cONSsXO8eLlwSQO20XREXLJJvaVmuWVA4bQGvXeanxjL ++gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0OoHEIvq++HatUS799FbIS8kFE9qdJKTvlS1kpCyc0M=; b=UXM0bcSV/HuqKgOoVIYhfRSOj3bUjAlqny8ZvV7eHi3FF3CJ1bxSC1T2GMqV5H+BUe BHLXtMGVe3pI3JKu2gtNyAoOqmPDjYFC495PKul7bQGPV2RbiIT0blYPbnC+KNh+e8nF T3x+WYpjMpnR3NSzbrGYivhdxSDwOCMQo6JHIUjuH1/aA5YA4x0/LkQ71VpTYXufcQVK KNibt7E4AKR0hhr2yeMOY0451eo4OnFBdNwmBAzQHGQLptgUMge8EQZ3PjojwC8bfxPM F+DrLcH+2GYXeAco9HfRtqG2ovE69f1jrvY5f8jt8GPrrpZSYR8vM3uxwkka2qlBUm2b Ti6w== X-Gm-Message-State: AOAM530vnwHnO4jMPJTxkMWGm1dSXbJs4XeVR89uNGBmqhrarvHlcX+o cWxFbW319B8IGWjcy9rDYAPrulGWINU= X-Google-Smtp-Source: ABdhPJwfuHB3fSndgbYD0jAWPrrcoN2jwg6KTrN+0Jhn3Ud7bHpfg1YsbtfH9wSgowRnPyo2y7R+Vw== X-Received: by 2002:a05:600c:22d5:: with SMTP id 21mr14797380wmg.33.1605991996132; Sat, 21 Nov 2020 12:53:16 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:dcb6:7e9c:ccbf:c450]) by smtp.gmail.com with ESMTPSA id p4sm9369815wmc.46.2020.11.21.12.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 12:53:15 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 4/4] add a new instruction for label-as-value Date: Sat, 21 Nov 2020 21:53:00 +0100 Message-Id: <20201121205300.94642-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201121205300.94642-1-luc.vanoostenryck@gmail.com> References: <20201121205300.94642-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Convert OP_SETVAL of a label into a new instruction: OP_LABEL. There is 2 reasons to do this: *) there is slightly less checking to be done in later phases (since OP_SETVAL can be for labels but also strings) *) OP_SETVAL is CSEd but this is largely useless because this instruction is hashed on the expression's address and these are (most) often not shared. With a separate instruction for label expressions, their CSE is now OK because the hashing is done on the BB. Signed-off-by: Luc Van Oostenryck --- cse.c | 9 +++++++++ example.c | 8 +++++--- linearize.c | 6 ++++++ liveness.c | 1 + opcode.def | 1 + simplify.c | 36 ++++++++++++++++++++++++------------ sparse-llvm.c | 11 +++++++++++ validation/optim/cse-label.c | 1 - 8 files changed, 57 insertions(+), 16 deletions(-) diff --git a/cse.c b/cse.c index 22dfd4ba5d19..1e58a973ecf6 100644 --- a/cse.c +++ b/cse.c @@ -80,6 +80,10 @@ void cse_collect(struct instruction *insn) hash += hashval(insn->src1); break; + case OP_LABEL: + hash += hashval(insn->bb_true); + break; + case OP_SETVAL: hash += hashval(insn->val); break; @@ -215,6 +219,11 @@ static int insn_compare(const void *_i1, const void *_i2) return i1->src1 < i2->src1 ? -1 : 1; break; + case OP_LABEL: + if (i1->bb_true != i2->bb_true) + return i1->bb_true < i2->bb_true ? -1 : 1; + break; + case OP_SETVAL: if (i1->val != i2->val) return i1->val < i2->val ? -1 : 1; diff --git a/example.c b/example.c index 8a2b1ab46fe8..0c2ddf50c015 100644 --- a/example.c +++ b/example.c @@ -66,6 +66,7 @@ static const char *opcodes[] = { /* Memory */ [OP_LOAD] = "load", [OP_STORE] = "store", + [OP_LABEL] = "label", [OP_SETVAL] = "set", /* Other */ @@ -619,7 +620,7 @@ static struct hardreg *fill_reg(struct bb_state *state, struct hardreg *hardreg, case PSEUDO_ARG: case PSEUDO_REG: def = pseudo->def; - if (def && def->opcode == OP_SETVAL) { + if (def && (def->opcode == OP_SETVAL || def->opcode == OP_LABEL)) { output_insn(state, "movl $<%s>,%s", show_pseudo(def->target), hardreg->name); break; } @@ -1375,10 +1376,11 @@ static void generate_one_insn(struct instruction *insn, struct bb_state *state) } /* - * OP_SETVAL likewise doesn't actually generate any + * OP_LABEL & OP_SETVAL likewise doesn't actually generate any * code. On use, the "def" of the pseudo will be * looked up. */ + case OP_LABEL: case OP_SETVAL: break; @@ -1531,7 +1533,7 @@ static void fill_output(struct bb_state *state, pseudo_t pseudo, struct storage return; case PSEUDO_REG: def = pseudo->def; - if (def && def->opcode == OP_SETVAL) { + if (def && (def->opcode == OP_SETVAL || def->opcode == OP_LABEL)) { write_val_to_storage(state, pseudo, out); return; } diff --git a/linearize.c b/linearize.c index ab91113d00eb..4391f09cb0da 100644 --- a/linearize.c +++ b/linearize.c @@ -249,6 +249,7 @@ static const char *opcodes[] = { /* Memory */ [OP_LOAD] = "load", [OP_STORE] = "store", + [OP_LABEL] = "label", [OP_SETVAL] = "set", [OP_SETFVAL] = "setfval", [OP_SYMADDR] = "symaddr", @@ -345,6 +346,11 @@ const char *show_instruction(struct instruction *insn) buf += sprintf(buf, "%s", show_label(insn->bb_true)); break; + case OP_LABEL: + buf += sprintf(buf, "%s <- ", show_pseudo(insn->target)); + buf += sprintf(buf, "%s", show_label(insn->bb_true)); + break; + case OP_SETVAL: { struct expression *expr = insn->val; buf += sprintf(buf, "%s <- ", show_pseudo(insn->target)); diff --git a/liveness.c b/liveness.c index 33cd04831fc0..30a9a5b6b169 100644 --- a/liveness.c +++ b/liveness.c @@ -92,6 +92,7 @@ static void track_instruction_usage(struct basic_block *bb, struct instruction * USES(src); USES(target); break; + case OP_LABEL: case OP_SETVAL: case OP_SETFVAL: DEFINES(target); diff --git a/opcode.def b/opcode.def index 2627abd4d894..ba757dae3c5a 100644 --- a/opcode.def +++ b/opcode.def @@ -98,6 +98,7 @@ OPCODE(STORE, BADOP, BADOP, BADOP, BADOP, 1, OPF_NONE) /* Other */ OPCODE(PHISOURCE, BADOP, BADOP, BADOP, BADOP, 1, OPF_TARGET) OPCODE(PHI, BADOP, BADOP, BADOP, BADOP, 0, OPF_TARGET) +OPCODE(LABEL, BADOP, BADOP, BADOP, BADOP, 0, OPF_TARGET) OPCODE(SETVAL, BADOP, BADOP, BADOP, BADOP, 0, OPF_TARGET) OPCODE(SETFVAL, BADOP, BADOP, BADOP, BADOP, 0, OPF_TARGET) OPCODE(CALL, BADOP, BADOP, BADOP, BADOP, 1, OPF_TARGET) diff --git a/simplify.c b/simplify.c index 24ecf074206e..e3344434f6d1 100644 --- a/simplify.c +++ b/simplify.c @@ -325,7 +325,6 @@ int kill_insn(struct instruction *insn, int force) /* fall through */ case OP_UNOP ... OP_UNOP_END: - case OP_SETVAL: case OP_SLICE: kill_use(&insn->src1); break; @@ -379,6 +378,8 @@ int kill_insn(struct instruction *insn, int force) return 0; case OP_BR: + case OP_LABEL: + case OP_SETVAL: case OP_SETFVAL: default: break; @@ -2114,15 +2115,11 @@ found: static struct basic_block *is_label(pseudo_t pseudo) { - struct expression *expr; struct instruction *def; - if (DEF_OPCODE(def, pseudo) != OP_SETVAL) + if (DEF_OPCODE(def, pseudo) != OP_LABEL) return NULL; - expr = def->val; - if (expr->type != EXPR_LABEL) - return NULL; - return expr->symbol->bb_target; + return def->bb_true; } static int simplify_cgoto(struct instruction *insn) @@ -2141,10 +2138,8 @@ static int simplify_cgoto(struct instruction *insn) return replace_pseudo(insn, &insn->src1, def->cond); } break; - case OP_SETVAL: - if (def->val->type != EXPR_LABEL) - break; - target = def->val->symbol->bb_target; + case OP_LABEL: + target = def->bb_true; if (!target->ep) return 0; FOR_EACH_PTR(insn->multijmp_list, jmp) { @@ -2162,6 +2157,21 @@ static int simplify_cgoto(struct instruction *insn) return 0; } +static int simplify_setval(struct instruction *insn) +{ + struct expression *val = insn->val; + + switch (val->type) { + case EXPR_LABEL: + insn->opcode = OP_LABEL; + insn->bb_true = val->symbol->bb_target; + return REPEAT_CSE; + default: + break; + } + return 0; +} + int simplify_instruction(struct instruction *insn) { unsigned flags; @@ -2227,9 +2237,11 @@ int simplify_instruction(struct instruction *insn) return replace_with_pseudo(insn, insn->src); case OP_SLICE: break; - case OP_SETVAL: + case OP_LABEL: case OP_SETFVAL: break; + case OP_SETVAL: + return simplify_setval(insn); case OP_PHI: return clean_up_phi(insn); case OP_PHISOURCE: diff --git a/sparse-llvm.c b/sparse-llvm.c index c984dc877a61..972ddfeea54f 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -935,6 +935,14 @@ static void output_op_fpcast(struct function *fn, struct instruction *insn) insn->target->priv = target; } +static void output_op_label(struct function *fn, struct instruction *insn) +{ + LLVMValueRef target; + + target = LLVMBlockAddress(fn->fn, insn->bb_true->priv); + insn->target->priv = target; +} + static void output_op_setval(struct function *fn, struct instruction *insn) { struct expression *val = insn->val; @@ -975,6 +983,9 @@ static void output_insn(struct function *fn, struct instruction *insn) case OP_SYMADDR: assert(0); break; + case OP_LABEL: + output_op_label(fn, insn); + break; case OP_SETVAL: output_op_setval(fn, insn); break; diff --git a/validation/optim/cse-label.c b/validation/optim/cse-label.c index e42968204615..c3b552d3dec9 100644 --- a/validation/optim/cse-label.c +++ b/validation/optim/cse-label.c @@ -7,7 +7,6 @@ label: /* * check-name: cse-label * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1