diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-01-06 22:43:42 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-01-26 22:49:11 +0100 |
commit | 33fda43cf26ce3e312e6cb4882821117b68056a2 (patch) | |
tree | fe46bd4a7aa2e6d42d1f920872ca6aa8e25442c7 | |
parent | 1cac46932aa290e4192ed178a26b0da6486d8cd3 (diff) | |
download | sparse-33fda43cf26ce3e312e6cb4882821117b68056a2.tar.gz |
cmps: fix simplification of sext(x) + signed compare of {SMAX,SMIN}
Commit a1c1b9236d5d ("cmp: simplify sext(x) cmps {SMAX,SMIN}")
had a double error (wrong size and wrong compare direction) which
was hidden because of too narrow testcases.
So, fix the simplification and extend the testcases.
Fixes: a1c1b9236d5d4af1681a45ced26f8350bd7721c2
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 4 | ||||
-rw-r--r-- | validation/optim/cmp-sext-simm.c | 46 |
2 files changed, 37 insertions, 13 deletions
@@ -1239,13 +1239,13 @@ static int simplify_compare_constant(struct instruction *insn, long long value) } break; case OP_SET_LT: case OP_SET_LE: - if (value >= sign_bit(osize)) + if (value < sign_bit(size)) return replace_with_value(insn, 1); else return replace_with_value(insn, 0); break; case OP_SET_GE: case OP_SET_GT: - if (value >= sign_bit(osize)) + if (value < sign_bit(size)) return replace_with_value(insn, 0); else return replace_with_value(insn, 1); diff --git a/validation/optim/cmp-sext-simm.c b/validation/optim/cmp-sext-simm.c index a8b2a8f9..57a4df1d 100644 --- a/validation/optim/cmp-sext-simm.c +++ b/validation/optim/cmp-sext-simm.c @@ -4,21 +4,45 @@ static int lt_ge0(int x) { return (sext(x) < (POS + 0)) == 1; } static int lt_ge1(int x) { return (sext(x) < (POS + 1)) == 1; } +static int lt_ge2(int x) { return (sext(x) < (POS + 2)) == 1; } +static int lt_gex(int x) { return (sext(x) < (POS<< 1)) == 1; } +static int lt_gey(int x) { return (sext(x) < (POS<< 3)) == 1; } static int le_ge0(int x) { return (sext(x) <= (POS + 0)) == 1; } static int le_ge1(int x) { return (sext(x) <= (POS + 1)) == 1; } -static int lt_lt0(int x) { return (sext(x) < (NEG - 0)) == 1; } -static int lt_lt1(int x) { return (sext(x) < (NEG - 1)) == 1; } -static int le_lt0(int x) { return (sext(x) <= (NEG - 0)) == 1; } -static int le_lt1(int x) { return (sext(x) <= (NEG - 1)) == 1; } - -static int gt_ge0(int x) { return (sext(x) > (POS + 0)) == 0; } -static int gt_ge1(int x) { return (sext(x) > (POS + 1)) == 0; } +static int le_ge2(int x) { return (sext(x) <= (POS + 2)) == 1; } +static int le_gex(int x) { return (sext(x) <= (POS<< 1)) == 1; } +static int le_gey(int x) { return (sext(x) <= (POS<< 3)) == 1; } static int ge_ge0(int x) { return (sext(x) >= (POS + 0)) == 0; } static int ge_ge1(int x) { return (sext(x) >= (POS + 1)) == 0; } -static int gt_lt0(int x) { return (sext(x) > (NEG - 0)) == 0; } -static int gt_lt1(int x) { return (sext(x) > (NEG - 1)) == 0; } -static int ge_lt0(int x) { return (sext(x) >= (NEG - 0)) == 0; } -static int ge_lt1(int x) { return (sext(x) >= (NEG - 1)) == 0; } +static int ge_ge2(int x) { return (sext(x) >= (POS + 2)) == 0; } +static int ge_gex(int x) { return (sext(x) >= (POS<< 1)) == 0; } +static int ge_gey(int x) { return (sext(x) >= (POS<< 3)) == 0; } +static int gt_ge0(int x) { return (sext(x) > (POS + 0)) == 0; } +static int gt_ge1(int x) { return (sext(x) > (POS + 1)) == 0; } +static int gt_ge2(int x) { return (sext(x) > (POS + 2)) == 0; } +static int gt_gex(int x) { return (sext(x) > (POS<< 1)) == 0; } +static int gt_gey(int x) { return (sext(x) > (POS<< 3)) == 0; } + +static int lt_lt0(int x) { return (sext(x) < (NEG - 0)) == 0; } +static int lt_lt1(int x) { return (sext(x) < (NEG - 1)) == 0; } +static int lt_lt2(int x) { return (sext(x) < (NEG - 2)) == 0; } +static int lt_ltx(int x) { return (sext(x) < (NEG<< 1)) == 0; } +static int lt_lty(int x) { return (sext(x) < (NEG<< 3)) == 0; } +static int le_lt0(int x) { return (sext(x) <= (NEG - 0)) == 0; } +static int le_lt1(int x) { return (sext(x) <= (NEG - 1)) == 0; } +static int le_lt2(int x) { return (sext(x) <= (NEG - 2)) == 0; } +static int le_ltx(int x) { return (sext(x) <= (NEG<< 1)) == 0; } +static int le_lty(int x) { return (sext(x) <= (NEG<< 3)) == 0; } +static int ge_lt0(int x) { return (sext(x) >= (NEG - 0)) == 1; } +static int ge_lt1(int x) { return (sext(x) >= (NEG - 1)) == 1; } +static int ge_lt2(int x) { return (sext(x) >= (NEG - 2)) == 1; } +static int ge_ltx(int x) { return (sext(x) >= (NEG<< 1)) == 1; } +static int ge_lty(int x) { return (sext(x) >= (NEG<< 3)) == 1; } +static int gt_lt0(int x) { return (sext(x) > (NEG - 0)) == 1; } +static int gt_lt1(int x) { return (sext(x) > (NEG - 1)) == 1; } +static int gt_lt2(int x) { return (sext(x) > (NEG - 2)) == 1; } +static int gt_ltx(int x) { return (sext(x) > (NEG<< 1)) == 1; } +static int gt_lty(int x) { return (sext(x) > (NEG<< 3)) == 1; } /* * check-name: cmp-sext-simm |