Skip to content

Conversation

@david-arm
Copy link

We often see patterns like this:

shrqi 32, %v0, %v1
testl 0x80000000, %v1
jcc CC_E, ...

but really this is the same as asking if %v0 is >= 0. Rewriting this in the form

cmp 0, %v0
jcc CC_GE, ...

saves two instructions, i.e. a lsr and a mov.

We often see patterns like this:

shrqi 32, %v0, %v1
testl 0x80000000, %v1
jcc CC_E, ...

but really this is the same as asking if %v0 is >= 0. Rewriting
this in the form

cmp 0, %v0
jcc CC_GE, ...

saves two instructions, i.e. a lsr and a mov.
@meta-codesync
Copy link

meta-codesync bot commented Nov 7, 2025

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this in D86516135. (Because this pull request was imported automatically, there will not be any future comments.)

@meteorfox
Copy link

This fails to compile with

fbcode/hphp/runtime/vm/jit/vasm-simplify-arm.cpp:117:10: error: unused variable 'bit_num' [-Werror,-Wunused-variable]
  117 |     auto bit_num = folly::findLastSet<uint64_t>(Val) - 1;
      |          ^~~~~~~
fbcode/hphp/runtime/vm/jit/vasm-simplify-arm.cpp:99:19: error: cannot refer to type member 'Kind' in 'HPHP::jit::Vconst const' with '.'
   99 |   assert(op_const.Kind != Vconst::Double);
      |                   ^
fbcode/hphp/runtime/vm/jit/vasm-simplify-arm.cpp:113:10: note: in instantiation of function template specialization 'HPHP::jit::arm::(anonymous namespace)::get_const_int<HPHP::jit::Vr<HPHP::jit::Reg32>>' requested here
  113 |     if (!get_const_int(env, tstl.s0, Val) || folly::popcount(Val) != 1)
      |          ^
buck-out/v2/gen/fbcode/hphp/runtime/vm/__headers__/fc799a07123e9b1d/buck-headers/hphp/runtime/vm/jit/vasm-unit.h:96:8: note: member 'Kind' declared here
   96 |   enum Kind { Quad, Long, Byte, Double };
      |        ^
fbcode/hphp/runtime/vm/jit/vasm-simplify-arm.cpp:99:19: error: cannot refer to type member 'Kind' in 'HPHP::jit::Vconst const' with '.'
   99 |   assert(op_const.Kind != Vconst::Double);
      |                   ^
fbcode/hphp/runtime/vm/jit/vasm-simplify-arm.cpp:131:8: note: in instantiation of function template specialization 'HPHP::jit::arm::(anonymous namespace)::get_const_int<HPHP::jit::Vr<HPHP::jit::Reg64>>' requested here
  131 |   if (!get_const_int(env, inst.s0, Val) || Val != 0x8000000000000000ull)
      |        ^
buck-out/v2/gen/fbcode/hphp/runtime/vm/__headers__/fc799a07123e9b1d/buck-headers/hphp/runtime/vm/jit/vasm-unit.h:96:8: note: member 'Kind' declared here
   96 |   enum Kind { Quad, Long, Byte, Double };
      |        ^
3 errors generated.

@david-arm
Copy link
Author

This fails to compile with

fbcode/hphp/runtime/vm/jit/vasm-simplify-arm.cpp:117:10: error: unused variable 'bit_num' [-Werror,-Wunused-variable]
  117 |     auto bit_num = folly::findLastSet<uint64_t>(Val) - 1;
      |          ^~~~~~~
fbcode/hphp/runtime/vm/jit/vasm-simplify-arm.cpp:99:19: error: cannot refer to type member 'Kind' in 'HPHP::jit::Vconst const' with '.'
   99 |   assert(op_const.Kind != Vconst::Double);
      |                   ^
fbcode/hphp/runtime/vm/jit/vasm-simplify-arm.cpp:113:10: note: in instantiation of function template specialization 'HPHP::jit::arm::(anonymous namespace)::get_const_int<HPHP::jit::Vr<HPHP::jit::Reg32>>' requested here
  113 |     if (!get_const_int(env, tstl.s0, Val) || folly::popcount(Val) != 1)
      |          ^
buck-out/v2/gen/fbcode/hphp/runtime/vm/__headers__/fc799a07123e9b1d/buck-headers/hphp/runtime/vm/jit/vasm-unit.h:96:8: note: member 'Kind' declared here
   96 |   enum Kind { Quad, Long, Byte, Double };
      |        ^
fbcode/hphp/runtime/vm/jit/vasm-simplify-arm.cpp:99:19: error: cannot refer to type member 'Kind' in 'HPHP::jit::Vconst const' with '.'
   99 |   assert(op_const.Kind != Vconst::Double);
      |                   ^
fbcode/hphp/runtime/vm/jit/vasm-simplify-arm.cpp:131:8: note: in instantiation of function template specialization 'HPHP::jit::arm::(anonymous namespace)::get_const_int<HPHP::jit::Vr<HPHP::jit::Reg64>>' requested here
  131 |   if (!get_const_int(env, inst.s0, Val) || Val != 0x8000000000000000ull)
      |        ^
buck-out/v2/gen/fbcode/hphp/runtime/vm/__headers__/fc799a07123e9b1d/buck-headers/hphp/runtime/vm/jit/vasm-unit.h:96:8: note: member 'Kind' declared here
   96 |   enum Kind { Quad, Long, Byte, Double };
      |        ^
3 errors generated.

OK thanks I'll take a look! It seemed to pass for me downstream, so presumably I'm using a different build setup.

@david-arm
Copy link
Author

Yeah the assert(op_const.Kind != Vconst::Double); is really daft and it's weird my build didn't complain about it. Also, looks like we should be building with -Werror too.

@facebook-github-bot
Copy link
Contributor

@david-arm has updated the pull request. You must reimport the pull request before landing.

@meteorfox
Copy link

Thanks it builds and passes tests now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants