@@ -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:
@@ -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
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> --- simplify.c | 8 ++++++++ validation/optim/canonical-cmps-minmax.c | 1 - 2 files changed, 8 insertions(+), 1 deletion(-)