From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 11/16] cmp: simplify zext(x) cmp C --> x cmp C
Date: Sun, 8 Nov 2020 02:21:21 +0100 [thread overview]
Message-ID: <20201108012126.94339-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20201108012126.94339-1-luc.vanoostenryck@gmail.com>
When doing a compare of a zero-extended value against a constant,
this extension can be dropped and the comparison done on the
original type if the constant is within the original range and
signed compares become the corresponding unsigned one.
Simplify away these sign-extensions.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 11 +++++++++++
validation/optim/cmp-zext-uimm1.c | 1 -
validation/optim/cmp-zext.c | 1 -
validation/optim/zext-cmpu.c | 1 -
4 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/simplify.c b/simplify.c
index eb2c724f6307..1cb5275b7a73 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1149,6 +1149,17 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
return replace_pseudo(insn, &insn->src1, def->src);
}
break;
+ case OP_ZEXT:
+ osize = def->orig_type->bit_size;
+ bits = bits_mask(osize);
+ if (value <= bits) {
+ const struct opcode_table *op = &opcode_table[insn->opcode];
+ if (op->flags & OPF_SIGNED)
+ insn->opcode = op->sign;
+ insn->itype = def->orig_type;
+ return replace_pseudo(insn, &insn->src1, def->src);
+ }
+ break;
}
return changed;
}
diff --git a/validation/optim/cmp-zext-uimm1.c b/validation/optim/cmp-zext-uimm1.c
index ffcdaad5c1bd..c21780ea728d 100644
--- a/validation/optim/cmp-zext-uimm1.c
+++ b/validation/optim/cmp-zext-uimm1.c
@@ -9,7 +9,6 @@ int zext_gt_p(unsigned int x) { return (zext(x) > (BITS )) == 0; }
/*
* check-name: cmp-zext-uimm1
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
diff --git a/validation/optim/cmp-zext.c b/validation/optim/cmp-zext.c
index ecee6b5e9101..ac4847806251 100644
--- a/validation/optim/cmp-zext.c
+++ b/validation/optim/cmp-zext.c
@@ -11,7 +11,6 @@ _Bool cmpu_zext(ARGS(UINT32)) { return TEST(UINT64, UINT32, a, < , 0xffffffff);
/*
* check-name: cmp-zext
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
diff --git a/validation/optim/zext-cmpu.c b/validation/optim/zext-cmpu.c
index 279ed70e0fda..9758e0710d7b 100644
--- a/validation/optim/zext-cmpu.c
+++ b/validation/optim/zext-cmpu.c
@@ -10,7 +10,6 @@ int gtl(unsigned x) { return (((long long)x) > 0x0fffffffeULL) == (x > 0xfffff
/*
* check-name: zext-cmpu
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
--
2.29.2
next prev parent reply other threads:[~2020-11-08 1:21 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-08 1:19 [PATCH 00/16] simplify & canonicalize compares Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 01/16] cmp: adapt testcase for compares' canonicalization Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 02/16] cmp: add testcases for the simplification of compares Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 03/16] cmp: add signed/unsigned to opcode table Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 04/16] cmp: move some code in a separate function: simplify_compare_constant() Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 05/16] cmp: use a few helpers for the simplification of compares Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 06/16] cmp: canonicalize unsigned (x {<,>=} C) --> (x {<=,>} C-1) Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 07/16] cmp: simplify unsigned (x {<=,>} UMAX) into {1,0} Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 08/16] cmp: canonicalize unsigned compare with UMAX or UMAX-1 Luc Van Oostenryck
2020-11-08 1:19 ` [PATCH 09/16] cmp: canonicalize unsigned (x {<=,>} SMAX) Luc Van Oostenryck
2020-11-08 1:21 ` [PATCH 10/16] cmp: simplify sext(x) cmp C --> x cmp C Luc Van Oostenryck
2020-11-08 1:21 ` Luc Van Oostenryck [this message]
2020-11-08 1:21 ` [PATCH 12/16] cmp: simplify sext(x) cmps {SMAX,SMIN} Luc Van Oostenryck
2020-11-08 1:21 ` [PATCH 13/16] cmp: canonicalize sext(x) cmpu C (with C >= SMAX) Luc Van Oostenryck
2020-11-08 1:21 ` [PATCH 14/16] cmp: simplify zext(x) cmps C Luc Van Oostenryck
2020-11-08 1:21 ` [PATCH 15/16] cmp: simplify zext(x) cmpu C Luc Van Oostenryck
2020-11-08 1:21 ` [PATCH 16/16] cmp: simplify compares and sign/zero extend Luc Van Oostenryck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201108012126.94339-2-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).