Skip to content

Commit 5fd6c8a

Browse files
committed
[vm] Do not fuse constants with different representations
Issue: #39044 Change-Id: I19b1309adb769742b498ed0b6fe80ae38a779405 Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-dartkb-linux-debug-simarm64-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-dartkb-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-precomp-mac-release-simarm_x64-try,dart-sdk-linux-try,flutter-engine-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122396 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
1 parent 2727fd9 commit 5fd6c8a

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

runtime/bin/ffi_test/ffi_test_functions.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ DART_EXPORT int64_t IntComputation(int8_t a, int16_t b, int32_t c, int64_t d) {
123123
return retval;
124124
}
125125

126+
// Used in regress_39044_test.dart.
127+
DART_EXPORT int64_t Regress39044(int64_t a, int8_t b) {
128+
std::cout << "Regress39044(" << a << ", " << static_cast<int>(b) << ")\n";
129+
const int64_t retval = a - b;
130+
std::cout << "returning " << retval << "\n";
131+
return retval;
132+
}
133+
126134
// Performs some computation on various sized unsigned ints.
127135
// Used for testing value ranges for unsigned ints.
128136
DART_EXPORT int64_t UintComputation(uint8_t a,

runtime/vm/compiler/backend/il.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,8 @@ ConstantInstr::ConstantInstr(const Object& value, TokenPosition token_pos)
11171117
bool ConstantInstr::AttributesEqual(Instruction* other) const {
11181118
ConstantInstr* other_constant = other->AsConstant();
11191119
ASSERT(other_constant != NULL);
1120-
return (value().raw() == other_constant->value().raw());
1120+
return (value().raw() == other_constant->value().raw() &&
1121+
representation() == other_constant->representation());
11211122
}
11221123

11231124
UnboxedConstantInstr::UnboxedConstantInstr(const Object& value,

tests/ffi/regress_39044_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// Check that the optimizer does not fuse constants with different
6+
// representations.
7+
//
8+
// SharedObjects=ffi_test_functions
9+
10+
import "dart:ffi";
11+
12+
import "package:expect/expect.dart";
13+
14+
import "dylib_utils.dart";
15+
16+
main() {
17+
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
18+
19+
final intComputation = ffiTestFunctions.lookupFunction<
20+
Int64 Function(Int64, Int8), int Function(int, int)>("Regress39044");
21+
22+
// The arguments are the same Smi constant, however they are different sizes.
23+
final result = intComputation(
24+
/* dart::kUnboxedInt64 --> int64_t */ 1,
25+
/* dart::kUnboxedInt32 --> truncated to int8_t */ 1);
26+
27+
Expect.equals(0, result);
28+
}

0 commit comments

Comments
 (0)