@@ -1148,6 +1148,20 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
insn->src2 = value_pseudo(zero_extend(value, osize));
return replace_pseudo(insn, &insn->src1, def->src);
}
+ switch (insn->opcode) {
+ case OP_SET_LT: case OP_SET_LE:
+ if (value >= sign_bit(osize))
+ 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))
+ return replace_with_value(insn, 0);
+ else
+ return replace_with_value(insn, 1);
+ break;
+ }
break;
case OP_ZEXT:
osize = def->orig_type->bit_size;
@@ -23,7 +23,6 @@ static int ge_lt1(int x) { return (sext(x) >= (NEG - 1)) == 0; }
/*
* check-name: cmp-sext-simm
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
A signed compare of a sign-extended value against a constant outside of the original range is statically known. Simplify to the corresponding 0/1. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- simplify.c | 14 ++++++++++++++ validation/optim/cmp-sext-simm.c | 1 - 2 files changed, 14 insertions(+), 1 deletion(-)