aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--simplify.c40
-rw-r--r--validation/optim/fact-select01.c1
2 files changed, 40 insertions, 1 deletions
diff --git a/simplify.c b/simplify.c
index 89a064b9..d729b390 100644
--- a/simplify.c
+++ b/simplify.c
@@ -554,6 +554,16 @@ static inline int swap_insn(struct instruction *out, struct instruction *in, pse
return replace_insn_pair(out, in->opcode, in, out->opcode, a, b, c);
}
+///
+// create an instruction pair OUT(SELECT(a, b, c), d)
+static int swap_select(struct instruction *out, struct instruction *in, pseudo_t a, pseudo_t b, pseudo_t c, pseudo_t d)
+{
+ use_pseudo(in, c, &in->src3);
+ swap_insn(out, in, a, b, d);
+ kill_use(&out->src3);
+ return REPEAT_CSE;
+}
+
static inline int def_opcode(pseudo_t p)
{
if (p->type != PSEUDO_REG)
@@ -2254,6 +2264,36 @@ static int simplify_select(struct instruction *insn)
}
break;
}
+
+ switch (DEF_OPCODE(def, src1)) {
+ case OP_ADD: case OP_OR: case OP_XOR:
+ if ((def->src1 == src2) && can_move_to(cond, def)) {
+ // SEL(x, OP(y,z), y) --> OP(SEL(x, z, 0), y)
+ swap_select(insn, def, cond, def->src2, value_pseudo(0), src2);
+ return REPEAT_CSE;
+ }
+ if ((def->src2 == src2) && can_move_to(cond, def)) {
+ // SEL(x, OP(z,y), y) --> OP(SEL(x, z, 0), y)
+ swap_select(insn, def, cond, def->src1, value_pseudo(0), src2);
+ return REPEAT_CSE;
+ }
+ break;
+ }
+
+ switch (DEF_OPCODE(def, src2)) {
+ case OP_ADD: case OP_OR: case OP_XOR:
+ if ((def->src1 == src1) && can_move_to(cond, def)) {
+ // SEL(x, y, OP(y,z)) --> OP(SEL(x, 0, z), y)
+ swap_select(insn, def, cond, value_pseudo(0), def->src2, src1);
+ return REPEAT_CSE;
+ }
+ if ((def->src2 == src1) && can_move_to(cond, def)) {
+ // SEL(x, y, OP(z,y)) --> OP(SEL(x, 0, z), y)
+ swap_select(insn, def, cond, value_pseudo(0), def->src1, src1);
+ return REPEAT_CSE;
+ }
+ break;
+ }
return 0;
}
diff --git a/validation/optim/fact-select01.c b/validation/optim/fact-select01.c
index ef4e5e89..9232fc90 100644
--- a/validation/optim/fact-select01.c
+++ b/validation/optim/fact-select01.c
@@ -19,7 +19,6 @@ int xor_y_yx(int p, int x, int y) { return (p ? y : (y^x)) == ((p ? 0 : x) ^ y);
/*
* check-name: fact-select01
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1