diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-01-05 00:01:08 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-01-26 22:49:11 +0100 |
commit | b5a4f039a159ade2f01af7b10cd7615cbc42ba35 (patch) | |
tree | 3cf080491c66dd46fa5dba538772d746e17fac52 | |
parent | 5db6d62e83623808fc29f6a6da636ddf5c658110 (diff) | |
download | sparse-b5a4f039a159ade2f01af7b10cd7615cbc42ba35.tar.gz |
cmps: simplify signed compares with SMIN or SMAX
Simplify away signed compares with SMIN or SMAX which can be
statically be determined to be always true or always false.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 17 | ||||
-rw-r--r-- | validation/optim/cmps-minmax.c | 1 |
2 files changed, 17 insertions, 1 deletions
@@ -1170,6 +1170,23 @@ static int simplify_compare_constant(struct instruction *insn, long long value) int changed = 0; switch (insn->opcode) { + case OP_SET_LT: + if (value == sign_bit(size)) // (x < SMIN) --> 0 + return replace_with_pseudo(insn, value_pseudo(0)); + break; + case OP_SET_LE: + if (value == sign_mask(size)) // (x <= SMAX) --> 1 + return replace_with_pseudo(insn, value_pseudo(1)); + break; + case OP_SET_GE: + if (value == sign_bit(size)) // (x >= SMIN) --> 1 + return replace_with_pseudo(insn, value_pseudo(1)); + break; + case OP_SET_GT: + if (value == sign_mask(size)) // (x > SMAX) --> 0 + return replace_with_pseudo(insn, value_pseudo(0)); + break; + case OP_SET_B: if (!value) // (x < 0) --> 0 return replace_with_pseudo(insn, value_pseudo(0)); diff --git a/validation/optim/cmps-minmax.c b/validation/optim/cmps-minmax.c index ded3286c..5802cdbc 100644 --- a/validation/optim/cmps-minmax.c +++ b/validation/optim/cmps-minmax.c @@ -10,7 +10,6 @@ int gt_smax(int a) { return (a > SMAX) == 0; } /* * check-name: cmps-minmax * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 |