Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: src/a64/lithium-a64.cc

Issue 175143002: Consistenly handle power-of-2 divisors in division-like operations (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/a64/lithium-a64.h ('k') | src/a64/lithium-codegen-a64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/a64/lithium-a64.cc
diff --git a/src/a64/lithium-a64.cc b/src/a64/lithium-a64.cc
index ae8705de436a5fc08b1f164695b6febecdc267c0..d2025fcb9a2ffb3d628a05b4f4c9a1a20ea3c0cb 100644
--- a/src/a64/lithium-a64.cc
+++ b/src/a64/lithium-a64.cc
@@ -1368,23 +1368,44 @@ LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
}
+LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) {
+ ASSERT(instr->representation().IsSmiOrInteger32());
+ ASSERT(instr->left()->representation().Equals(instr->representation()));
+ ASSERT(instr->right()->representation().Equals(instr->representation()));
+ LOperand* dividend = UseRegister(instr->left());
+ int32_t divisor = instr->right()->GetInteger32Constant();
+ LInstruction* result =
+ DefineAsRegister(new(zone()) LDivByPowerOf2I(dividend, divisor));
+ bool can_deopt =
+ (instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
+ instr->left()->RangeCanInclude(0) && divisor < 0) ||
+ (instr->CheckFlag(HValue::kCanOverflow) &&
+ instr->left()->RangeCanInclude(kMinInt) && divisor == -1) ||
+ (!instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) &&
+ divisor != 1 && divisor != -1);
+ return can_deopt ? AssignEnvironment(result) : result;
+}
+
+
+LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) {
+ ASSERT(instr->representation().IsSmiOrInteger32());
+ ASSERT(instr->left()->representation().Equals(instr->representation()));
+ ASSERT(instr->right()->representation().Equals(instr->representation()));
+ LOperand* dividend = UseRegister(instr->left());
+ LOperand* divisor = UseRegister(instr->right());
+ LOperand* temp = instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)
+ ? NULL : TempRegister();
+ LDivI* div = new(zone()) LDivI(dividend, divisor, temp);
+ return AssignEnvironment(DefineAsRegister(div));
+}
+
+
LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
- if (instr->representation().IsInteger32()) {
- // TODO(all): Update this case to support smi inputs.
- ASSERT(instr->left()->representation().Equals(instr->representation()));
- ASSERT(instr->right()->representation().Equals(instr->representation()));
- if (instr->RightIsPowerOf2()) {
- ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero));
- LOperand* value = UseRegister(instr->left());
- LDivI* div = new(zone()) LDivI(value, UseConstant(instr->right()), NULL);
- return AssignEnvironment(DefineAsRegister(div));
- }
- LOperand* dividend = UseRegister(instr->left());
- LOperand* divisor = UseRegister(instr->right());
- LOperand* temp = instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)
- ? NULL : TempRegister();
- LDivI* div = new(zone()) LDivI(dividend, divisor, temp);
- return AssignEnvironment(DefineAsRegister(div));
+ if (instr->representation().IsSmiOrInteger32()) {
+ // TODO(all): Add Smi support to DoDivI and turn this into a ternary.
+ if (instr->RightIsPowerOf2()) return DoDivByPowerOf2I(instr);
+ if (instr->representation().IsInteger32()) return DoDivI(instr);
+ return DoArithmeticT(Token::DIV, instr);
} else if (instr->representation().IsDouble()) {
return DoArithmeticD(Token::DIV, instr);
} else {
@@ -1692,13 +1713,37 @@ LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) {
}
-LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
- HValue* right = instr->right();
+LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
+ LOperand* dividend = UseRegisterAtStart(instr->left());
+ int32_t divisor = instr->right()->GetInteger32Constant();
+ LInstruction* result =
+ DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor));
+ bool can_deopt =
+ (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
+ (instr->left()->RangeCanInclude(kMinInt) && divisor == -1);
+ return can_deopt ? AssignEnvironment(result) : result;
+}
+
+
+LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) {
LOperand* dividend = UseRegister(instr->left());
- LOperand* divisor = UseRegister(right);
+ LOperand* divisor = UseRegister(instr->right());
LOperand* remainder = TempRegister();
- return AssignEnvironment(DefineAsRegister(
- new(zone()) LMathFloorOfDiv(dividend, divisor, remainder)));
+ LInstruction* result =
+ DefineAsRegister(new(zone()) LFlooringDivI(dividend, divisor, remainder));
+ return AssignEnvironment(result);
+}
+
+
+LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) {
+ if (instr->RightIsPowerOf2()) {
+ return DoFlooringDivByPowerOf2I(instr);
+ } else if (instr->right()->IsConstant()) {
+ // TODO(svenpanne) Do something more efficient in this case.
+ return DoFlooringDivI(instr);
+ } else {
+ return DoFlooringDivI(instr);
+ }
}
@@ -1721,38 +1766,46 @@ LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
}
-LInstruction* LChunkBuilder::DoMod(HMod* hmod) {
- HValue* hleft = hmod->left();
- HValue* hright = hmod->right();
-
- // TODO(jbramley): Add smi support.
- if (hmod->representation().IsInteger32()) {
- ASSERT(hleft->representation().IsInteger32());
- ASSERT(hleft->representation().IsInteger32());
- LOperand* left_op;
- LOperand* right_op;
+LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) {
+ ASSERT(instr->representation().IsSmiOrInteger32());
+ ASSERT(instr->left()->representation().Equals(instr->representation()));
+ ASSERT(instr->right()->representation().Equals(instr->representation()));
+ LOperand* dividend = UseRegisterAtStart(instr->left());
+ int32_t divisor = instr->right()->GetInteger32Constant();
+ LInstruction* result =
+ DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor));
+ bool can_deopt =
+ instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
+ instr->left()->CanBeNegative();
+ return can_deopt ? AssignEnvironment(result) : result;
+}
- if (hmod->RightIsPowerOf2()) {
- left_op = UseRegisterAtStart(hleft);
- right_op = UseConstant(hright);
- } else {
- right_op = UseRegister(hright);
- left_op = UseRegister(hleft);
- }
- LModI* lmod = new(zone()) LModI(left_op, right_op);
+LInstruction* LChunkBuilder::DoModI(HMod* instr) {
+ ASSERT(instr->representation().IsSmiOrInteger32());
+ ASSERT(instr->left()->representation().Equals(instr->representation()));
+ ASSERT(instr->right()->representation().Equals(instr->representation()));
+ LOperand* dividend = UseRegister(instr->left());
+ LOperand* divisor = UseRegister(instr->right());
+ LInstruction* result =
+ DefineAsRegister(new(zone()) LModI(dividend, divisor));
+ bool can_deopt = (instr->right()->CanBeZero() ||
+ (instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
+ instr->left()->CanBeNegative() && instr->CanBeZero()));
+ return can_deopt ? AssignEnvironment(result) : result;
+}
- if (hmod->right()->CanBeZero() ||
- (hmod->CheckFlag(HValue::kBailoutOnMinusZero) &&
- hmod->left()->CanBeNegative() && hmod->CanBeZero())) {
- AssignEnvironment(lmod);
- }
- return DefineAsRegister(lmod);
- } else if (hmod->representation().IsSmiOrTagged()) {
- return DoArithmeticT(Token::MOD, hmod);
+LInstruction* LChunkBuilder::DoMod(HMod* instr) {
+ if (instr->representation().IsSmiOrInteger32()) {
+ // TODO(all): Add Smi support to DoDivI and turn this into a ternary.
+ if (instr->RightIsPowerOf2()) return DoModByPowerOf2I(instr);
+ if (instr->representation().IsInteger32()) return DoModI(instr);
+ return DoArithmeticT(Token::MOD, instr);
+ } else if (instr->representation().IsDouble()) {
+ return DoArithmeticD(Token::MOD, instr);
} else {
- return DoArithmeticD(Token::MOD, hmod);
+ return DoArithmeticT(Token::MOD, instr);
}
}
« no previous file with comments | « src/a64/lithium-a64.h ('k') | src/a64/lithium-codegen-a64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698