diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-25 16:05:42 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-08 02:15:20 +0100 |
commit | 4a5f616407e26efb67013f8267adef2d6e093bf1 (patch) | |
tree | 65c15a2c9c3920e5473215fb3967892a1a5ec196 | |
parent | a1c1b9236d5d4af1681a45ced26f8350bd7721c2 (diff) | |
download | sparse-4a5f616407e26efb67013f8267adef2d6e093bf1.tar.gz |
cmp: canonicalize sext(x) cmpu C (with C >= SMAX)
A unsigned compare of a sign-extended value against a value
bigger than the original SMAX is equivalent to a signed
compare against 0.
Canonicalize to the signed compare against 0.
Note: ultimately both forms are just a test of the sign bit.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 12 | ||||
-rw-r--r-- | validation/optim/cmp-sext-uimm.c | 1 |
2 files changed, 12 insertions, 1 deletions
@@ -1149,6 +1149,18 @@ static int simplify_compare_constant(struct instruction *insn, long long value) return replace_pseudo(insn, &insn->src1, def->src); } switch (insn->opcode) { + case OP_SET_BE: + if (value >= sign_bit(osize)) { + replace_binop_value(insn, OP_SET_GE, 0); + return replace_pseudo(insn, &insn->src1, def->src); + } + break; + case OP_SET_A: + if (value >= sign_bit(osize)) { + replace_binop_value(insn, OP_SET_LT, 0); + return replace_pseudo(insn, &insn->src1, def->src); + } + break; case OP_SET_LT: case OP_SET_LE: if (value >= sign_bit(osize)) return replace_with_value(insn, 1); diff --git a/validation/optim/cmp-sext-uimm.c b/validation/optim/cmp-sext-uimm.c index cc89a806..05da042f 100644 --- a/validation/optim/cmp-sext-uimm.c +++ b/validation/optim/cmp-sext-uimm.c @@ -19,7 +19,6 @@ int sext_gtu_m3(int x) { return (sext(x) > (NEG - 3)) == (x < 0); } /* * check-name: cmp-sext-uimm * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 |