@@ -1081,18 +1081,24 @@ static int simplify_seteq_setne(struct instruction *insn, long long value)
static int simplify_compare_constant(struct instruction *insn, long long value)
{
+ int changed = 0;
+
switch (insn->opcode) {
case OP_SET_B:
if (!value) // (x < 0) --> 0
return replace_with_pseudo(insn, value_pseudo(0));
if (value == 1) // (x < 1) --> (x == 0)
return replace_binop_value(insn, OP_SET_EQ, 0);
+ else // (x < y) --> (x <= (y-1))
+ changed |= replace_binop_value(insn, OP_SET_BE, value - 1);
break;
case OP_SET_AE:
if (!value) // (x >= 0) --> 1
return replace_with_pseudo(insn, value_pseudo(1));
if (value == 1) // (x >= 1) --> (x != 0)
return replace_binop_value(insn, OP_SET_NE, 0);
+ else // (x >= y) --> (x > (y-1)
+ changed |= replace_binop_value(insn, OP_SET_A, value - 1);
break;
case OP_SET_BE:
if (!value) // (x <= 0) --> (x == 0)
@@ -1103,7 +1109,7 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
return replace_opcode(insn, OP_SET_NE);
break;
}
- return 0;
+ return changed;
}
static int simplify_constant_mask(struct instruction *insn, unsigned long long mask)
@@ -9,7 +9,6 @@ int cmp_geu(unsigned int x) { return (x >= 256) == (x > 255); }
/*
* check-name: canonical-cmpu
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
An unsigned comparison like (x < 3) is equivalent to (x <= 2). Canonicalize '<' & '>=' to '<=' & '>', such that the smallest constant is used. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- simplify.c | 8 +++++++- validation/optim/canonical-cmpu.c | 1 - 2 files changed, 7 insertions(+), 2 deletions(-)