From patchwork Wed Dec 7 16:05:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9464783 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E508560512 for ; Wed, 7 Dec 2016 16:06:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E041E284FD for ; Wed, 7 Dec 2016 16:06:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D527C28520; Wed, 7 Dec 2016 16:06:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA649284FD for ; Wed, 7 Dec 2016 16:06:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752921AbcLGQGm (ORCPT ); Wed, 7 Dec 2016 11:06:42 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35681 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752203AbcLGQGk (ORCPT ); Wed, 7 Dec 2016 11:06:40 -0500 Received: by mail-wm0-f66.google.com with SMTP id a20so28829422wme.2 for ; Wed, 07 Dec 2016 08:05:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=FxdWEsOS5cs4xvWvq8O2rp9nnovjHB8t9rDe+RW7j7s=; b=I/yETZ3GuHO1QBIb8hc6pbEiwmQj/pUuKk3IE8DD7rjKhQfOeZ5fdex3qRFAspGd4M bUSdfYXWIVLYFY2eJKnr6YyvsHSDYaJe2+1HJsvqCZDJks1zcuqTTWi1cv1MrecLK8oZ 5lphh6b8Ftiuhd2MNXgkQML+e8pBLZd6KzFz+u57D2SV1Nn9dCnUyT3S1teWvX98SANO f6qIMXGww90T8jiRD02Sk+tW0Hl7CS3wVEHF9LGMRWL61trt/lc6pxOlZskQ+lqP2Cbc Lq1H4xXMP+k0wT8CTpHizoeOfUYfLxLuVlPtupzu+enjCxed7dwZ5yZaXizml6zzUQ4R VSPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FxdWEsOS5cs4xvWvq8O2rp9nnovjHB8t9rDe+RW7j7s=; b=WlhdxHn0ET083w0CKbnlfha8VfTjgsv30FOE4dK0KIQfbVLkpgm4sdYJWRvfzfbzNg 0+Bj4Aj1cGiQxN3n6IgJ0rHP2dIs7tCMnWG6jWIe1kq9o3ysEYXZ6/cuIpvUQxOeG6/o HnxbS5dJEsUTjZJb4GBjy1s5j6ghN8wlAgVbfDfHUHjeTFYlLaPeGzUzEQn3AXgQpyeu M3LfCEPHDGVj3oHqwdMWuhwjdEcaHiAVV3Kjr7TytW9soDNPRaIULkQxlJ57iAPmk5pS NpLslWwd/dpVdvYMjNcjMcLtPc1OLmfNlyPB44oslazPaqUnd+diO8SBPsOZU11uP0v/ kDaQ== X-Gm-Message-State: AKaTC01zkb2IGna0RfDxS3kkH1jVZY4WVXuQ9kDs5hpji6xn+bdJ18AFPUuK7bptmAYsng== X-Received: by 10.28.35.14 with SMTP id j14mr3331451wmj.24.1481126751948; Wed, 07 Dec 2016 08:05:51 -0800 (PST) Received: from localhost.localdomain ([91.180.121.141]) by smtp.gmail.com with ESMTPSA id b15sm10410553wma.5.2016.12.07.08.05.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2016 08:05:51 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH] simplify '~(~x)' and '-(-x)' to 'x' Date: Wed, 7 Dec 2016 17:05:47 +0100 Message-Id: <20161207160547.9821-1-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.10.2 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently those double operations are not simplified. This patch add those simplifications and some small test cases. Note: the 'boolean not': '!(!x)' is not handled by this patch because this operator is processed differently (it doesn't generate an unop instruction but directly generates 'seteq' operations). Signed-off-by: Luc Van Oostenryck --- WARNING: the test cases, to give the correct results, need the patches from the serie "fix uses of killed instructions" sent previously. simplify.c | 17 +++++++++++++++++ validation/optim/double-unop.c | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 validation/optim/double-unop.c diff --git a/simplify.c b/simplify.c index b5cd0ea7..7e4bce5b 100644 --- a/simplify.c +++ b/simplify.c @@ -588,6 +588,23 @@ static int simplify_unop(struct instruction *insn) return REPEAT_CSE; if (constant(insn->src1)) return simplify_constant_unop(insn); + + switch (insn->opcode) { + struct instruction *def; + + case OP_NOT: + def = insn->src->def; + if (def && def->opcode == OP_NOT) + return replace_with_pseudo(insn, def->src); + break; + case OP_NEG: + def = insn->src->def; + if (def && def->opcode == OP_NEG) + return replace_with_pseudo(insn, def->src); + break; + default: + return 0; + } return 0; } diff --git a/validation/optim/double-unop.c b/validation/optim/double-unop.c new file mode 100644 index 00000000..f0e6d94f --- /dev/null +++ b/validation/optim/double-unop.c @@ -0,0 +1,15 @@ +typedef unsigned int u32; + +u32 unotnot(u32 a) { return ~(~a); } +int snotnot(int a) { return ~(~a); } +u32 unegneg(int a) { return -(-a); } +int snegneg(int a) { return -(-a); } + +/* + * check-name: double-unop + * check-command: test-linearize -Wno-decl $file + * check-output-ignore + * + * check-output-excludes: not\\. + * check-output-excludes: neg\\. + */