diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-01-22 23:56:05 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-01-26 22:49:11 +0100 |
commit | a5a61b2e345bac65ef1c256daeb7842539ab1262 (patch) | |
tree | a9b1c51e5d8f2a8e3cf2f33b3cf222ff1bd0d9b4 | |
parent | 54b6c78979c2a131a55c5439937e5e6bd8584b06 (diff) | |
download | sparse-a5a61b2e345bac65ef1c256daeb7842539ab1262.tar.gz |
cmps: canonicalize SEL(x {<,<=} y, a, b) --> SEL(x {>=,>} y, b, a)
Both compares and OP_SELECT are anti-symmetrical: swapping
the arguments is equivalent to inversing the condition.
As consequence, when combined, they're symmetrical:
swapping the arguments of the compare (or equivalently reversing
the direction of the compare) and swapping the operand of the
OP_SELECT is a no-op, both forms are equivalent.
So, canonicalize these to always use OP_GT or OP_GE.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 7 | ||||
-rw-r--r-- | validation/optim/canonical-cmps-sel.c | 1 |
2 files changed, 7 insertions, 1 deletions
@@ -2301,6 +2301,13 @@ static int simplify_select(struct instruction *insn) if (src2 == def->src1 && src1 == def->src2) return replace_with_pseudo(insn, src1); // SEL(y!=x,x,y) --> x break; + case OP_SET_LE: case OP_SET_LT: + case OP_SET_BE: case OP_SET_B: + if (!one_use(cond)) + break; + // SEL(x {<,<=} y, a, b) --> SEL(x {>=,>} y, b, a) + def->opcode = opcode_negate(def->opcode); + return switch_pseudo(insn, &insn->src2, insn, &insn->src3); case OP_SEL: if (constant(def->src2) && constant(def->src3)) { // Is the def of the conditional another select? diff --git a/validation/optim/canonical-cmps-sel.c b/validation/optim/canonical-cmps-sel.c index f0a0effc..bba5e5c8 100644 --- a/validation/optim/canonical-cmps-sel.c +++ b/validation/optim/canonical-cmps-sel.c @@ -19,7 +19,6 @@ _Bool sel_leu(unsigned int a, unsigned int b, int x, int y) /* * check-name: canonical-cmps-sel * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 |