aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2021-01-13 00:49:16 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2021-01-26 22:49:11 +0100
commit7b1d4ca6b5ad28ccf8e489c58fe99c00b1436bfb (patch)
tree50474efa41db1a8605b07210dd361e1618d45145
parent61010b15b6074fcfee4256b848b1123a57d61947 (diff)
downloadsparse-7b1d4ca6b5ad28ccf8e489c58fe99c00b1436bfb.tar.gz
cmps: canonicalize SMIN/SMAX +- 1 --> EQ/NE
Compares with SMIN + 1 or SMAX - 1 are equivalent to an equality testing. For example, (x < SMIN + 1) is the same as (x == SMIN). Canonicalize these to the equality testing since these are usually simpler to handle. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c8
-rw-r--r--validation/optim/canonical-cmpe-minmax.c1
2 files changed, 8 insertions, 1 deletions
diff --git a/simplify.c b/simplify.c
index f7c6c68d..ad3adb11 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1175,24 +1175,32 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
return replace_with_pseudo(insn, value_pseudo(0));
if (value == sign_mask(size)) // (x < SMAX) --> (x != SMAX)
return replace_opcode(insn, OP_SET_NE);
+ if (value == sign_bit(size) + 1)// (x < SMIN + 1) --> (x == SMIN)
+ return replace_binop_value(insn, OP_SET_EQ, sign_bit(size));
break;
case OP_SET_LE:
if (value == sign_mask(size)) // (x <= SMAX) --> 1
return replace_with_pseudo(insn, value_pseudo(1));
if (value == sign_bit(size)) // (x <= SMIN) --> (x == SMIN)
return replace_opcode(insn, OP_SET_EQ);
+ if (value == sign_mask(size) - 1) // (x <= SMAX - 1) --> (x != SMAX)
+ return replace_binop_value(insn, OP_SET_NE, sign_mask(size));
break;
case OP_SET_GE:
if (value == sign_bit(size)) // (x >= SMIN) --> 1
return replace_with_pseudo(insn, value_pseudo(1));
if (value == sign_mask(size)) // (x >= SMAX) --> (x == SMAX)
return replace_opcode(insn, OP_SET_EQ);
+ if (value == sign_bit(size) + 1)// (x >= SMIN + 1) --> (x != SMIN)
+ return replace_binop_value(insn, OP_SET_NE, sign_bit(size));
break;
case OP_SET_GT:
if (value == sign_mask(size)) // (x > SMAX) --> 0
return replace_with_pseudo(insn, value_pseudo(0));
if (value == sign_bit(size)) // (x > SMIN) --> (x != SMIN)
return replace_opcode(insn, OP_SET_NE);
+ if (value == sign_mask(size) - 1) // (x > SMAX - 1) --> (x == SMAX)
+ return replace_binop_value(insn, OP_SET_EQ, sign_mask(size));
break;
case OP_SET_B:
diff --git a/validation/optim/canonical-cmpe-minmax.c b/validation/optim/canonical-cmpe-minmax.c
index c7281924..32b27243 100644
--- a/validation/optim/canonical-cmpe-minmax.c
+++ b/validation/optim/canonical-cmpe-minmax.c
@@ -10,7 +10,6 @@ int ge_smin(int a) { return (a >= (SMIN + 1)) == (a != SMIN); }
/*
* check-name: canonical-cmpe-minmax
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1