@@ -1754,6 +1754,15 @@ static int simplify_and_one_side(struct instruction *insn, pseudo_t *p1, pseudo_
}
}
break;
+ case OP_SHL: case OP_LSR: case OP_ASR:
+ if (DEF_OPCODE(defr, *p2) == def->opcode && defr->src2 == def->src2) {
+ if (can_move_to(def->src1, defr)) {
+ // SHIFT(x, s) & SHIFT(y, s) --> SHIFT((x & y), s)
+ swap_insn(insn, defr, def->src1, defr->src1, def->src2);
+ return REPEAT_CSE;
+ }
+ }
+ break;
}
return 0;
}
@@ -1799,6 +1808,15 @@ static int simplify_ior_one_side(struct instruction *insn, pseudo_t *p1, pseudo_
return replace_with_value(insn, 1);
}
break;
+ case OP_SHL: case OP_LSR: case OP_ASR:
+ if (DEF_OPCODE(defr, *p2) == def->opcode && defr->src2 == def->src2) {
+ if (can_move_to(def->src1, defr)) {
+ // SHIFT(x, s) | SHIFT(y, s) --> SHIFT((x | y), s)
+ swap_insn(insn, defr, def->src1, defr->src1, def->src2);
+ return REPEAT_CSE;
+ }
+ }
+ break;
}
return 0;
}
@@ -1844,6 +1862,15 @@ static int simplify_xor_one_side(struct instruction *insn, pseudo_t *p1, pseudo_
return replace_with_value(insn, 1);
}
break;
+ case OP_SHL: case OP_LSR: case OP_ASR:
+ if (DEF_OPCODE(defr, *p2) == def->opcode && defr->src2 == def->src2) {
+ if (can_move_to(def->src1, defr)) {
+ // SHIFT(x, s) ^ SHIFT(y, s) --> SHIFT((x ^ y), s)
+ swap_insn(insn, defr, def->src1, defr->src1, def->src2);
+ return REPEAT_CSE;
+ }
+ }
+ break;
}
return 0;
}
@@ -20,7 +20,6 @@ sint fact_and_asr(sint a, sint b, sint s)
/*
* check-name: fact-and-shift
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
@@ -20,7 +20,6 @@ sint fact_ior_asr(sint a, sint b, sint s)
/*
* check-name: fact-ior-shift
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
@@ -20,7 +20,6 @@ sint fact_xor_asr(sint a, sint b, sint s)
/*
* check-name: fact-xor-shift
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1
Factorize bitwise OPs of shifts with identical counts. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- simplify.c | 27 +++++++++++++++++++++++++++ validation/optim/fact-and-shift.c | 1 - validation/optim/fact-ior-shift.c | 1 - validation/optim/fact-xor-shift.c | 1 - 4 files changed, 27 insertions(+), 3 deletions(-)