Skip to content

Commit 7c47a67

Browse files
mcfimeta-codesync[bot]
authored andcommitted
Peep andbi/movzbq and movtqb/andbi
Summary: Two peeps: ``` 1. movtqb{s, tmp}; andbi{imm, tmp, d} --> copy{s, tmp}; andbi{imm, tmp, d}. 2. andbi{imm, s, tmp}; movzbq{tmp, d} --> andbi{imm, s, tmp}; copy{tmp, d}. ``` If tmp == d, the copy vasm will be eliminated. Reviewed By: ottoni Differential Revision: D92644063 fbshipit-source-id: 3fa9643eaa90b18fcdd373747e9903bac94e5b75
1 parent e52bd7f commit 7c47a67

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

hphp/runtime/vm/jit/vasm-simplify-arm.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,44 @@ bool simplify(Env& env, const ldimmq& inst, Vlabel b, size_t i) {
196196
bool simplify(Env& env, const movtqb& inst, Vlabel b, size_t i) {
197197
if (env.use_counts[inst.d] != 1) return false;
198198

199-
if (if_inst<Vinstr::movzbq>(env, b, i + 1, [&](const movzbq& ext) {
199+
// movtqb{s, tmp}; movzbq{tmp, d} --> movzbq{s, d}
200+
bool simplified = if_inst<Vinstr::movzbq>(env, b, i + 1, [&](const movzbq& ext) {
200201
if (ext.s != inst.d) return false;
201202

202203
return simplify_impl(env, b, i, [&] (Vout& v) {
203204
v << movzbq{Vreg8((Vreg)inst.s), ext.d};
204205
return 2;
205206
});
206-
})) {
207+
});
208+
209+
if (simplified) return true;
210+
211+
// movtqb{s, tmp}; andbi{imm, tmp, d} --> copy{s, tmp}; andbi{imm, tmp, d}
212+
// the copy vasm could be a nop if tmp == d
213+
return if_inst<Vinstr::andbi>(env, b, i + 1, [&](const andbi& vandbi) {
214+
if (vandbi.s1 != inst.d) return false;
215+
216+
return simplify_impl(env, b, i, [&] (Vout& v) {
217+
v << copy{Vreg8((Vreg)inst.s), vandbi.s1};
218+
return 1;
219+
});
220+
});
221+
}
222+
223+
bool simplify(Env& env, const movzbq& inst, Vlabel b, size_t i) {
224+
auto const def_op = env.def_insts[inst.s];
225+
226+
// Check if `inst.s' was defined by an andbi instruction, which
227+
// automatically clears the high bits.
228+
if (def_op != Vinstr::andbi) {
229+
return false;
207230
}
208-
return false;
231+
232+
// If so, the movzbq{} is redundant
233+
return simplify_impl(env, b, i, [&] (Vout& v) {
234+
v << copy{inst.s, inst.d};
235+
return 1;
236+
});
209237
}
210238

211239
bool simplify(Env& env, const movzbl& inst, Vlabel b, size_t i) {

0 commit comments

Comments
 (0)