diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-01-06 00:16:08 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-01-26 22:49:11 +0100 |
commit | 61010b15b6074fcfee4256b848b1123a57d61947 (patch) | |
tree | 58b8cd23df3e6c78f80014fc613d9a5044e66424 | |
parent | b5a4f039a159ade2f01af7b10cd7615cbc42ba35 (diff) | |
download | sparse-61010b15b6074fcfee4256b848b1123a57d61947.tar.gz |
cmps: canonicalize signed compares with SMIN/SMAX
The remaining compares with SMIN or SMAX are equivalent to an
equality testing. For example, (x < SMAX) is the same as (x != SMAX).
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.c | 8 | ||||
-rw-r--r-- | validation/optim/canonical-cmps-minmax.c | 1 |
2 files changed, 8 insertions, 1 deletions
@@ -1173,18 +1173,26 @@ static int simplify_compare_constant(struct instruction *insn, long long value) case OP_SET_LT: if (value == sign_bit(size)) // (x < SMIN) --> 0 return replace_with_pseudo(insn, value_pseudo(0)); + if (value == sign_mask(size)) // (x < SMAX) --> (x != SMAX) + return replace_opcode(insn, OP_SET_NE); 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); 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); 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); break; case OP_SET_B: diff --git a/validation/optim/canonical-cmps-minmax.c b/validation/optim/canonical-cmps-minmax.c index bab09282..48927f49 100644 --- a/validation/optim/canonical-cmps-minmax.c +++ b/validation/optim/canonical-cmps-minmax.c @@ -10,7 +10,6 @@ int gt_smin(int a) { return (a > SMIN) == (a != SMIN); } /* * check-name: canonical-cmps-minmax * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 |