diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-31 17:20:36 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-07 22:53:05 +0100 |
commit | 467fce3048571227e49beee068f783fb1c76a1e7 (patch) | |
tree | f00a14248b0c6dd4066149efba9454b7f724144f | |
parent | c25293e689b0b408c6228676536e928e4f042dfe (diff) | |
download | sparse-467fce3048571227e49beee068f783fb1c76a1e7.tar.gz |
simplify SEL(x == y, x, y) and friends
If the condition of a select instruction is a equality test of the
select's operands, then the result of the select is always the same as
its second operand. Same for the first operand with an inequality test.
Simplify away these selects.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 12 | ||||
-rw-r--r-- | validation/optim/eqne-select.c | 12 |
2 files changed, 24 insertions, 0 deletions
@@ -1783,6 +1783,18 @@ static int simplify_select(struct instruction *insn) } switch (DEF_OPCODE(def, cond)) { + case OP_SET_EQ: + if (src1 == def->src1 && src2 == def->src2) + return replace_with_pseudo(insn, src2); // SEL(x==y,x,y) --> y + if (src2 == def->src1 && src1 == def->src2) + return replace_with_pseudo(insn, src2); // SEL(y==x,x,y) --> y + break; + case OP_SET_NE: + if (src1 == def->src1 && src2 == def->src2) + return replace_with_pseudo(insn, src1); // SEL(x!=y,x,y) --> x + if (src2 == def->src1 && src1 == def->src2) + return replace_with_pseudo(insn, src1); // SEL(y!=x,x,y) --> x + break; case OP_SEL: if (constant(def->src2) && constant(def->src3)) { // Is the def of the conditional another select? diff --git a/validation/optim/eqne-select.c b/validation/optim/eqne-select.c new file mode 100644 index 00000000..9dfd88b5 --- /dev/null +++ b/validation/optim/eqne-select.c @@ -0,0 +1,12 @@ +int sel_eq01(int a, int b) { return ((a == b) ? a : b) == b; } +int sel_eq10(int a, int b) { return ((a == b) ? b : a) == a; } +int sel_ne01(int a, int b) { return ((a != b) ? a : b) == a; } +int sel_ne10(int a, int b) { return ((a != b) ? b : a) == b; } + +/* + * check-name: eqne-select + * check-command: test-linearize -Wno-decl $file + * + * check-output-ignore + * check-output-returns: 1 + */ |