cherry-pick-7e5c7b5964.patch 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Georg Neis <[email protected]>
  3. Date: Fri, 11 Sep 2020 16:37:47 +0200
  4. Subject: Fix bug in SimplifiedLowering's overflow computation
  5. It's unsound to ignore -0 inputs:
  6. -0 - INT32_MIN is outside of INT32 range.
  7. Bug: chromium:1126249
  8. Change-Id: I3b92f16c1201705780acb0359975329aa2ca34d1
  9. Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2404452
  10. Reviewed-by: Tobias Tebbi <[email protected]>
  11. Commit-Queue: Georg Neis <[email protected]>
  12. Cr-Commit-Position: refs/heads/master@{#69877}
  13. (cherry picked from commit e371325bcb03f20a362ebfa48225159702c6fde7)
  14. diff --git a/src/compiler/simplified-lowering.cc b/src/compiler/simplified-lowering.cc
  15. index 8997a5a83166e87fa52f12864690250855dd6161..ea4e242ef6fe3e93a3c7bb2b71b11c49861f9ca4 100644
  16. --- a/src/compiler/simplified-lowering.cc
  17. +++ b/src/compiler/simplified-lowering.cc
  18. @@ -175,10 +175,16 @@ void ReplaceEffectControlUses(Node* node, Node* effect, Node* control) {
  19. }
  20. bool CanOverflowSigned32(const Operator* op, Type left, Type right,
  21. - Zone* type_zone) {
  22. - // We assume the inputs are checked Signed32 (or known statically
  23. - // to be Signed32). Technically, the inputs could also be minus zero, but
  24. - // that cannot cause overflow.
  25. + TypeCache const* type_cache, Zone* type_zone) {
  26. + // We assume the inputs are checked Signed32 (or known statically to be
  27. + // Signed32). Technically, the inputs could also be minus zero, which we treat
  28. + // as 0 for the purpose of this function.
  29. + if (left.Maybe(Type::MinusZero())) {
  30. + left = Type::Union(left, type_cache->kSingletonZero, type_zone);
  31. + }
  32. + if (right.Maybe(Type::MinusZero())) {
  33. + right = Type::Union(right, type_cache->kSingletonZero, type_zone);
  34. + }
  35. left = Type::Intersect(left, Type::Signed32(), type_zone);
  36. right = Type::Intersect(right, Type::Signed32(), type_zone);
  37. if (left.IsNone() || right.IsNone()) return false;
  38. @@ -1468,7 +1474,8 @@ class RepresentationSelector {
  39. if (lower()) {
  40. if (truncation.IsUsedAsWord32() ||
  41. !CanOverflowSigned32(node->op(), left_feedback_type,
  42. - right_feedback_type, graph_zone())) {
  43. + right_feedback_type, type_cache_,
  44. + graph_zone())) {
  45. ChangeToPureOp(node, Int32Op(node));
  46. } else {
  47. diff --git a/test/mjsunit/compiler/regress-1126249.js b/test/mjsunit/compiler/regress-1126249.js
  48. new file mode 100644
  49. index 0000000000000000000000000000000000000000..87f4885305da3c48389251c50bfeabc70100be4b
  50. --- /dev/null
  51. +++ b/test/mjsunit/compiler/regress-1126249.js
  52. @@ -0,0 +1,22 @@
  53. +// Copyright 2020 the V8 project authors. All rights reserved.
  54. +// Use of this source code is governed by a BSD-style license that can be
  55. +// found in the LICENSE file.
  56. +
  57. +// Flags: --allow-natives-syntax
  58. +
  59. +function foo(b) {
  60. + var x = -0;
  61. + var y = -0x80000000;
  62. +
  63. + if (b) {
  64. + x = -1;
  65. + y = 1;
  66. + }
  67. +
  68. + return (x - y) == -0x80000000;
  69. +}
  70. +
  71. +%PrepareFunctionForOptimization(foo);
  72. +assertFalse(foo(true));
  73. +%OptimizeFunctionOnNextCall(foo);
  74. +assertFalse(foo(false));