Commit d542b077 authored by ivica.bogosavljevic's avatar ivica.bogosavljevic Committed by Commit bot

MIPS64: Optimize load followed by shift

Turbofan uses 64-bit load followed by 32 bit arithmetic shift when
loading higher 32 bits of 64-bit value. We simplify this
by loading higher 32 bits directly.

BUG=

Review-Url: https://codereview.chromium.org/2532333003
Cr-Commit-Position: refs/heads/master@{#41455}
parent e454742d
...@@ -195,6 +195,16 @@ struct ExtendingLoadMatcher { ...@@ -195,6 +195,16 @@ struct ExtendingLoadMatcher {
DCHECK(m.IsWord64Sar()); DCHECK(m.IsWord64Sar());
if (m.left().IsLoad() && m.right().Is(32) && if (m.left().IsLoad() && m.right().Is(32) &&
selector_->CanCover(m.node(), m.left().node())) { selector_->CanCover(m.node(), m.left().node())) {
MachineRepresentation rep =
LoadRepresentationOf(m.left().node()->op()).representation();
DCHECK(ElementSizeLog2Of(rep) == 3);
if (rep != MachineRepresentation::kTaggedSigned &&
rep != MachineRepresentation::kTaggedPointer &&
rep != MachineRepresentation::kTagged &&
rep != MachineRepresentation::kWord64) {
return;
}
Mips64OperandGenerator g(selector_); Mips64OperandGenerator g(selector_);
Node* load = m.left().node(); Node* load = m.left().node();
Node* offset = load->InputAt(1); Node* offset = load->InputAt(1);
...@@ -212,7 +222,8 @@ struct ExtendingLoadMatcher { ...@@ -212,7 +222,8 @@ struct ExtendingLoadMatcher {
} }
}; };
bool TryEmitExtendingLoad(InstructionSelector* selector, Node* node) { bool TryEmitExtendingLoad(InstructionSelector* selector, Node* node,
Node* output_node) {
ExtendingLoadMatcher m(node, selector); ExtendingLoadMatcher m(node, selector);
Mips64OperandGenerator g(selector); Mips64OperandGenerator g(selector);
if (m.Matches()) { if (m.Matches()) {
...@@ -222,7 +233,7 @@ bool TryEmitExtendingLoad(InstructionSelector* selector, Node* node) { ...@@ -222,7 +233,7 @@ bool TryEmitExtendingLoad(InstructionSelector* selector, Node* node) {
m.opcode() | AddressingModeField::encode(kMode_MRI); m.opcode() | AddressingModeField::encode(kMode_MRI);
DCHECK(is_int32(m.immediate())); DCHECK(is_int32(m.immediate()));
inputs[1] = g.TempImmediate(static_cast<int32_t>(m.immediate())); inputs[1] = g.TempImmediate(static_cast<int32_t>(m.immediate()));
InstructionOperand outputs[] = {g.DefineAsRegister(node)}; InstructionOperand outputs[] = {g.DefineAsRegister(output_node)};
selector->Emit(opcode, arraysize(outputs), outputs, arraysize(inputs), selector->Emit(opcode, arraysize(outputs), outputs, arraysize(inputs),
inputs); inputs);
return true; return true;
...@@ -778,7 +789,7 @@ void InstructionSelector::VisitWord64Shr(Node* node) { ...@@ -778,7 +789,7 @@ void InstructionSelector::VisitWord64Shr(Node* node) {
void InstructionSelector::VisitWord64Sar(Node* node) { void InstructionSelector::VisitWord64Sar(Node* node) {
if (TryEmitExtendingLoad(this, node)) return; if (TryEmitExtendingLoad(this, node, node)) return;
VisitRRO(this, kMips64Dsar, node); VisitRRO(this, kMips64Dsar, node);
} }
...@@ -1348,13 +1359,17 @@ void InstructionSelector::VisitTruncateInt64ToInt32(Node* node) { ...@@ -1348,13 +1359,17 @@ void InstructionSelector::VisitTruncateInt64ToInt32(Node* node) {
if (CanCover(node, value)) { if (CanCover(node, value)) {
switch (value->opcode()) { switch (value->opcode()) {
case IrOpcode::kWord64Sar: { case IrOpcode::kWord64Sar: {
Int64BinopMatcher m(value); if (TryEmitExtendingLoad(this, value, node)) {
if (m.right().IsInRange(32, 63)) {
// After smi untagging no need for truncate. Combine sequence.
Emit(kMips64Dsar, g.DefineSameAsFirst(node),
g.UseRegister(m.left().node()),
g.UseImmediate(m.right().node()));
return; return;
} else {
Int64BinopMatcher m(value);
if (m.right().IsInRange(32, 63)) {
// After smi untagging no need for truncate. Combine sequence.
Emit(kMips64Dsar, g.DefineSameAsFirst(node),
g.UseRegister(m.left().node()),
g.UseImmediate(m.right().node()));
return;
}
} }
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment