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

Unified Diff: src/compiler/simplified-lowering.cc

Issue 2169293002: [turbofan] Improve lowering for NumberAbs to Int32Abs. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/simplified-lowering.cc
diff --git a/src/compiler/simplified-lowering.cc b/src/compiler/simplified-lowering.cc
index ad55f1db910e9095f4bc1c08f762fd64b7f26e3c..0e0e22e311e01e8a6539acbe84cfd8f151fc757c 100644
--- a/src/compiler/simplified-lowering.cc
+++ b/src/compiler/simplified-lowering.cc
@@ -3117,14 +3117,18 @@ Node* SimplifiedLowering::Float64Trunc(Node* const node) {
}
Node* SimplifiedLowering::Int32Abs(Node* const node) {
- Node* const zero = jsgraph()->Int32Constant(0);
Node* const input = node->InputAt(0);
- // if 0 < input then input else 0 - input
- return graph()->NewNode(
- common()->Select(MachineRepresentation::kWord32, BranchHint::kTrue),
- graph()->NewNode(machine()->Int32LessThan(), zero, input), input,
- graph()->NewNode(machine()->Int32Sub(), zero, input));
+ // Generate case for absolute integer value.
+ //
+ // let sign = input >> 31 in
+ // (input ^ sign) - sign
+
+ Node* sign = graph()->NewNode(machine()->Word32Sar(), input,
+ jsgraph()->Int32Constant(31));
+ return graph()->NewNode(machine()->Int32Sub(),
+ graph()->NewNode(machine()->Word32Xor(), input, sign),
+ sign);
}
Node* SimplifiedLowering::Int32Div(Node* const node) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698