Skip to content

Commit 62d1fc3

Browse files
committed
Aarch64: fold movsbq+shlqi into sbfizq
- add the sbfizq VASM opcode with ARM lowering - teach the ARM simplifier to replace movsbq+shlqi with sbfizq - mark the new instruction as pure for effects analysis
1 parent d1ed3e8 commit 62d1fc3

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ struct Vgen {
450450
void emit(const mrs& i) { a->Mrs(X(i.r), vixl::SystemRegister(i.s.l())); }
451451
void emit(const msr& i) { a->Msr(vixl::SystemRegister(i.s.l()), X(i.r)); }
452452
void emit(const ubfmli& i) { a->ubfm(W(i.d), W(i.s), i.mr.w(), i.ms.w()); }
453+
void emit(const sbfizq& i) { a->Sbfiz(X(i.d), X(i.s), i.shift.l(), i.width.l()); }
453454
void emit(const storepair& i) { a->Stp(X(i.s0), X(i.s1), M(i.d)); }
454455
void emit(const storepairl& i) { a->Stp(W(i.s0), W(i.s1), M(i.d)); }
455456
void emit(const loadpair& i) { a->Ldp(X(i.d0), X(i.d1), M(i.s)); }

hphp/runtime/vm/jit/vasm-info.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ bool effectsImpl(const Vinstr& inst, bool pure) {
247247
case Vinstr::sar:
248248
case Vinstr::sarq:
249249
case Vinstr::sarqi:
250+
case Vinstr::sbfizq:
250251
case Vinstr::setcc:
251252
case Vinstr::shl:
252253
case Vinstr::shr:

hphp/runtime/vm/jit/vasm-instr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ Width width(Vinstr::Opcode op) {
356356
case Vinstr::sarqi:
357357
case Vinstr::shlqi:
358358
case Vinstr::shrqi:
359+
case Vinstr::sbfizq:
359360
case Vinstr::subq:
360361
case Vinstr::subqi:
361362
case Vinstr::subqim:

hphp/runtime/vm/jit/vasm-instr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ struct Vunit;
362362
O(mrs, I(s), Un, D(r))\
363363
O(msr, I(s), U(r), Dn)\
364364
O(ubfmli, I(mr) I(ms), U(s), D(d))\
365+
O(sbfizq, I(shift) I(width), U(s), D(d))\
365366
O(loadpair, Inone, U(s), D(d0) D(d1))\
366367
O(loadpairl, Inone, U(s), D(d0) D(d1))\
367368
O(storepair, Inone, U(s0) U(s1) UW(d), Dn)\
@@ -1280,6 +1281,7 @@ struct fcvtzs { VregDbl s; Vreg64 d;};
12801281
struct mrs { Immed s; Vreg64 r; };
12811282
struct msr { Vreg64 r; Immed s; };
12821283
struct ubfmli { Immed mr, ms; Vreg32 s, d; };
1284+
struct sbfizq { Immed shift, width; Vreg64 s, d; };
12831285
struct loadpair { Vptr128 s; Vreg64 d0, d1; };
12841286
struct loadpairl { Vptr64 s; Vreg32 d0, d1; };
12851287
struct storepair { Vreg64 s0, s1; Vptr128 d; };

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,27 @@ bool simplify(Env& env, const movzbl& inst, Vlabel b, size_t i) {
152152

153153
///////////////////////////////////////////////////////////////////////////////
154154

155+
bool simplify(Env& env, const movsbq& inst, Vlabel b, size_t i) {
156+
// movsbq{s, tmp}; shlqi{imm, tmp, d} -> sbfizq{imm, 8, s, d}
157+
return if_inst<Vinstr::shlqi>(env, b, i + 1, [&] (const shlqi& sh) {
158+
if (inst.d != sh.s1) return false;
159+
if (env.use_counts[inst.d] != 1) return false;
160+
if (sh.fl) return false;
161+
if (sh.sf.isValid() && env.use_counts[sh.sf]) return false;
162+
163+
auto const shift = sh.s0.l();
164+
if (shift < 0 || shift > 56) return false;
165+
166+
return simplify_impl(env, b, i, [&] (Vout& v) {
167+
auto const src = Vreg64(Vreg(inst.s));
168+
v << sbfizq{sh.s0, Immed{8}, src, sh.d};
169+
return 2;
170+
});
171+
});
172+
}
173+
174+
///////////////////////////////////////////////////////////////////////////////
175+
155176
int is_adjacent_vptr64(const Vptr64& a, const Vptr64& b, int32_t step, int32_t min_disp, int32_t max_disp) {
156177
const int32_t min_disp_val = a.disp < b.disp ? a.disp : b.disp;
157178
if (a.base.isValid() && b.base.isValid() &&

0 commit comments

Comments
 (0)