From patchwork Fri Nov 27 16:49:43 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: 11936921 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.7 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 0F390C63798 for ; Fri, 27 Nov 2020 16:52:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4C4320795 for ; Fri, 27 Nov 2020 16:52:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fCU/iwDg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732141AbgK0QwB (ORCPT ); Fri, 27 Nov 2020 11:52:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732128AbgK0QwB (ORCPT ); Fri, 27 Nov 2020 11:52:01 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E78E5C0613D1 for ; Fri, 27 Nov 2020 08:52:00 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id r3so6260472wrt.2 for ; Fri, 27 Nov 2020 08:52:00 -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=h/3e9FMMFTb5bWEGpkd883UgRKrevSAneF3JDDaXlA4=; b=fCU/iwDgXNoyVIX0G2qoo/T2Bc5B2RAKFNt4j+1GO6z5+yIaHdGm42gkxb6czRnEm/ +m3GCirASrcmY50MVEuPrMCB8YgM4JRZiFTF2V7CAmOSkUhXT7Wi/f6Q9jjIDYanpSQ8 vI9E2GLYi7zCQaj/rb+3r1BvQP+HZ9W6lotKuyY/xSbCdM5PaFxo4mp6GskRnlqzHbcV JnY4CDCHDYDthMb8P6oAY88NUBDAyD64cz2pJcYKFphEs+W1OIkh6KMy72Z7MRMTIGub +gJYy7ZCfg84rRflDWpxXTk1I25o2B7HBVo+nb+wtcLYPi0iup91c0WJeiybu6Dmf3u+ BDRQ== 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=h/3e9FMMFTb5bWEGpkd883UgRKrevSAneF3JDDaXlA4=; b=ab5s1JiQJo8isa5X+47tny2yzjO84G02wGhuDDjMfi9YbeiNfEZ7n/OX54XE18/RMD sqcixjt9moTZ6SvRWE8brl6PIn8nmZuqaw03+4DkGGHY8BBpRYRqULjTJGGRxhAqCgN7 QBeGWi0dhe7d4UY38YMiySIkK9vmkLDj1BeumL6mkeq10+caH5Tp7hbl1pJwGdhtLlto Yo4W/aRxTgxsuDtcmO3p3R1cyYHxIvF611o8YT0ZqN3RCqJ6xO3eZofYwH8QCSTCmpNo D1W2tgApB9zVFFwbo5xJCI+ntoP9aINApNE672AH/H3WPvSvqJhx4/rZTMQOmht2rROm pMWQ== X-Gm-Message-State: AOAM533piPcSX0iEK1zlixarm4DfPvfDTQm1CzWmac4CMosu0izkTQXe 508fV2UOF3umvePYf7wb2uIJPhFNLU8= X-Google-Smtp-Source: ABdhPJxG72WumXCu2Qpd9EDgeAK6ux+HJjs41jxX7BfJJ9HUquUNBlxEY26pancACLXREBRTZJyjUw== X-Received: by 2002:adf:e502:: with SMTP id j2mr11748516wrm.73.1606495919302; Fri, 27 Nov 2020 08:51:59 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:e9bd:38ae:745f:40ea]) by smtp.gmail.com with ESMTPSA id y2sm15895539wrn.31.2020.11.27.08.51.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 08:51:58 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 1/8] add testscases for some factorization of distributive operations Date: Fri, 27 Nov 2020 17:49:43 +0100 Message-Id: <20201127164950.41517-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> References: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Add some testcases for factorizations of: (x * z) + (y * z) --> (x + y) * z (x | z) & (y | z) --> (x & y) | z (x & z) | (y & z) --> (x | y) & z (x & z) ^ (y & z) --> (x ^ y) & z and (x << s) | (y << s) --> ((x | y) << s) and same for &, ^, LSR and ASR. Signed-off-by: Luc Van Oostenryck --- validation/optim/fact-add-mul.c | 28 ++++++++++++++++++++++++++++ validation/optim/fact-and-ior.c | 28 ++++++++++++++++++++++++++++ validation/optim/fact-and-shift.c | 27 +++++++++++++++++++++++++++ validation/optim/fact-ior-and.c | 28 ++++++++++++++++++++++++++++ validation/optim/fact-ior-shift.c | 27 +++++++++++++++++++++++++++ validation/optim/fact-xor-and.c | 28 ++++++++++++++++++++++++++++ validation/optim/fact-xor-shift.c | 27 +++++++++++++++++++++++++++ 7 files changed, 193 insertions(+) create mode 100644 validation/optim/fact-add-mul.c create mode 100644 validation/optim/fact-and-ior.c create mode 100644 validation/optim/fact-and-shift.c create mode 100644 validation/optim/fact-ior-and.c create mode 100644 validation/optim/fact-ior-shift.c create mode 100644 validation/optim/fact-xor-and.c create mode 100644 validation/optim/fact-xor-shift.c diff --git a/validation/optim/fact-add-mul.c b/validation/optim/fact-add-mul.c new file mode 100644 index 000000000000..48c3d656accc --- /dev/null +++ b/validation/optim/fact-add-mul.c @@ -0,0 +1,28 @@ +int fr_abx(int a, int b, int x) { return ((a * x) + (b * x)) == ((a + b) * x); } +int fl_abx(int a, int b, int x) { return ((x * a) + (x * b)) == ((a + b) * x); } +int fm_abx(int a, int b, int x) { return ((a * x) + (x * b)) == ((a + b) * x); } +int fn_abx(int a, int b, int x) { return ((x * a) + (b * x)) == ((a + b) * x); } + +int fr_bax(int b, int a, int x) { return ((a * x) + (b * x)) == ((b + a) * x); } +int fl_bax(int b, int a, int x) { return ((x * a) + (x * b)) == ((b + a) * x); } +int fm_bax(int b, int a, int x) { return ((a * x) + (x * b)) == ((b + a) * x); } +int fn_bax(int b, int a, int x) { return ((x * a) + (b * x)) == ((b + a) * x); } + +int fr_axb(int a, int x, int b) { return ((a * x) + (b * x)) == ((a + b) * x); } +int fl_axb(int a, int x, int b) { return ((x * a) + (x * b)) == ((a + b) * x); } +int fm_axb(int a, int x, int b) { return ((a * x) + (x * b)) == ((a + b) * x); } +int fn_axb(int a, int x, int b) { return ((x * a) + (b * x)) == ((a + b) * x); } + +int fr_bxa(int b, int x, int a) { return ((b * x) + (a * x)) == ((b + a) * x); } +int fl_bxa(int b, int x, int a) { return ((x * b) + (x * a)) == ((b + a) * x); } +int fm_bxa(int b, int x, int a) { return ((b * x) + (x * a)) == ((b + a) * x); } +int fn_bxa(int b, int x, int a) { return ((x * b) + (a * x)) == ((b + a) * x); } + +/* + * check-name: fact-add-mul + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-returns: 1 + */ diff --git a/validation/optim/fact-and-ior.c b/validation/optim/fact-and-ior.c new file mode 100644 index 000000000000..f2a78eddf41d --- /dev/null +++ b/validation/optim/fact-and-ior.c @@ -0,0 +1,28 @@ +int fr_abx(int a, int b, int x) { return ((a | x) & (b | x)) == ((a & b) | x); } +int fl_abx(int a, int b, int x) { return ((x | a) & (x | b)) == ((a & b) | x); } +int fm_abx(int a, int b, int x) { return ((a | x) & (x | b)) == ((a & b) | x); } +int fn_abx(int a, int b, int x) { return ((x | a) & (b | x)) == ((a & b) | x); } + +int fr_bax(int b, int a, int x) { return ((a | x) & (b | x)) == ((b & a) | x); } +int fl_bax(int b, int a, int x) { return ((x | a) & (x | b)) == ((b & a) | x); } +int fm_bax(int b, int a, int x) { return ((a | x) & (x | b)) == ((b & a) | x); } +int fn_bax(int b, int a, int x) { return ((x | a) & (b | x)) == ((b & a) | x); } + +int fr_axb(int a, int x, int b) { return ((a | x) & (b | x)) == ((a & b) | x); } +int fl_axb(int a, int x, int b) { return ((x | a) & (x | b)) == ((a & b) | x); } +int fm_axb(int a, int x, int b) { return ((a | x) & (x | b)) == ((a & b) | x); } +int fn_axb(int a, int x, int b) { return ((x | a) & (b | x)) == ((a & b) | x); } + +int fr_bxa(int b, int x, int a) { return ((b | x) & (a | x)) == ((b & a) | x); } +int fl_bxa(int b, int x, int a) { return ((x | b) & (x | a)) == ((b & a) | x); } +int fm_bxa(int b, int x, int a) { return ((b | x) & (x | a)) == ((b & a) | x); } +int fn_bxa(int b, int x, int a) { return ((x | b) & (a | x)) == ((b & a) | x); } + +/* + * check-name: fact-and-ior + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-returns: 1 + */ diff --git a/validation/optim/fact-and-shift.c b/validation/optim/fact-and-shift.c new file mode 100644 index 000000000000..401750216b44 --- /dev/null +++ b/validation/optim/fact-and-shift.c @@ -0,0 +1,27 @@ +typedef unsigned int uint; +typedef signed int sint; + + +uint fact_and_shl(uint a, uint b, uint s) +{ + return ((a << s) & (b << s)) == ((a & b) << s); +} + +uint fact_and_lsr(uint a, uint b, uint s) +{ + return ((a >> s) & (b >> s)) == ((a & b) >> s); +} + +sint fact_and_asr(sint a, sint b, sint s) +{ + return ((a >> s) & (b >> s)) == ((a & b) >> s); +} + +/* + * check-name: fact-and-shift + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-returns: 1 + */ diff --git a/validation/optim/fact-ior-and.c b/validation/optim/fact-ior-and.c new file mode 100644 index 000000000000..7af89df1e1f0 --- /dev/null +++ b/validation/optim/fact-ior-and.c @@ -0,0 +1,28 @@ +int fr_abx(int a, int b, int x) { return ((a & x) | (b & x)) == ((a | b) & x); } +int fl_abx(int a, int b, int x) { return ((x & a) | (x & b)) == ((a | b) & x); } +int fm_abx(int a, int b, int x) { return ((a & x) | (x & b)) == ((a | b) & x); } +int fn_abx(int a, int b, int x) { return ((x & a) | (b & x)) == ((a | b) & x); } + +int fr_bax(int b, int a, int x) { return ((a & x) | (b & x)) == ((b | a) & x); } +int fl_bax(int b, int a, int x) { return ((x & a) | (x & b)) == ((b | a) & x); } +int fm_bax(int b, int a, int x) { return ((a & x) | (x & b)) == ((b | a) & x); } +int fn_bax(int b, int a, int x) { return ((x & a) | (b & x)) == ((b | a) & x); } + +int fr_axb(int a, int x, int b) { return ((a & x) | (b & x)) == ((a | b) & x); } +int fl_axb(int a, int x, int b) { return ((x & a) | (x & b)) == ((a | b) & x); } +int fm_axb(int a, int x, int b) { return ((a & x) | (x & b)) == ((a | b) & x); } +int fn_axb(int a, int x, int b) { return ((x & a) | (b & x)) == ((a | b) & x); } + +int fr_bxa(int b, int x, int a) { return ((b & x) | (a & x)) == ((b | a) & x); } +int fl_bxa(int b, int x, int a) { return ((x & b) | (x & a)) == ((b | a) & x); } +int fm_bxa(int b, int x, int a) { return ((b & x) | (x & a)) == ((b | a) & x); } +int fn_bxa(int b, int x, int a) { return ((x & b) | (a & x)) == ((b | a) & x); } + +/* + * check-name: fact-ior-and + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-returns: 1 + */ diff --git a/validation/optim/fact-ior-shift.c b/validation/optim/fact-ior-shift.c new file mode 100644 index 000000000000..07fdf80604dc --- /dev/null +++ b/validation/optim/fact-ior-shift.c @@ -0,0 +1,27 @@ +typedef unsigned int uint; +typedef signed int sint; + + +uint fact_ior_shl(uint a, uint b, uint s) +{ + return ((a << s) | (b << s)) == ((a | b) << s); +} + +uint fact_ior_lsr(uint a, uint b, uint s) +{ + return ((a >> s) | (b >> s)) == ((a | b) >> s); +} + +sint fact_ior_asr(sint a, sint b, sint s) +{ + return ((a >> s) | (b >> s)) == ((a | b) >> s); +} + +/* + * check-name: fact-ior-shift + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-returns: 1 + */ diff --git a/validation/optim/fact-xor-and.c b/validation/optim/fact-xor-and.c new file mode 100644 index 000000000000..905cbf4ab659 --- /dev/null +++ b/validation/optim/fact-xor-and.c @@ -0,0 +1,28 @@ +int fr_abx(int a, int b, int x) { return ((a & x) ^ (b & x)) == ((a ^ b) & x); } +int fl_abx(int a, int b, int x) { return ((x & a) ^ (x & b)) == ((a ^ b) & x); } +int fm_abx(int a, int b, int x) { return ((a & x) ^ (x & b)) == ((a ^ b) & x); } +int fn_abx(int a, int b, int x) { return ((x & a) ^ (b & x)) == ((a ^ b) & x); } + +int fr_bax(int b, int a, int x) { return ((a & x) ^ (b & x)) == ((b ^ a) & x); } +int fl_bax(int b, int a, int x) { return ((x & a) ^ (x & b)) == ((b ^ a) & x); } +int fm_bax(int b, int a, int x) { return ((a & x) ^ (x & b)) == ((b ^ a) & x); } +int fn_bax(int b, int a, int x) { return ((x & a) ^ (b & x)) == ((b ^ a) & x); } + +int fr_axb(int a, int x, int b) { return ((a & x) ^ (b & x)) == ((a ^ b) & x); } +int fl_axb(int a, int x, int b) { return ((x & a) ^ (x & b)) == ((a ^ b) & x); } +int fm_axb(int a, int x, int b) { return ((a & x) ^ (x & b)) == ((a ^ b) & x); } +int fn_axb(int a, int x, int b) { return ((x & a) ^ (b & x)) == ((a ^ b) & x); } + +int fr_bxa(int b, int x, int a) { return ((b & x) ^ (a & x)) == ((b ^ a) & x); } +int fl_bxa(int b, int x, int a) { return ((x & b) ^ (x & a)) == ((b ^ a) & x); } +int fm_bxa(int b, int x, int a) { return ((b & x) ^ (x & a)) == ((b ^ a) & x); } +int fn_bxa(int b, int x, int a) { return ((x & b) ^ (a & x)) == ((b ^ a) & x); } + +/* + * check-name: fact-xor-and + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-returns: 1 + */ diff --git a/validation/optim/fact-xor-shift.c b/validation/optim/fact-xor-shift.c new file mode 100644 index 000000000000..81fcda851400 --- /dev/null +++ b/validation/optim/fact-xor-shift.c @@ -0,0 +1,27 @@ +typedef unsigned int uint; +typedef signed int sint; + + +uint fact_xor_shl(uint a, uint b, uint s) +{ + return ((a << s) ^ (b << s)) == ((a ^ b) << s); +} + +uint fact_xor_lsr(uint a, uint b, uint s) +{ + return ((a >> s) ^ (b >> s)) == ((a ^ b) >> s); +} + +sint fact_xor_asr(sint a, sint b, sint s) +{ + return ((a >> s) ^ (b >> s)) == ((a ^ b) >> s); +} + +/* + * check-name: fact-xor-shift + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-returns: 1 + */ From patchwork Fri Nov 27 16:49:44 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: 11936917 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.7 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 2EE48C6379D for ; Fri, 27 Nov 2020 16:52:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFA9E221EB for ; Fri, 27 Nov 2020 16:52:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f8cLEhKB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731448AbgK0QwC (ORCPT ); Fri, 27 Nov 2020 11:52:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732128AbgK0QwC (ORCPT ); Fri, 27 Nov 2020 11:52:02 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 395A0C0613D1 for ; Fri, 27 Nov 2020 08:52:02 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id s8so6214555wrw.10 for ; Fri, 27 Nov 2020 08:52:02 -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=ScrtSZlA/2DvlbYC7iS+PdZe8g+yHK5UMOTMv5T7unI=; b=f8cLEhKBpOX3vYYy6aJo0v1vBbfPnmoSm9PIjmU9gafpLD/RBmHn0jwrlfzvzV2ADE 13qha09KvHSAZFpALogmZAuUhDHPLc7idnyuORLB5T56wXUJ93t9wcuiX5+gSnXDi/4l A7SVbONUIRU0OCC40nOSwACqz73IbjuxkuG3mWIwxFUinqJp9/RSJgOkfzmOJp0jnfMw rOL/JqbEvWGM0d7ySHokx3C3/c7Q5EtW5pAtwEOEAwJJFDuueNGCa3ZHk6/CUuc1NtrY PbbX8eSEeD7PAQ0JxY5meLnwOo1xuflRHcTWjh1v7os64obdArbFlkmw/0hwbE2/Mpuo HEMQ== 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=ScrtSZlA/2DvlbYC7iS+PdZe8g+yHK5UMOTMv5T7unI=; b=nING2ReSaRUfe8CfAdBHjmnjzXlFWcUaOmBXg9p4xJpuuQNiDh+1RoZHkL4M4r+JoG 1GYhK1yER2/PQy344053Ila+2m6wwcptxqkSF4PJ5YfMEkEEUb34taQWQ67UcQjORWf9 dbAakyxHK7jAmNmjCvdbgn9M1WQb7WaCk29uA2KwBeCpPkp12BaDOyNZM69lYdrmfZvg gLMSGiAgJe9IEIvjpzX5gX2pVJTkNF5OTPtKFdVI2ScsB2RySIvJcvDBARfsYQFHDnSX 5bIvzPXZ+tznR/CCR4Iw6wFng6KQalCv/Onni0JwDQX225XGvgCwlvkNV2lxF+IqQqKG j0ng== X-Gm-Message-State: AOAM531mtdE1NbFziqBXjQxPD9T0oXQYOHfXWgwHTlZtNQCxP9graFHc zMF1mCkDdJ/b58NTX21Y+7Ur9Jk8AGA= X-Google-Smtp-Source: ABdhPJwxxVfC/nskA3wd1UZvjfkN5gBgxXXmXun1exeGQrBH7AaMzoUQjF35pJW5TLTieOneKLvShw== X-Received: by 2002:adf:e490:: with SMTP id i16mr11622076wrm.337.1606495920709; Fri, 27 Nov 2020 08:52:00 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:e9bd:38ae:745f:40ea]) by smtp.gmail.com with ESMTPSA id y2sm15895539wrn.31.2020.11.27.08.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 08:52:00 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 2/8] reassoc: add helper can_move_to() Date: Fri, 27 Nov 2020 17:49:44 +0100 Message-Id: <20201127164950.41517-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> References: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org When transforming IR expressions, it may happen that we want to reuse an instruction and move a pseudo into it but that this pseudo is only defined later. Add a small help to check this: can_move_to(). Signed-off-by: Luc Van Oostenryck --- simplify.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/simplify.c b/simplify.c index de03d315ec33..d16390caed49 100644 --- a/simplify.c +++ b/simplify.c @@ -46,6 +46,7 @@ #include "linearize.h" #include "flow.h" #include "symbol.h" +#include "flowgraph.h" /// // Utilities @@ -1508,6 +1509,42 @@ static inline int simple_pseudo(pseudo_t pseudo) return pseudo->type == PSEUDO_VAL || pseudo->type == PSEUDO_SYM; } +/// +// test if, in the given BB, the ordering of 2 instructions +static bool insn_before(struct basic_block *bb, struct instruction *x, struct instruction *y) +{ + struct instruction *insn; + + FOR_EACH_PTR(bb->insns, insn) { + if (insn == x) + return true; + if (insn == y) + return false; + } END_FOR_EACH_PTR(insn); + return false; +} + +/// +// check if it safe for a pseudo to be used by an instruction +static inline bool can_move_to(pseudo_t src, struct instruction *dst) +{ + struct basic_block *bbs, *bbd; + struct instruction *def; + + if (!one_use(dst->target)) + return false; + if (src->type != PSEUDO_REG) + return true; + + def = src->def; + bbs = def->bb; + bbd = dst->bb; + if (bbs == bbd) + return insn_before(bbs, def, dst); + else + return domtree_dominates(bbs, bbd); +} + static int simplify_associative_binop(struct instruction *insn) { struct instruction *def; From patchwork Fri Nov 27 16:49:45 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: 11936919 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.7 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 5535CC64E7A for ; Fri, 27 Nov 2020 16:52:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D3B320795 for ; Fri, 27 Nov 2020 16:52:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fh/PmCRn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732142AbgK0QwE (ORCPT ); Fri, 27 Nov 2020 11:52:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732128AbgK0QwD (ORCPT ); Fri, 27 Nov 2020 11:52:03 -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 57980C0613D1 for ; Fri, 27 Nov 2020 08:52:03 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id f190so4086053wme.1 for ; Fri, 27 Nov 2020 08:52:03 -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=jAC7LnI9d+ILNNjboWAHlG+DH0oCS0kBDK+Bkm8Eovo=; b=Fh/PmCRnulKfb7+Z4J7L74wEEEhKz20LXnJnhxOKyRUg/k16VyINUWnJBfCJabMKhP TVhKKSrWVPbgz9pVQr+PAZOMslZwkV4m2AXC8XO/+RtiluaX6+QkCS+2/LdT+tklQNbC t5ZswzgedH6dbLiv3u10sPIdWub/hJdBk/4IxwwNGIzVkIMmD1QlcqsmnSkqrnCViLiO sfufcAIwmkh53jyWzGIyA2QygycPZhmBeK81dQKKvIyWkX84HcmaWeMvYVRWBLDhde4P 2XV9oYn2U1u2mLrLEIG5ufE7HpbCWJ7+9Go2ksBgN3K6QEk0myZLIYx9V0Xkm469RPQQ 9Qnw== 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=jAC7LnI9d+ILNNjboWAHlG+DH0oCS0kBDK+Bkm8Eovo=; b=Gc2RpF5SWPF8jeXa5azQBddoG5LHLfURgBtfuZnFwqKd50wZS1D1shyeLgI9dh8KWN ZB7zaVR8Ts/K3wZn2vQsOLUar3HrTueyuzmItwswtKMOTURbLKD/Q+C5N198ysYjSN6r E9E26mrdb8ww8IH249v6CGpJuaJWJUovnlU4pJP6eS0r5sKtU3rtOEvBADQ95nA6ZaY/ CBIK+BdRGhd3YpbP+w63NLn+MwdJSUP/VSxqbfVhD0N/FgZrASKmPRi4J/S/xT5Woc6R sWvhmVR1UYH2xL/NXZcUkAuEyyrrDb95KdFp5OGpuaYOV6KSMSn1nnkZtdL2q0NxqRVP /q0Q== X-Gm-Message-State: AOAM530TyGdJ/PMhvzirmz1kE5/bskV36EuAzJrrHrBo1ebTOpCRNes5 X9TP52FeA86ppDGI/IyZmCt5ZtPxPEg= X-Google-Smtp-Source: ABdhPJx34FGRXAn+p6xmYgK4Pk4Q4kz7vCplDvF63FH/i9LRyUAMOesxYdbWzI0Zn/UCrsV8QnqBeA== X-Received: by 2002:a7b:c1ce:: with SMTP id a14mr10192443wmj.169.1606495921904; Fri, 27 Nov 2020 08:52:01 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:e9bd:38ae:745f:40ea]) by smtp.gmail.com with ESMTPSA id y2sm15895539wrn.31.2020.11.27.08.52.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 08:52:01 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 3/8] add helper make_insn_pair() & swap_insn() Date: Fri, 27 Nov 2020 17:49:45 +0100 Message-Id: <20201127164950.41517-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> References: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Add two helpers to create instruction pair OUT(IN(a, b), c). Signed-off-by: Luc Van Oostenryck --- simplify.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/simplify.c b/simplify.c index d16390caed49..24b3dcb52428 100644 --- a/simplify.c +++ b/simplify.c @@ -506,6 +506,37 @@ static inline int replace_opcode(struct instruction *insn, int op) return REPEAT_CSE; } +/// +// create an instruction pair OUT(IN(a, b), c) +static int replace_insn_pair(struct instruction *out, int op_out, struct instruction *in, int op_in, pseudo_t a, pseudo_t b, pseudo_t c) +{ + pseudo_t old_a = in->src1; + pseudo_t old_b = in->src2; + pseudo_t old_1 = out->src1; + pseudo_t old_2 = out->src2; + + use_pseudo(in, a, &in->src1); + use_pseudo(in, b, &in->src2); + use_pseudo(out, in->target, &out->src1); + use_pseudo(out, c, &out->src2); + + remove_usage(old_a, &in->src1); + remove_usage(old_b, &in->src2); + remove_usage(old_1, &out->src1); + remove_usage(old_2, &out->src2); + + out->opcode = op_out; + in->opcode = op_in; + return REPEAT_CSE; +} + +/// +// create an instruction pair OUT(IN(a, b), c) with swapped opcodes +static inline int swap_insn(struct instruction *out, struct instruction *in, pseudo_t a, pseudo_t b, pseudo_t c) +{ + return replace_insn_pair(out, in->opcode, in, out->opcode, a, b, c); +} + static inline int def_opcode(pseudo_t p) { if (p->type != PSEUDO_REG) From patchwork Fri Nov 27 16:49:46 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: 11936923 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.7 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 731DDC64E7C for ; Fri, 27 Nov 2020 16:52:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 418DF221EB for ; Fri, 27 Nov 2020 16:52:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dz2lDWif" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732001AbgK0QwF (ORCPT ); Fri, 27 Nov 2020 11:52:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732143AbgK0QwF (ORCPT ); Fri, 27 Nov 2020 11:52:05 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36219C0613D1 for ; Fri, 27 Nov 2020 08:52:05 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id e7so6236909wrv.6 for ; Fri, 27 Nov 2020 08:52:05 -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=+vUf0KW2sZz7OITOeA3UReNoLMOlG7LaRjTI4rJr6JA=; b=dz2lDWifrZuBZ2x1EVDYGvyxBP7Ca7MKuQbKjgBJfHq5Yy3qrHZy7wi8DdoBfOK9uP yrIlU4Cok7zem+1jovzHi/JJvW8UQiPOJ4qacKm7TqccUfC+DCWC10sOHA7JbjPHRJD0 VjRUoTrLHVeCj0a8764tXwYjMBTxqSMHm7ArRaldt5ljjlujjUjCYVERltoPIPxuCrU6 2Saw+xSVSreKQ3C9MgQs6hMQ+/eNbXW8p+u+XtIHBCvKnQLXyAHDklwiA9JTb4UFnikK cinVa39zwD3r6D391c6uX1PYNcaD02A6tcyRGdmIBAeFVxAyS2GApqM74i1dGXTWYnEg Dr0g== 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=+vUf0KW2sZz7OITOeA3UReNoLMOlG7LaRjTI4rJr6JA=; b=JGO2Dc9RRnl+fXdLyoOmshAtw173oXrFxaXvxxr25CUXGoH9i781GHOLdZWRJhqUhJ ZJozFfkOxkyK/l3I0WMR5q4MnzpcKzAfhEQU1T0+kxQOV/jfyHip+cU+oHzF5W8aDQ6n mW3G//Eif/3/dMandKITtcJprSkvnua5qvTRhzGx7BZKdYf/G/A+e2rOocH/F7xWze+J Z7WEjZ2IK8qt6nLbTyogMWHWtJhz5Smj+qRCfAyqw/WI2Yl81AXh8R0G8ovDazVZY7Ir sD0hALa8ZuQkkFgoFxvDreHNvchHXAMmrqmVfLbigej+4EgV8DvUvbtw8ccRh0Z6c/Nr JnrA== X-Gm-Message-State: AOAM530Sicgy58KYoW72rz9WIbso4FPKEWlf27EIsLUu/B14lOHsRmP5 1X1m9oGaQF0xWqP31t2foh2ONnz+HZc= X-Google-Smtp-Source: ABdhPJylEZMoMmJFFm2ElRYNZrdTjnko6zwZ2YkwBpuS0CNCNVr543pDphbh5uOU2iF1H8GQSgFT6g== X-Received: by 2002:adf:bc13:: with SMTP id s19mr11890860wrg.397.1606495923713; Fri, 27 Nov 2020 08:52:03 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:e9bd:38ae:745f:40ea]) by smtp.gmail.com with ESMTPSA id y2sm15895539wrn.31.2020.11.27.08.52.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 08:52:03 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 4/8] add helper replace_binop() Date: Fri, 27 Nov 2020 17:49:46 +0100 Message-Id: <20201127164950.41517-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> References: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Add an helper to replace a binop OP(a, b) and taking care to drop the usage of the previous operands. Signed-off-by: Luc Van Oostenryck --- simplify.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/simplify.c b/simplify.c index 24b3dcb52428..046bf02c6d36 100644 --- a/simplify.c +++ b/simplify.c @@ -497,6 +497,23 @@ static inline int replace_binop_value(struct instruction *insn, int op, long lon return REPEAT_CSE; } +/// +// replace binop's opcode and values +// @insn: the instruction to be replaced +// @op: the instruction's new opcode +// @return: REPEAT_CSE +static inline int replace_binop(struct instruction *insn, int op, pseudo_t *pa, pseudo_t a, pseudo_t *pb, pseudo_t b) +{ + pseudo_t olda = *pa; + pseudo_t oldb = *pb; + insn->opcode = op; + use_pseudo(insn, a, pa); + use_pseudo(insn, b, pb); + remove_usage(olda, pa); + remove_usage(oldb, pb); + return REPEAT_CSE; +} + /// // replace the opcode of an instruction // @return: REPEAT_CSE From patchwork Fri Nov 27 16:49:47 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: 11936925 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.7 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 C9973C64E8A for ; Fri, 27 Nov 2020 16:52:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9372720795 for ; Fri, 27 Nov 2020 16:52:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UARenfpJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732020AbgK0QwH (ORCPT ); Fri, 27 Nov 2020 11:52:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732138AbgK0QwG (ORCPT ); Fri, 27 Nov 2020 11:52:06 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 610B2C0613D1 for ; Fri, 27 Nov 2020 08:52:06 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id d3so2562988wmb.4 for ; Fri, 27 Nov 2020 08:52:06 -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=qY3zM7AEcXD4DaouYS0uVroIotDp/b3XoVejh7F4UeI=; b=UARenfpJiZ7T3se/AgX6Vvrx7XpC/Ti3kyzfgKtGh4L++qNWAeSiEFWsizQsjcz8fu XaHZA2vuEMswy6gEUxuimsTRtmXxcg1OfYtnWUbwWCQhgQTIHWY5nP4lx/yVlSllKPly pNsc+W21Jwcv5EFYRAuQjXtAuN4fBYTLv0uv4ulgSRQkhl4uZjAAAWxMBwfx4fwJIwIn TEDcvSVsR5/iqHbFaLZQl5MRmgSzMB4ppzkEPeNBEuNiu/dTf+efoVy06fvYtKF1/8je p95AhS5BhhTC02uyf6K7qXJBgPuSdZtJzJ6jCZxMb19MPUVtpiknBfwAEOFSjNswCRT6 Jriw== 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=qY3zM7AEcXD4DaouYS0uVroIotDp/b3XoVejh7F4UeI=; b=aQzPWP0w9UEdejNMAzuFGLALFoubnHlBjr+LRuQLCLo/xgbmEAaOBlJfAUwCY07ysB ajIpBZmB16q5zDj10Vq2W7coUJOjvqLl2IXXyR18uOXMgRnf0A1O614DfodAXPg9Gcuk +WuA/pwL3uTYnn9NjqNSf8p/3kZu/fiZCIZ3dL3m2xoxqXOBOPn2eNAgOG4YzeYvi8TU RvbXz2/8rWKWirRvmuf8NlRUhE16FTBxvy0TkHbnLcwUiJeWRiH/6MLcs0E9tBi77ZdW lVT+JMDzkc1L4pcWIqRwdpIQ4LBX9O+/xThEVPMv5jbpQGilHdPDcjmLnH/+UVHsNwdg posQ== X-Gm-Message-State: AOAM532PQegg1K7FrrUCRlWIDplWIoGJoe7hAGKOP2i3jlhKVuxTmCJW jqgao0o2MJkQBO5b36cexLZvPgldd50= X-Google-Smtp-Source: ABdhPJzhEDeMOfU3vmdk8xuaXZwU3XJCytOh4Mh5/XiDKYd2szO58OmQyIrjvMOACSOc+Yrt+LryEw== X-Received: by 2002:a1c:e042:: with SMTP id x63mr10278117wmg.68.1606495924794; Fri, 27 Nov 2020 08:52:04 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:e9bd:38ae:745f:40ea]) by smtp.gmail.com with ESMTPSA id y2sm15895539wrn.31.2020.11.27.08.52.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 08:52:04 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 5/8] refactor simplify_add() to avoid code duplication (preparation) Date: Fri, 27 Nov 2020 17:49:47 +0100 Message-Id: <20201127164950.41517-6-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> References: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Do some refactoring in simplify_add() to prepare the next patch which will avoid some code duplication there. Signed-off-by: Luc Van Oostenryck --- simplify.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/simplify.c b/simplify.c index 046bf02c6d36..82ff1242bb0e 100644 --- a/simplify.c +++ b/simplify.c @@ -1628,9 +1628,7 @@ static int simplify_add(struct instruction *insn) switch (DEF_OPCODE(def, src1)) { case OP_NEG: // (-x + y) --> (y - x) - switch_pseudo(insn, &insn->src1, insn, &insn->src2); - insn->opcode = OP_SUB; - return replace_pseudo(insn, &insn->src2, def->src); + return replace_binop(insn, OP_SUB, &insn->src1, src2, &insn->src2, def->src); case OP_SUB: if (def->src2 == src2) // (x - y) + y --> x @@ -1640,8 +1638,7 @@ static int simplify_add(struct instruction *insn) switch (DEF_OPCODE(def, src2)) { case OP_NEG: // (x + -y) --> (x - y) - insn->opcode = OP_SUB; - return replace_pseudo(insn, &insn->src2, def->src); + return replace_binop(insn, OP_SUB, &insn->src1, src1, &insn->src2, def->src); case OP_SUB: if (src1 == def->src2) // x + (y - x) --> y return replace_with_pseudo(insn, def->src1); From patchwork Fri Nov 27 16:49:48 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: 11936927 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.7 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 03547C71155 for ; Fri, 27 Nov 2020 16:52:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6D1E221EB for ; Fri, 27 Nov 2020 16:52:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="u33/o9ym" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731469AbgK0QwI (ORCPT ); Fri, 27 Nov 2020 11:52:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731952AbgK0QwH (ORCPT ); Fri, 27 Nov 2020 11:52:07 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77AFBC0613D1 for ; Fri, 27 Nov 2020 08:52:07 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id k14so6262520wrn.1 for ; Fri, 27 Nov 2020 08:52:07 -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=CAVlJGQ5x4FVveyNh51EYzXwMKdj7wwS/7sFlX2rgrs=; b=u33/o9ymKmRef84D59xQ863YiNkJJ8oPQ0dRqS0tWGIdYKJMx6kpCZ8SBQusXVDx1f mGxQcDWKEYe/bHT7YgBBDaXLKZTvmIOxq9h12kognt5GJ+2peHtR7bNRTzXAzG0R2H4N I/M+kyEM4DUn92BZ7xIUq8xEVUox2hIy/GPc6S5s03AFPTkPSemrVTse4XsNk3Muu2n/ 8GpCGSij2P268dE13LEU2kdo3KIjHw8y6N56vY2NjqXoGz7do6bKDo/2RwfsRUYVs5dJ gyeirLRF3Q3invMj0m/kSiVjxSXLr9diqATqymKEARV527r9AHpZP9DNrIQ8rx3CZAuE Pf8Q== 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=CAVlJGQ5x4FVveyNh51EYzXwMKdj7wwS/7sFlX2rgrs=; b=pGbuWtSYVCAgEcEt4Rl7UWzsAGml7y91waeoVNqBA9NoXOuKqGBI4Bkkj683uGNtUb qPXMt3fSXZw+ppWh8OntL5UIp2a1I/o9G3rkcTvS7dExSZqnzqHAJdPKiamLrAtA+6zc q03vaY+Oy5rnY286fNh+xL1BdssJGUWUc8n/mEVkSv1tsdiDGwNSM8oUok5pMx3ncgZA lSjEyRPqK9y+Y1p7oZu6qmScxplgJEp77qulPXXjbbXo5yE2FvT7ltQSk/sVPjVIRfdQ vrhEII9+0sgb3TETOgz123195jbQRXPliCQW2Yu2dG7L4KAZav590yFdq4UR0fHmj7BB +LGw== X-Gm-Message-State: AOAM533F/uIFKz596jP4OAJza9mPtbzFoqsHlMkx0mm/HmSL6MqRDkHX tgqAJZJn7+g0R8mZgbj9kQ/i23dl3Ow= X-Google-Smtp-Source: ABdhPJyyM/lhmuVqcgc5SptZ4xhQsnINTqqZkonGWtzO/7W1TVyR+9sEIfd6C4l1bE/w+ykFf21LVw== X-Received: by 2002:a5d:6852:: with SMTP id o18mr11758157wrw.336.1606495925996; Fri, 27 Nov 2020 08:52:05 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:e9bd:38ae:745f:40ea]) by smtp.gmail.com with ESMTPSA id y2sm15895539wrn.31.2020.11.27.08.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 08:52:05 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 6/8] refactor simplify_add() to avoid code duplication Date: Fri, 27 Nov 2020 17:49:48 +0100 Message-Id: <20201127164950.41517-7-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> References: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Do some refactoring in simplify_add() to avoid some code duplication there and better handle generic transforms that need to be applied on both operands. Signed-off-by: Luc Van Oostenryck --- simplify.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/simplify.c b/simplify.c index 82ff1242bb0e..5174a903dfd6 100644 --- a/simplify.c +++ b/simplify.c @@ -1620,11 +1620,11 @@ static int simplify_associative_binop(struct instruction *insn) return REPEAT_CSE; } -static int simplify_add(struct instruction *insn) +static int simplify_add_one_side(struct instruction *insn, pseudo_t *p1, pseudo_t *p2) { - pseudo_t src1 = insn->src1; - pseudo_t src2 = insn->src2; struct instruction *def; + pseudo_t src1 = *p1; + pseudo_t src2 = *p2; switch (DEF_OPCODE(def, src1)) { case OP_NEG: // (-x + y) --> (y - x) @@ -1635,19 +1635,15 @@ static int simplify_add(struct instruction *insn) return replace_with_pseudo(insn, def->src1); break; } - - switch (DEF_OPCODE(def, src2)) { - case OP_NEG: // (x + -y) --> (x - y) - return replace_binop(insn, OP_SUB, &insn->src1, src1, &insn->src2, def->src); - case OP_SUB: - if (src1 == def->src2) // x + (y - x) --> y - return replace_with_pseudo(insn, def->src1); - break; - } - return 0; } +static int simplify_add(struct instruction *insn) +{ + return simplify_add_one_side(insn, &insn->src1, &insn->src2) || + simplify_add_one_side(insn, &insn->src2, &insn->src1); +} + static int simplify_sub(struct instruction *insn) { pseudo_t src1 = insn->src1; From patchwork Fri Nov 27 16:49:49 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: 11936931 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.7 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 1F1C6C64E90 for ; Fri, 27 Nov 2020 16:52:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0BEB20795 for ; Fri, 27 Nov 2020 16:52:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kQ82w8cJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731981AbgK0QwJ (ORCPT ); Fri, 27 Nov 2020 11:52:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731615AbgK0QwJ (ORCPT ); Fri, 27 Nov 2020 11:52:09 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20453C0613D1 for ; Fri, 27 Nov 2020 08:52:09 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id p8so6232920wrx.5 for ; Fri, 27 Nov 2020 08:52:09 -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=96qxitp+mIBbRdtkL3noBukHAsCzdBuvulBjmwV/Mdk=; b=kQ82w8cJGzYR4BOO/TUy2nPfcphMBwHRNfNnMObDYdnw1qUteLBALkoyUqU0L0zLnN TwrSNdB/Pr92Cp10sI7G3NuuzWL0r02QJtCNnNE7XioH6VVrlLe4qK9lGQ6YIN5e/jG3 UrALrElfdCmFYsCaEYwb75agda3LoLx7XblbTcY4D/CWV7Lf5piKYKfLnNuRodSDu0UR HI7+c4crVHqmomo9uN8HqEmYPzHK/lKm67WEW+6wL/U+pKmOh/8REz1DsKOiWqP7enQy T3AAap7+qFOkoQ3FQP9QZZOS+YMk98RMMnyDXxrwH+op1KHIUdrgw1s8lJEUZ5+FDX/4 kkXA== 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=96qxitp+mIBbRdtkL3noBukHAsCzdBuvulBjmwV/Mdk=; b=o5667zcv/s3R2OGA+xzGQicNIUyRAARiiVLB9HZUbLSEK5xlxrz3kOc15hbC+LruHK KWDUTw28//sVVLxgoE//IToIUAT1d9eVUOVFq4zUvLbW47BMYU08h/lfZIpJUxRRfzxi w1aYnujtmTAdnR+iiqByrYrnMyctzWRkpcvEuS8oE8/CnulIjp4YBGwyVGntiLqMq5Fh 7QL0YI1j1vPLPC2HD8Mj9l6rpAePBz0hM8+uM4WVgLoeCQj5XLoy7By7rUzA6XtWMtHy vJ7S/LpGZ42kOFJBB23tf1AAvWj70TjFWT2aUIT3sVDBmeI3zOdn9fh9BUgZDRNq9fUA JgJA== X-Gm-Message-State: AOAM531cVLgUFrUUU5vum0D1vljmeZYe1dDsjhNa28s60rSPUICzVg3Y 9JZMlRaqPemNlv4JMFdcWgFs8tvHkeU= X-Google-Smtp-Source: ABdhPJwv5UssDcv1qqHbIYqwdgzKNlyBi9e0vUyxMdN54eosDiKAUSinlK7P5GXanBf6lLe+igDmIg== X-Received: by 2002:adf:de05:: with SMTP id b5mr11819695wrm.131.1606495927593; Fri, 27 Nov 2020 08:52:07 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:e9bd:38ae:745f:40ea]) by smtp.gmail.com with ESMTPSA id y2sm15895539wrn.31.2020.11.27.08.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 08:52:07 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 7/8] factorize (x OP1 z) OP2 (y OP1 z) into (x OP2 y) OP1 z Date: Fri, 27 Nov 2020 17:49:49 +0100 Message-Id: <20201127164950.41517-8-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> References: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Factorize common distributive operations: (x * z) + (y * z) --> (x + y) * z (x | z) & (y | z) --> (x & y) | z (x & z) | (y & z) --> (x | y) & z (x & z) ^ (y & z) --> (x ^ y) & z Signed-off-by: Luc Van Oostenryck --- simplify.c | 78 +++++++++++++++++++++++++++++++++ validation/optim/fact-add-mul.c | 1 - validation/optim/fact-and-ior.c | 1 - validation/optim/fact-ior-and.c | 1 - validation/optim/fact-xor-and.c | 1 - 5 files changed, 78 insertions(+), 4 deletions(-) diff --git a/simplify.c b/simplify.c index 5174a903dfd6..319112a90b7b 100644 --- a/simplify.c +++ b/simplify.c @@ -1622,11 +1622,32 @@ static int simplify_associative_binop(struct instruction *insn) static int simplify_add_one_side(struct instruction *insn, pseudo_t *p1, pseudo_t *p2) { + struct instruction *defr = NULL; struct instruction *def; pseudo_t src1 = *p1; pseudo_t src2 = *p2; switch (DEF_OPCODE(def, src1)) { + case OP_MUL: + if (DEF_OPCODE(defr, *p2) == OP_MUL) { + if (defr->src2 == def->src2 && can_move_to(def->src2, defr)) { + // ((x * z) + (y * z)) into ((x + y) * z) + swap_insn(insn, defr, def->src1, defr->src1, def->src2); + return REPEAT_CSE; + } + if (defr->src1 == def->src1 && can_move_to(def->src1, defr)) { + // ((z * x) + (z * y)) into ((x + y) * z) + swap_insn(insn, defr, def->src2, defr->src2, def->src1); + return REPEAT_CSE; + } + if (defr->src1 == def->src2 && can_move_to(def->src1, defr)) { + // ((x * z) + (z * y)) into ((x + y) * z) + swap_insn(insn, defr, def->src1, defr->src2, def->src2); + return REPEAT_CSE; + } + } + break; + case OP_NEG: // (-x + y) --> (y - x) return replace_binop(insn, OP_SUB, &insn->src1, src2, &insn->src2, def->src); @@ -1714,6 +1735,25 @@ static int simplify_and_one_side(struct instruction *insn, pseudo_t *p1, pseudo_ return replace_with_value(insn, 0); } break; + case OP_OR: + if (DEF_OPCODE(defr, *p2) == OP_OR) { + if (defr->src2 == def->src2 && can_move_to(def->src2, defr)) { + // ((x | z) & (y | z)) into ((x & y) | z) + swap_insn(insn, defr, def->src1, defr->src1, def->src2); + return REPEAT_CSE; + } + if (defr->src1 == def->src1 && can_move_to(def->src1, defr)) { + // ((z | x) & (z | y)) into ((x & y) | z) + swap_insn(insn, defr, def->src2, defr->src2, def->src1); + return REPEAT_CSE; + } + if (defr->src1 == def->src2 && can_move_to(def->src1, defr)) { + // ((x | z) & (z | y)) into ((x & y) | z) + swap_insn(insn, defr, def->src1, defr->src2, def->src2); + return REPEAT_CSE; + } + } + break; } return 0; } @@ -1730,6 +1770,25 @@ static int simplify_ior_one_side(struct instruction *insn, pseudo_t *p1, pseudo_ pseudo_t src1 = *p1; switch (DEF_OPCODE(def, src1)) { + case OP_AND: + if (DEF_OPCODE(defr, *p2) == OP_AND) { + if (defr->src2 == def->src2 && can_move_to(def->src2, defr)) { + // ((x & z) | (y & z)) into ((x | y) & z) + swap_insn(insn, defr, def->src1, defr->src1, def->src2); + return REPEAT_CSE; + } + if (defr->src1 == def->src1 && can_move_to(def->src1, defr)) { + // ((z & x) | (z & y)) into ((x | y) & z) + swap_insn(insn, defr, def->src2, defr->src2, def->src1); + return REPEAT_CSE; + } + if (defr->src1 == def->src2 && can_move_to(def->src1, defr)) { + // ((x & z) | (z & y)) into ((x | y) & z) + swap_insn(insn, defr, def->src1, defr->src2, def->src2); + return REPEAT_CSE; + } + } + break; case OP_NOT: if (def->src == *p2) return replace_with_value(insn, bits_mask(insn->size)); @@ -1756,6 +1815,25 @@ static int simplify_xor_one_side(struct instruction *insn, pseudo_t *p1, pseudo_ pseudo_t src1 = *p1; switch (DEF_OPCODE(def, src1)) { + case OP_AND: + if (DEF_OPCODE(defr, *p2) == OP_AND) { + if (defr->src2 == def->src2 && can_move_to(def->src2, defr)) { + // ((x & z) ^ (y & z)) into ((x ^ y) & z) + swap_insn(insn, defr, def->src1, defr->src1, def->src2); + return REPEAT_CSE; + } + if (defr->src1 == def->src1 && can_move_to(def->src1, defr)) { + // ((z & x) ^ (z & y)) into ((x ^ y) & z) + swap_insn(insn, defr, def->src2, defr->src2, def->src1); + return REPEAT_CSE; + } + if (defr->src1 == def->src2 && can_move_to(def->src1, defr)) { + // ((x & z) ^ (z & y)) into ((x ^ y) & z) + swap_insn(insn, defr, def->src1, defr->src2, def->src2); + return REPEAT_CSE; + } + } + break; case OP_NOT: if (def->src == *p2) return replace_with_value(insn, bits_mask(insn->size)); diff --git a/validation/optim/fact-add-mul.c b/validation/optim/fact-add-mul.c index 48c3d656accc..9da6d71c9a7d 100644 --- a/validation/optim/fact-add-mul.c +++ b/validation/optim/fact-add-mul.c @@ -21,7 +21,6 @@ int fn_bxa(int b, int x, int a) { return ((x * b) + (a * x)) == ((b + a) * x); } /* * check-name: fact-add-mul * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 diff --git a/validation/optim/fact-and-ior.c b/validation/optim/fact-and-ior.c index f2a78eddf41d..96466616d877 100644 --- a/validation/optim/fact-and-ior.c +++ b/validation/optim/fact-and-ior.c @@ -21,7 +21,6 @@ int fn_bxa(int b, int x, int a) { return ((x | b) & (a | x)) == ((b & a) | x); } /* * check-name: fact-and-ior * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 diff --git a/validation/optim/fact-ior-and.c b/validation/optim/fact-ior-and.c index 7af89df1e1f0..a6ad3c45515d 100644 --- a/validation/optim/fact-ior-and.c +++ b/validation/optim/fact-ior-and.c @@ -21,7 +21,6 @@ int fn_bxa(int b, int x, int a) { return ((x & b) | (a & x)) == ((b | a) & x); } /* * check-name: fact-ior-and * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 diff --git a/validation/optim/fact-xor-and.c b/validation/optim/fact-xor-and.c index 905cbf4ab659..62232b29da40 100644 --- a/validation/optim/fact-xor-and.c +++ b/validation/optim/fact-xor-and.c @@ -21,7 +21,6 @@ int fn_bxa(int b, int x, int a) { return ((x & b) ^ (a & x)) == ((b ^ a) & x); } /* * check-name: fact-xor-and * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 From patchwork Fri Nov 27 16:49:50 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: 11936929 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.7 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 416CDC71156 for ; Fri, 27 Nov 2020 16:52:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 10C88221EB for ; Fri, 27 Nov 2020 16:52:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F4LBZzn8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732138AbgK0QwK (ORCPT ); Fri, 27 Nov 2020 11:52:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732032AbgK0QwK (ORCPT ); Fri, 27 Nov 2020 11:52:10 -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 12E2FC0613D1 for ; Fri, 27 Nov 2020 08:52:10 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id w24so7123561wmi.0 for ; Fri, 27 Nov 2020 08:52:10 -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=6MxQEPAlZddDzkoKOwm1PjTUhwDPKHRvL3sAVuYJutc=; b=F4LBZzn8+KrmQ9/xOKNnBaV3DYPkt6A5niZWvc1re3mm80dXiRiS56gn/GVrv+WBfW VCMcffckbedwvoA57VZNoHEAulDhkSdccPp/qWxcDyI03R9oABvR0aZORDysgYNp9aF4 Kxqig+mQkLiBnd4nLTT8AveBdXD9PTm7dHyZ9HzDOQSqGMB28y03gBFp2ocFpNCEA/YU uj8UBlq+B4yOnZX+gaXH+BZPy9J6caG2rzUgsIT1pxCF1G3vsA3nvKWkBMTxtFItbsrm rNdZfbho2UbeX2QMtw5YzZfVX4RySy8lS3nG6pprmN1uxoRfA6s5jYbZS4Wy+WImfqug SoxA== 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=6MxQEPAlZddDzkoKOwm1PjTUhwDPKHRvL3sAVuYJutc=; b=UX+NG4rKchQdbqbLoLK0uRwJR7ySWH+Iw6191S8RRE7f1QrrNOQOzCMvjgWfNHGQ9X wSzpXeMqBtcpxYqDNR08exbRxmfUnKyTZ8siQ+USItLeQS6SQS1unXc8OSjEGg8iRd2A jJ0JjgbzYpJt1WAjcQ7aRr8TaMHOP8Ks9kMVDVDZwpxQ7roXqzlVN+By9Ed14xRcLm/x GgrTTRZZ9GVO87npMfmfK6lorP1WdCHYULZJzgC6JHO8cqFGpYawnAd96VZd0KtKFLnj 3ZuqC1qUgQeH9pO6GNcIij8UumxSXs9BkiGMuN0PG0EtPt2qPL3Vqcoe5Uz7XWe8wJ8r GDkw== X-Gm-Message-State: AOAM533xCUlvekCRCMpLvUzOy7fzbKzj5ovPUq1+wKvx6HIEUptOkaje z+clqbPoMtGCIWH7ljYjb2AfGwTI3AQ= X-Google-Smtp-Source: ABdhPJytZnt9Axt5JXr5g0gCU99uUVU8mmWL7pxKliGhmVumBV75IU8rFGlBrE+NLjpqq3ynauaIsw== X-Received: by 2002:a1c:4c14:: with SMTP id z20mr10037403wmf.149.1606495928610; Fri, 27 Nov 2020 08:52:08 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:e9bd:38ae:745f:40ea]) by smtp.gmail.com with ESMTPSA id y2sm15895539wrn.31.2020.11.27.08.52.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 08:52:08 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 8/8] factorize SHIFT(x, s) OP SHIFT(y, s) into SHIFT((x OP y), s) Date: Fri, 27 Nov 2020 17:49:50 +0100 Message-Id: <20201127164950.41517-9-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> References: <20201127164950.41517-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Factorize bitwise OPs of shifts with identical counts. Signed-off-by: Luc Van Oostenryck --- simplify.c | 27 +++++++++++++++++++++++++++ validation/optim/fact-and-shift.c | 1 - validation/optim/fact-ior-shift.c | 1 - validation/optim/fact-xor-shift.c | 1 - 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/simplify.c b/simplify.c index 319112a90b7b..89a064b93e85 100644 --- a/simplify.c +++ b/simplify.c @@ -1754,6 +1754,15 @@ static int simplify_and_one_side(struct instruction *insn, pseudo_t *p1, pseudo_ } } break; + case OP_SHL: case OP_LSR: case OP_ASR: + if (DEF_OPCODE(defr, *p2) == def->opcode && defr->src2 == def->src2) { + if (can_move_to(def->src1, defr)) { + // SHIFT(x, s) & SHIFT(y, s) --> SHIFT((x & y), s) + swap_insn(insn, defr, def->src1, defr->src1, def->src2); + return REPEAT_CSE; + } + } + break; } return 0; } @@ -1799,6 +1808,15 @@ static int simplify_ior_one_side(struct instruction *insn, pseudo_t *p1, pseudo_ return replace_with_value(insn, 1); } break; + case OP_SHL: case OP_LSR: case OP_ASR: + if (DEF_OPCODE(defr, *p2) == def->opcode && defr->src2 == def->src2) { + if (can_move_to(def->src1, defr)) { + // SHIFT(x, s) | SHIFT(y, s) --> SHIFT((x | y), s) + swap_insn(insn, defr, def->src1, defr->src1, def->src2); + return REPEAT_CSE; + } + } + break; } return 0; } @@ -1844,6 +1862,15 @@ static int simplify_xor_one_side(struct instruction *insn, pseudo_t *p1, pseudo_ return replace_with_value(insn, 1); } break; + case OP_SHL: case OP_LSR: case OP_ASR: + if (DEF_OPCODE(defr, *p2) == def->opcode && defr->src2 == def->src2) { + if (can_move_to(def->src1, defr)) { + // SHIFT(x, s) ^ SHIFT(y, s) --> SHIFT((x ^ y), s) + swap_insn(insn, defr, def->src1, defr->src1, def->src2); + return REPEAT_CSE; + } + } + break; } return 0; } diff --git a/validation/optim/fact-and-shift.c b/validation/optim/fact-and-shift.c index 401750216b44..e9eb9cceef95 100644 --- a/validation/optim/fact-and-shift.c +++ b/validation/optim/fact-and-shift.c @@ -20,7 +20,6 @@ sint fact_and_asr(sint a, sint b, sint s) /* * check-name: fact-and-shift * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 diff --git a/validation/optim/fact-ior-shift.c b/validation/optim/fact-ior-shift.c index 07fdf80604dc..5fa91eb5cfc2 100644 --- a/validation/optim/fact-ior-shift.c +++ b/validation/optim/fact-ior-shift.c @@ -20,7 +20,6 @@ sint fact_ior_asr(sint a, sint b, sint s) /* * check-name: fact-ior-shift * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 diff --git a/validation/optim/fact-xor-shift.c b/validation/optim/fact-xor-shift.c index 81fcda851400..5fb228bd80a1 100644 --- a/validation/optim/fact-xor-shift.c +++ b/validation/optim/fact-xor-shift.c @@ -20,7 +20,6 @@ sint fact_xor_asr(sint a, sint b, sint s) /* * check-name: fact-xor-shift * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1