Skip to content

Commit 7332811

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm, compiler] Add Location::MayBeSameAsInput.
`op x, x, y` is often shorter than `op z, x, y` in RISC-V because of the availablity of compressed instructions, but unconditionally using the two-address form requires extra moves when x is live after the instruction. dart2js.aot.rv64 19767848 -> 19751424 TEST=ci Change-Id: I92bf2a84fa91bb627e79853da94da51ee7924c34 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305600 Reviewed-by: Slava Egorov <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 91746d1 commit 7332811

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

runtime/vm/compiler/backend/flow_graph_compiler.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,7 @@ void FlowGraphCompiler::AllocateRegistersLocally(Instruction* instr) {
18341834
break;
18351835
case Location::kSameAsFirstInput:
18361836
case Location::kSameAsFirstOrSecondInput:
1837+
case Location::kMayBeSameAsFirstInput:
18371838
result_location = locs->in(0);
18381839
break;
18391840
case Location::kRequiresFpuRegister:

runtime/vm/compiler/backend/il_riscv.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,9 +3233,8 @@ LocationSummary* BinarySmiOpInstr::MakeLocationSummary(Zone* zone,
32333233
if (kNumTemps == 1) {
32343234
summary->set_temp(0, Location::RequiresRegister());
32353235
}
3236-
// We make use of 3-operand instructions by not requiring result register
3237-
// to be identical to first input register as on Intel.
3238-
summary->set_out(0, Location::RequiresRegister());
3236+
summary->set_out(0, CanDeoptimize() ? Location::RequiresRegister()
3237+
: Location::MayBeSameAsFirstInput());
32393238
return summary;
32403239
}
32413240

@@ -4340,9 +4339,8 @@ LocationSummary* UnarySmiOpInstr::MakeLocationSummary(Zone* zone,
43404339
LocationSummary* summary = new (zone)
43414340
LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall);
43424341
summary->set_in(0, Location::RequiresRegister());
4343-
// We make use of 3-operand instructions by not requiring result register
4344-
// to be identical to first input register as on Intel.
4345-
summary->set_out(0, Location::RequiresRegister());
4342+
summary->set_out(0, CanDeoptimize() ? Location::RequiresRegister()
4343+
: Location::MayBeSameAsFirstInput());
43464344
return summary;
43474345
}
43484346

@@ -5556,7 +5554,7 @@ LocationSummary* BinaryInt64OpInstr::MakeLocationSummary(Zone* zone,
55565554
zone, kNumInputs, kNumTemps, LocationSummary::kNoCall);
55575555
summary->set_in(0, Location::RequiresRegister());
55585556
summary->set_in(1, LocationRegisterOrConstant(right()));
5559-
summary->set_out(0, Location::RequiresRegister());
5557+
summary->set_out(0, Location::MayBeSameAsFirstInput());
55605558
return summary;
55615559
}
55625560
}
@@ -6171,7 +6169,7 @@ LocationSummary* UnaryInt64OpInstr::MakeLocationSummary(Zone* zone,
61716169
LocationSummary* summary = new (zone)
61726170
LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall);
61736171
summary->set_in(0, Location::RequiresRegister());
6174-
summary->set_out(0, Location::RequiresRegister());
6172+
summary->set_out(0, Location::MayBeSameAsFirstInput());
61756173
return summary;
61766174
#endif
61776175
}
@@ -6900,8 +6898,7 @@ void ConditionInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
69006898
<< kBoolValueBitPosition) == kTrueOffsetFromNull);
69016899
__ SetIf(InvertCondition(true_condition), result);
69026900
__ addi(result, result, kTrueOffsetFromNull >> kBoolValueBitPosition);
6903-
__ slli(result, result, kBoolValueBitPosition);
6904-
__ add(result, result, NULL_REG);
6901+
__ AddShifted(result, NULL_REG, result, kBoolValueBitPosition);
69056902
}
69066903
}
69076904

runtime/vm/compiler/backend/linearscan.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,16 @@ void FlowGraphAllocator::ProcessOneInstruction(BlockEntryInstr* block,
14871487
locs->set_out(0, Location::SameAsFirstInput());
14881488
}
14891489

1490+
if (locs->out(0).IsUnallocated() &&
1491+
(locs->out(0).policy() == Location::kMayBeSameAsFirstInput)) {
1492+
auto input_defn = current->InputAt(0)->definition();
1493+
if (IsDeadAfterCurrentInstruction(block, current, input_defn)) {
1494+
locs->set_out(0, Location::SameAsFirstInput());
1495+
} else {
1496+
locs->set_out(0, Location::RequiresRegister());
1497+
}
1498+
}
1499+
14901500
const bool output_same_as_first_input =
14911501
locs->out(0).IsUnallocated() &&
14921502
(locs->out(0).policy() == Location::kSameAsFirstInput);

runtime/vm/compiler/backend/locations.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ const char* Location::Name() const {
409409
return "0";
410410
case kSameAsFirstOrSecondInput:
411411
return "0|1";
412+
case kMayBeSameAsFirstInput:
413+
return "0?";
412414
case kRequiresStack:
413415
return "RS";
414416
}

runtime/vm/compiler/backend/locations.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ class Location : public ValueObject {
337337
kWritableRegister,
338338
kSameAsFirstInput,
339339
kSameAsFirstOrSecondInput,
340+
kMayBeSameAsFirstInput,
340341
// Forces the location to be spilled to the stack.
341342
// Currently only used for `Handle` arguments in `FfiCall` instructions.
342343
// Only available in optimized mode.
@@ -398,6 +399,12 @@ class Location : public ValueObject {
398399
return UnallocatedLocation(kSameAsFirstOrSecondInput);
399400
}
400401

402+
// Used for a three address instruction that can let its output be
403+
// the same as an input if convenient.
404+
static Location MayBeSameAsFirstInput() {
405+
return UnallocatedLocation(kMayBeSameAsFirstInput);
406+
}
407+
401408
// Empty location. Used if there the location should be ignored.
402409
static Location NoLocation() { return Location(); }
403410

0 commit comments

Comments
 (0)