Skip to content

Commit f359a43

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm, compiler] Improve TestImmediate on RISC-V for higher single-bit tests.
Shifting the interesting bit to the sign bit is shorter than loading a large immediate. TEST=ci Change-Id: Ibd3dadf3885b554643e4606e8cbf83fcc6ba3d30 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392463 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Alexander Aprelev <[email protected]>
1 parent e65b892 commit f359a43

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

runtime/vm/compiler/assembler/assembler_riscv.cc

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,10 +2853,34 @@ void Assembler::BranchIf(Condition condition,
28532853
UNREACHABLE();
28542854
}
28552855
} else if (deferred_compare_ == kTestImm || deferred_compare_ == kTestReg) {
2856-
if (deferred_compare_ == kTestImm) {
2857-
AndImmediate(TMP2, deferred_left_, deferred_imm_);
2858-
} else {
2856+
uintx_t uimm = deferred_imm_;
2857+
if (deferred_compare_ == kTestReg) {
28592858
and_(TMP2, deferred_left_, deferred_reg_);
2859+
} else if (IsITypeImm(deferred_imm_)) {
2860+
andi(TMP2, deferred_left_, deferred_imm_);
2861+
} else if (Utils::IsPowerOfTwo(uimm)) {
2862+
intptr_t shift = Utils::ShiftForPowerOfTwo(uimm);
2863+
Register sign;
2864+
if (shift == XLEN - 1) {
2865+
sign = deferred_left_;
2866+
} else {
2867+
slli(TMP2, deferred_left_, XLEN - 1 - shift);
2868+
sign = TMP2;
2869+
}
2870+
switch (condition) {
2871+
case ZERO:
2872+
bgez(sign, label, distance);
2873+
break;
2874+
case NOT_ZERO:
2875+
bltz(sign, label, distance);
2876+
break;
2877+
default:
2878+
UNREACHABLE();
2879+
}
2880+
deferred_compare_ = kNone; // Consumed.
2881+
return;
2882+
} else {
2883+
AndImmediate(TMP2, deferred_left_, deferred_imm_);
28602884
}
28612885
switch (condition) {
28622886
case ZERO:

0 commit comments

Comments
 (0)