* [PATCH 0/9] simplify CMP(AND(x,M), C) and CMP(OR(x,M), C)
@ 2021-03-10 21:49 Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 1/9] change testing of signed compares against SMIN or SMAX Luc Van Oostenryck
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2021-03-10 21:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
This series contains simplifications of compaes between a constant
and a constant AND/OR mask.
Luc Van Oostenryck (9):
change testing of signed compares against SMIN or SMAX
add testcases for constant compares against AND/OR
simplify (x & M) cmps C
simplify (x & M) cmpu C
simplify (x & M) cmps 0
simplify (x & M) {==,!=} C
simplify (x | M) {==,!=} C
simplify (x | M) cmps C
simplify (x | M) cmpu C
simplify.c | 98 ++++++++++++++++++++++++++++++++++
validation/optim/cmpe-and0.c | 10 ++++
validation/optim/cmpe-or0.c | 10 ++++
validation/optim/cmps-and0.c | 21 ++++++++
validation/optim/cmps-minmax.c | 8 +--
validation/optim/cmps-or0.c | 21 ++++++++
validation/optim/cmps0-and0.c | 12 +++++
validation/optim/cmpu-and0.c | 17 ++++++
validation/optim/cmpu-or0.c | 18 +++++++
9 files changed, 211 insertions(+), 4 deletions(-)
create mode 100644 validation/optim/cmpe-and0.c
create mode 100644 validation/optim/cmpe-or0.c
create mode 100644 validation/optim/cmps-and0.c
create mode 100644 validation/optim/cmps-or0.c
create mode 100644 validation/optim/cmps0-and0.c
create mode 100644 validation/optim/cmpu-and0.c
create mode 100644 validation/optim/cmpu-or0.c
--
2.30.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/9] change testing of signed compares against SMIN or SMAX
2021-03-10 21:49 [PATCH 0/9] simplify CMP(AND(x,M), C) and CMP(OR(x,M), C) Luc Van Oostenryck
@ 2021-03-10 21:49 ` Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 2/9] add testcases for constant compares against AND/OR Luc Van Oostenryck
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2021-03-10 21:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
These tests are written by testing if the comparisons are equal
to their expected value: 0 or 1. So, a compare of a compare
but such compares of compare have their own simplification
which defeats what's tested here.
So, rewrite the test to avoid such compares of compare.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
validation/optim/cmps-minmax.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/validation/optim/cmps-minmax.c b/validation/optim/cmps-minmax.c
index 5802cdbcafd1..0b1a0a099d7d 100644
--- a/validation/optim/cmps-minmax.c
+++ b/validation/optim/cmps-minmax.c
@@ -1,11 +1,11 @@
#define SMAX __INT_MAX__
#define SMIN (-__INT_MAX__-1)
-int lt_smin(int a) { return (a < SMIN) == 0; }
-int le_smax(int a) { return (a <= SMAX) == 1; }
+int lt_smin(int a) { return (a < SMIN) + 1; }
+int le_smax(int a) { return (a <= SMAX) + 0; }
-int ge_smin(int a) { return (a >= SMIN) == 1; }
-int gt_smax(int a) { return (a > SMAX) == 0; }
+int ge_smin(int a) { return (a >= SMIN) + 0; }
+int gt_smax(int a) { return (a > SMAX) + 1; }
/*
* check-name: cmps-minmax
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/9] add testcases for constant compares against AND/OR
2021-03-10 21:49 [PATCH 0/9] simplify CMP(AND(x,M), C) and CMP(OR(x,M), C) Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 1/9] change testing of signed compares against SMIN or SMAX Luc Van Oostenryck
@ 2021-03-10 21:49 ` Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 3/9] simplify (x & M) cmps C Luc Van Oostenryck
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2021-03-10 21:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
validation/optim/cmpe-and0.c | 11 +++++++++++
validation/optim/cmpe-or0.c | 11 +++++++++++
validation/optim/cmps-and0.c | 22 ++++++++++++++++++++++
validation/optim/cmps-or0.c | 22 ++++++++++++++++++++++
validation/optim/cmps0-and0.c | 13 +++++++++++++
validation/optim/cmpu-and0.c | 18 ++++++++++++++++++
validation/optim/cmpu-or0.c | 19 +++++++++++++++++++
7 files changed, 116 insertions(+)
create mode 100644 validation/optim/cmpe-and0.c
create mode 100644 validation/optim/cmpe-or0.c
create mode 100644 validation/optim/cmps-and0.c
create mode 100644 validation/optim/cmps-or0.c
create mode 100644 validation/optim/cmps0-and0.c
create mode 100644 validation/optim/cmpu-and0.c
create mode 100644 validation/optim/cmpu-or0.c
diff --git a/validation/optim/cmpe-and0.c b/validation/optim/cmpe-and0.c
new file mode 100644
index 000000000000..7db608365568
--- /dev/null
+++ b/validation/optim/cmpe-and0.c
@@ -0,0 +1,11 @@
+int cmpe_and_eq(int a) { return ((a & 0xff00) == 0xff01) + 1; }
+int cmpe_and_ne(int a) { return ((a & 0xff00) != 0xff01) + 0; }
+
+/*
+ * check-name: cmpe-and0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/optim/cmpe-or0.c b/validation/optim/cmpe-or0.c
new file mode 100644
index 000000000000..bef2316120f7
--- /dev/null
+++ b/validation/optim/cmpe-or0.c
@@ -0,0 +1,11 @@
+int cmp_eq(int a) { return ((a | 1) != 0) + 0; }
+int cmp_ne(int a) { return ((a | 1) == 0) + 1; }
+
+/*
+ * check-name: cmpe-or0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/optim/cmps-and0.c b/validation/optim/cmps-and0.c
new file mode 100644
index 000000000000..097ec2f9f16c
--- /dev/null
+++ b/validation/optim/cmps-and0.c
@@ -0,0 +1,22 @@
+#define MINUS_ONE -1
+#define MASK 32
+
+
+int cmps_and_lt_lt0(int a) { return ((a & MASK) < MINUS_ONE) + 1; }
+int cmps_and_lt_gtm(int a) { return ((a & MASK) < (MASK + 1)) + 0; }
+int cmps_and_le_lt0(int a) { return ((a & MASK) <= MINUS_ONE) + 1; }
+int cmps_and_le_gtm(int a) { return ((a & MASK) <= (MASK + 1)) + 0; }
+
+int cmps_and_gt_lt0(int a) { return ((a & MASK) > MINUS_ONE) + 0; }
+int cmps_and_gt_gtm(int a) { return ((a & MASK) > (MASK + 1)) + 1; }
+int cmps_and_ge_lt0(int a) { return ((a & MASK) >= MINUS_ONE) + 0; }
+int cmps_and_ge_gtm(int a) { return ((a & MASK) >= (MASK + 1)) + 1; }
+
+/*
+ * check-name: cmps-and0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/optim/cmps-or0.c b/validation/optim/cmps-or0.c
new file mode 100644
index 000000000000..40a2092c58a4
--- /dev/null
+++ b/validation/optim/cmps-or0.c
@@ -0,0 +1,22 @@
+#define EQ(X) + (X == 0)
+#define SIGN (1 << 31)
+#define MASK (SIGN | 32)
+
+
+int cmps_ior_lt_x(int a) { return ((a | MASK) < 4) EQ(1); }
+int cmps_ior_lt_0(int a) { return ((a | MASK) < 0) EQ(1); }
+int cmps_ior_le_x(int a) { return ((a | MASK) <= 4) EQ(1); }
+int cmps_ior_le_0(int a) { return ((a | MASK) <= 0) EQ(1); }
+int cmps_ior_ge_x(int a) { return ((a | MASK) >= 4) EQ(0); }
+int cmps_ior_ge_0(int a) { return ((a | MASK) >= 0) EQ(0); }
+int cmps_ior_gt_x(int a) { return ((a | MASK) > 4) EQ(0); }
+int cmps_ior_gt_0(int a) { return ((a | MASK) > 0) EQ(0); }
+
+/*
+ * check-name: cmps-or0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/optim/cmps0-and0.c b/validation/optim/cmps0-and0.c
new file mode 100644
index 000000000000..819a1dc2a793
--- /dev/null
+++ b/validation/optim/cmps0-and0.c
@@ -0,0 +1,13 @@
+#define M 32
+
+int cmps_and_sle0(int a) { return ((a & M) <= 0) == ((a & M) == 0); }
+int cmps_and_sgt0(int a) { return ((a & M) > 0) == ((a & M) != 0); }
+
+/*
+ * check-name: cmps0-and
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/optim/cmpu-and0.c b/validation/optim/cmpu-and0.c
new file mode 100644
index 000000000000..253212941779
--- /dev/null
+++ b/validation/optim/cmpu-and0.c
@@ -0,0 +1,18 @@
+#define MASK 32U
+
+
+int cmps_and_ltu_gt(int a) { return ((a & MASK) < (MASK + 1)) + 0; }
+int cmps_and_leu_gt(int a) { return ((a & MASK) <= (MASK + 1)) + 0; }
+int cmps_and_leu_eq(int a) { return ((a & MASK) <= (MASK + 0)) + 0; }
+int cmps_and_geu_gt(int a) { return ((a & MASK) >= (MASK + 1)) + 1; }
+int cmps_and_gtu_gt(int a) { return ((a & MASK) > (MASK + 1)) + 1; }
+int cmps_and_gtu_eq(int a) { return ((a & MASK) > (MASK + 0)) + 1; }
+
+/*
+ * check-name: cmpu-and0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
diff --git a/validation/optim/cmpu-or0.c b/validation/optim/cmpu-or0.c
new file mode 100644
index 000000000000..77360d3feb0f
--- /dev/null
+++ b/validation/optim/cmpu-or0.c
@@ -0,0 +1,19 @@
+#define EQ(X) + (X == 0)
+#define MASK 32U
+
+
+int cmpu_ior_lt_lt(int a) { return ((a | MASK) < (MASK - 1)) EQ(0); }
+int cmpu_ior_lt_eq(int a) { return ((a | MASK) < (MASK )) EQ(0); }
+int cmpu_ior_le_lt(int a) { return ((a | MASK) <= (MASK - 1)) EQ(0); }
+int cmpu_ior_ge_lt(int a) { return ((a | MASK) >= (MASK - 1)) EQ(1); }
+int cmpu_ior_ge_eq(int a) { return ((a | MASK) >= (MASK )) EQ(1); }
+int cmpu_ior_gt_lt(int a) { return ((a | MASK) > (MASK - 1)) EQ(1); }
+
+/*
+ * check-name: cmpu-or0
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/9] simplify (x & M) cmps C
2021-03-10 21:49 [PATCH 0/9] simplify CMP(AND(x,M), C) and CMP(OR(x,M), C) Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 1/9] change testing of signed compares against SMIN or SMAX Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 2/9] add testcases for constant compares against AND/OR Luc Van Oostenryck
@ 2021-03-10 21:49 ` Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 4/9] simplify (x & M) cmpu C Luc Van Oostenryck
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2021-03-10 21:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 25 +++++++++++++++++++++++++
validation/optim/cmps-and0.c | 1 -
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/simplify.c b/simplify.c
index 207af8edf28f..90b0c5ba0127 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1258,6 +1258,31 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
src2 = insn->src2;
value = src2->value;
switch (DEF_OPCODE(def, src1)) {
+ case OP_AND:
+ if (!constant(def->src2))
+ break;
+ bits = def->src2->value;
+ switch (insn->opcode) {
+ case OP_SET_LE:
+ value = sign_extend(value, def->size);
+ if (bits & sign_bit(def->size))
+ break;
+ if (value < 0)
+ return replace_with_value(insn, 0);
+ if (value >= (long long)bits)
+ return replace_with_value(insn, 1);
+ break;
+ case OP_SET_GT:
+ value = sign_extend(value, def->size);
+ if (bits & sign_bit(def->size))
+ break;
+ if (value < 0)
+ return replace_with_value(insn, 1);
+ if (value >= (long long)bits)
+ return replace_with_value(insn, 0);
+ break;
+ }
+ break;
case OP_SEXT: // sext(x) cmp C --> x cmp trunc(C)
osize = def->orig_type->bit_size;
if (is_signed_constant(value, osize, size)) {
diff --git a/validation/optim/cmps-and0.c b/validation/optim/cmps-and0.c
index 097ec2f9f16c..962fbd2d29f8 100644
--- a/validation/optim/cmps-and0.c
+++ b/validation/optim/cmps-and0.c
@@ -15,7 +15,6 @@ int cmps_and_ge_gtm(int a) { return ((a & MASK) >= (MASK + 1)) + 1; }
/*
* check-name: cmps-and0
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/9] simplify (x & M) cmpu C
2021-03-10 21:49 [PATCH 0/9] simplify CMP(AND(x,M), C) and CMP(OR(x,M), C) Luc Van Oostenryck
` (2 preceding siblings ...)
2021-03-10 21:49 ` [PATCH 3/9] simplify (x & M) cmps C Luc Van Oostenryck
@ 2021-03-10 21:49 ` Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 5/9] simplify (x & M) cmps 0 Luc Van Oostenryck
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2021-03-10 21:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 16 ++++++++++++++++
validation/optim/cmpu-and0.c | 1 -
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/simplify.c b/simplify.c
index 90b0c5ba0127..ee29c9619bdc 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1281,6 +1281,22 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
if (value >= (long long)bits)
return replace_with_value(insn, 0);
break;
+ case OP_SET_B:
+ if (value > bits)
+ return replace_with_value(insn, 1);
+ break;
+ case OP_SET_BE:
+ if (value >= bits)
+ return replace_with_value(insn, 1);
+ break;
+ case OP_SET_AE:
+ if (value > bits)
+ return replace_with_value(insn, 0);
+ break;
+ case OP_SET_A:
+ if (value >= bits)
+ return replace_with_value(insn, 0);
+ break;
}
break;
case OP_SEXT: // sext(x) cmp C --> x cmp trunc(C)
diff --git a/validation/optim/cmpu-and0.c b/validation/optim/cmpu-and0.c
index 253212941779..927b9fb65f52 100644
--- a/validation/optim/cmpu-and0.c
+++ b/validation/optim/cmpu-and0.c
@@ -11,7 +11,6 @@ int cmps_and_gtu_eq(int a) { return ((a & MASK) > (MASK + 0)) + 1; }
/*
* check-name: cmpu-and0
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/9] simplify (x & M) cmps 0
2021-03-10 21:49 [PATCH 0/9] simplify CMP(AND(x,M), C) and CMP(OR(x,M), C) Luc Van Oostenryck
` (3 preceding siblings ...)
2021-03-10 21:49 ` [PATCH 4/9] simplify (x & M) cmpu C Luc Van Oostenryck
@ 2021-03-10 21:49 ` Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 6/9] simplify (x & M) {==,!=} C Luc Van Oostenryck
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2021-03-10 21:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 4 ++++
validation/optim/cmps0-and0.c | 1 -
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/simplify.c b/simplify.c
index ee29c9619bdc..6c11018ea3bf 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1271,6 +1271,8 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
return replace_with_value(insn, 0);
if (value >= (long long)bits)
return replace_with_value(insn, 1);
+ if (value == 0)
+ return replace_opcode(insn, OP_SET_EQ);
break;
case OP_SET_GT:
value = sign_extend(value, def->size);
@@ -1280,6 +1282,8 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
return replace_with_value(insn, 1);
if (value >= (long long)bits)
return replace_with_value(insn, 0);
+ if (value == 0)
+ return replace_opcode(insn, OP_SET_NE);
break;
case OP_SET_B:
if (value > bits)
diff --git a/validation/optim/cmps0-and0.c b/validation/optim/cmps0-and0.c
index 819a1dc2a793..8316916abc8c 100644
--- a/validation/optim/cmps0-and0.c
+++ b/validation/optim/cmps0-and0.c
@@ -6,7 +6,6 @@ int cmps_and_sgt0(int a) { return ((a & M) > 0) == ((a & M) != 0); }
/*
* check-name: cmps0-and
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6/9] simplify (x & M) {==,!=} C
2021-03-10 21:49 [PATCH 0/9] simplify CMP(AND(x,M), C) and CMP(OR(x,M), C) Luc Van Oostenryck
` (4 preceding siblings ...)
2021-03-10 21:49 ` [PATCH 5/9] simplify (x & M) cmps 0 Luc Van Oostenryck
@ 2021-03-10 21:49 ` Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 7/9] simplify (x | " Luc Van Oostenryck
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2021-03-10 21:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 8 ++++++++
validation/optim/cmpe-and0.c | 1 -
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/simplify.c b/simplify.c
index 6c11018ea3bf..b46e08c3b79a 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1263,6 +1263,14 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
break;
bits = def->src2->value;
switch (insn->opcode) {
+ case OP_SET_EQ:
+ if ((value & bits) != value)
+ return replace_with_value(insn, 0);
+ break;
+ case OP_SET_NE:
+ if ((value & bits) != value)
+ return replace_with_value(insn, 1);
+ break;
case OP_SET_LE:
value = sign_extend(value, def->size);
if (bits & sign_bit(def->size))
diff --git a/validation/optim/cmpe-and0.c b/validation/optim/cmpe-and0.c
index 7db608365568..75af77528f61 100644
--- a/validation/optim/cmpe-and0.c
+++ b/validation/optim/cmpe-and0.c
@@ -4,7 +4,6 @@ int cmpe_and_ne(int a) { return ((a & 0xff00) != 0xff01) + 0; }
/*
* check-name: cmpe-and0
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 7/9] simplify (x | M) {==,!=} C
2021-03-10 21:49 [PATCH 0/9] simplify CMP(AND(x,M), C) and CMP(OR(x,M), C) Luc Van Oostenryck
` (5 preceding siblings ...)
2021-03-10 21:49 ` [PATCH 6/9] simplify (x & M) {==,!=} C Luc Van Oostenryck
@ 2021-03-10 21:49 ` Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 8/9] simplify (x | M) cmps C Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 9/9] simplify (x | M) cmpu C Luc Van Oostenryck
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2021-03-10 21:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 15 +++++++++++++++
validation/optim/cmpe-or0.c | 1 -
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/simplify.c b/simplify.c
index b46e08c3b79a..865fadfb590e 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1311,6 +1311,21 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
break;
}
break;
+ case OP_OR:
+ if (!constant(def->src2))
+ break;
+ bits = def->src2->value;
+ switch (insn->opcode) {
+ case OP_SET_EQ:
+ if ((value & bits) != bits)
+ return replace_with_value(insn, 0);
+ break;
+ case OP_SET_NE:
+ if ((value & bits) != bits)
+ return replace_with_value(insn, 1);
+ break;
+ }
+ break;
case OP_SEXT: // sext(x) cmp C --> x cmp trunc(C)
osize = def->orig_type->bit_size;
if (is_signed_constant(value, osize, size)) {
diff --git a/validation/optim/cmpe-or0.c b/validation/optim/cmpe-or0.c
index bef2316120f7..2e89d611117d 100644
--- a/validation/optim/cmpe-or0.c
+++ b/validation/optim/cmpe-or0.c
@@ -4,7 +4,6 @@ int cmp_ne(int a) { return ((a | 1) == 0) + 1; }
/*
* check-name: cmpe-or0
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 8/9] simplify (x | M) cmps C
2021-03-10 21:49 [PATCH 0/9] simplify CMP(AND(x,M), C) and CMP(OR(x,M), C) Luc Van Oostenryck
` (6 preceding siblings ...)
2021-03-10 21:49 ` [PATCH 7/9] simplify (x | " Luc Van Oostenryck
@ 2021-03-10 21:49 ` Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 9/9] simplify (x | M) cmpu C Luc Van Oostenryck
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2021-03-10 21:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 14 ++++++++++++++
validation/optim/cmps-or0.c | 1 -
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/simplify.c b/simplify.c
index 865fadfb590e..e721f9f860a0 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1324,6 +1324,20 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
if ((value & bits) != bits)
return replace_with_value(insn, 1);
break;
+ case OP_SET_LE:
+ value = sign_extend(value, def->size);
+ if (bits & sign_bit(def->size)) {
+ if (value >= -1)
+ return replace_with_value(insn, 1);
+ }
+ break;
+ case OP_SET_GT:
+ value = sign_extend(value, def->size);
+ if (bits & sign_bit(def->size)) {
+ if (value >= -1)
+ return replace_with_value(insn, 0);
+ }
+ break;
}
break;
case OP_SEXT: // sext(x) cmp C --> x cmp trunc(C)
diff --git a/validation/optim/cmps-or0.c b/validation/optim/cmps-or0.c
index 40a2092c58a4..70fcb024a846 100644
--- a/validation/optim/cmps-or0.c
+++ b/validation/optim/cmps-or0.c
@@ -15,7 +15,6 @@ int cmps_ior_gt_0(int a) { return ((a | MASK) > 0) EQ(0); }
/*
* check-name: cmps-or0
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 9/9] simplify (x | M) cmpu C
2021-03-10 21:49 [PATCH 0/9] simplify CMP(AND(x,M), C) and CMP(OR(x,M), C) Luc Van Oostenryck
` (7 preceding siblings ...)
2021-03-10 21:49 ` [PATCH 8/9] simplify (x | M) cmps C Luc Van Oostenryck
@ 2021-03-10 21:49 ` Luc Van Oostenryck
8 siblings, 0 replies; 10+ messages in thread
From: Luc Van Oostenryck @ 2021-03-10 21:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 16 ++++++++++++++++
validation/optim/cmpu-or0.c | 1 -
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/simplify.c b/simplify.c
index e721f9f860a0..9e3514d838a9 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1324,6 +1324,22 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
if ((value & bits) != bits)
return replace_with_value(insn, 1);
break;
+ case OP_SET_B:
+ if (bits >= value)
+ return replace_with_value(insn, 0);
+ break;
+ case OP_SET_BE:
+ if (bits > value)
+ return replace_with_value(insn, 0);
+ break;
+ case OP_SET_AE:
+ if (bits > value)
+ return replace_with_value(insn, 1);
+ break;
+ case OP_SET_A:
+ if (bits >= value)
+ return replace_with_value(insn, 1);
+ break;
case OP_SET_LE:
value = sign_extend(value, def->size);
if (bits & sign_bit(def->size)) {
diff --git a/validation/optim/cmpu-or0.c b/validation/optim/cmpu-or0.c
index 77360d3feb0f..e97e91809461 100644
--- a/validation/optim/cmpu-or0.c
+++ b/validation/optim/cmpu-or0.c
@@ -12,7 +12,6 @@ int cmpu_ior_gt_lt(int a) { return ((a | MASK) > (MASK - 1)) EQ(1); }
/*
* check-name: cmpu-or0
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-03-10 22:11 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10 21:49 [PATCH 0/9] simplify CMP(AND(x,M), C) and CMP(OR(x,M), C) Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 1/9] change testing of signed compares against SMIN or SMAX Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 2/9] add testcases for constant compares against AND/OR Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 3/9] simplify (x & M) cmps C Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 4/9] simplify (x & M) cmpu C Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 5/9] simplify (x & M) cmps 0 Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 6/9] simplify (x & M) {==,!=} C Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 7/9] simplify (x | " Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 8/9] simplify (x | M) cmps C Luc Van Oostenryck
2021-03-10 21:49 ` [PATCH 9/9] simplify (x | M) cmpu C Luc Van Oostenryck
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).