Skip to content

Commit 1f26e44

Browse files
sparker-armV8 LUCI CQ
authored andcommitted
[arm64][turbofan] Word[32|64]Select support
Enable the use of csel. Change-Id: I6c2d3cc835149ce4beeb7334985ad2c11300d2c8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4374179 Reviewed-by: Thibaud Michaud <[email protected]> Commit-Queue: Martyn Capewell <[email protected]> Reviewed-by: Andreas Haas <[email protected]> Cr-Commit-Position: refs/heads/main@{#87165}
1 parent ff8868e commit 1f26e44

4 files changed

Lines changed: 64 additions & 36 deletions

File tree

src/compiler/backend/arm64/code-generator-arm64.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,11 +3148,17 @@ void CodeGenerator::AssembleArchSelect(Instruction* instr,
31483148
__ Fcsel(i.OutputFloat32Register(),
31493149
i.InputFloat32Register(true_value_index),
31503150
i.InputFloat32Register(false_value_index), cc);
3151-
} else {
3152-
DCHECK_EQ(rep, MachineRepresentation::kFloat64);
3151+
} else if (rep == MachineRepresentation::kFloat64) {
31533152
__ Fcsel(i.OutputFloat64Register(),
31543153
i.InputFloat64Register(true_value_index),
31553154
i.InputFloat64Register(false_value_index), cc);
3155+
} else if (rep == MachineRepresentation::kWord32) {
3156+
__ Csel(i.OutputRegister32(), i.InputRegister32(true_value_index),
3157+
i.InputRegister32(false_value_index), cc);
3158+
} else {
3159+
DCHECK_EQ(rep, MachineRepresentation::kWord64);
3160+
__ Csel(i.OutputRegister64(), i.InputRegister64(true_value_index),
3161+
i.InputRegister64(false_value_index), cc);
31563162
}
31573163
}
31583164

src/compiler/backend/arm64/instruction-selector-arm64.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4708,7 +4708,9 @@ InstructionSelector::SupportedMachineOperatorFlags() {
47084708
MachineOperatorBuilder::kWord64ReverseBits |
47094709
MachineOperatorBuilder::kSatConversionIsSafe |
47104710
MachineOperatorBuilder::kFloat32Select |
4711-
MachineOperatorBuilder::kFloat64Select;
4711+
MachineOperatorBuilder::kFloat64Select |
4712+
MachineOperatorBuilder::kWord32Select |
4713+
MachineOperatorBuilder::kWord64Select;
47124714
}
47134715

47144716
// static

test/cctest/compiler/test-run-machops.cc

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,22 @@ TEST(RunSelectUnorderedNotEqual) {
472472
CHECK_EQ(input1, m.Call(input1, input2, std::nanf("")));
473473
}
474474

475+
namespace {
476+
template <typename T>
477+
ExternalReference ExternalRefFromFunc(RawMachineAssemblerTester<T>* m,
478+
Address func_address) {
479+
ExternalReference::Type func_type = ExternalReference::FAST_C_CALL;
480+
ApiFunction func(func_address);
481+
ExternalReference ref = ExternalReference::Create(&func, func_type);
482+
#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
483+
EncodedCSignature sig = m->call_descriptor()->ToEncodedCSignature();
484+
m->main_isolate()->simulator_data()->AddSignatureForTargetForTesting(
485+
func_address, sig);
486+
#endif
487+
return ref;
488+
}
489+
} // namespace
490+
475491
namespace {
476492
void FooForSelect() {}
477493
} // namespace
@@ -484,14 +500,13 @@ TEST(RunWord32SelectWithMemoryInput) {
484500
}
485501

486502
// Test that the generated code also works with values spilled on the stack.
487-
488-
auto* foo_ptr = &FooForSelect;
503+
ExternalReference ref = ExternalRefFromFunc(&m, FUNCTION_ADDR(FooForSelect));
489504
constexpr int input1 = 16;
490505
int input2 = 3443;
491506
// Load {value2} before the function call so that it gets spilled.
492507
Node* value2 = m.LoadFromPointer(&input2, MachineType::Int32());
493-
Node* function = m.LoadFromPointer(&foo_ptr, MachineType::Pointer());
494508
// Call a function so that {value2} gets spilled on the stack.
509+
Node* function = m.ExternalConstant(ref);
495510
m.CallCFunction(function, MachineType::Int32());
496511
Node* cmp = m.Word32Equal(m.Parameter(1), m.Int32Constant(0));
497512
m.Return(m.Word32Select(cmp, m.Parameter(0), value2));
@@ -511,13 +526,13 @@ TEST(RunWord64SelectWithMemoryInput) {
511526

512527
// Test that the generated code also works with values spilled on the stack.
513528

514-
auto* foo_ptr = &FooForSelect;
529+
ExternalReference ref = ExternalRefFromFunc(&m, FUNCTION_ADDR(FooForSelect));
515530
constexpr int64_t input1 = 16;
516531
int64_t input2 = 0x12345678ABCD;
517532
// Load {value2} before the function call so that it gets spilled.
518533
Node* value2 = m.LoadFromPointer(&input2, MachineType::Int64());
519-
Node* function = m.LoadFromPointer(&foo_ptr, MachineType::Pointer());
520534
// Call a function so that {value2} gets spilled on the stack.
535+
Node* function = m.ExternalConstant(ref);
521536
m.CallCFunction(function, MachineType::Int32());
522537
Node* cmp = m.Word32Equal(m.Parameter(1), m.Int32Constant(0));
523538
m.Return(m.Word64Select(cmp, m.Parameter(0), value2));
@@ -6778,20 +6793,6 @@ TEST(RunCallCFunction9) {
67786793
#endif // !USE_SIMULATOR
67796794

67806795
#ifdef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
6781-
#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
6782-
#define IF_SIMULATOR_ADD_SIGNATURE \
6783-
EncodedCSignature sig = m.call_descriptor()->ToEncodedCSignature(); \
6784-
m.main_isolate()->simulator_data()->AddSignatureForTargetForTesting( \
6785-
func_address, sig);
6786-
#else
6787-
#define IF_SIMULATOR_ADD_SIGNATURE
6788-
#endif // V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
6789-
6790-
#define EXTERNAL_REF_FROM_FUNC(FUNC) \
6791-
Address func_address = FUNCTION_ADDR(&FUNC); \
6792-
ExternalReference::Type func_type = ExternalReference::FAST_C_CALL; \
6793-
ApiFunction func(func_address); \
6794-
ExternalReference ref = ExternalReference::Create(&func, func_type);
67956796

67966797
namespace {
67976798

@@ -6919,8 +6920,7 @@ double int_foo10(int64_t a, int64_t b, int64_t c, int64_t d, int64_t e,
69196920

69206921
TEST(RunCallDoubleCFunction0) {
69216922
RawMachineAssemblerTester<double> m;
6922-
EXTERNAL_REF_FROM_FUNC(double_foo0)
6923-
IF_SIMULATOR_ADD_SIGNATURE
6923+
ExternalReference ref = ExternalRefFromFunc(&m, FUNCTION_ADDR(double_foo0));
69246924

69256925
Node* function = m.ExternalConstant(ref);
69266926
m.Return(m.CallCFunction(function, MachineType::Float64()));
@@ -6929,8 +6929,7 @@ TEST(RunCallDoubleCFunction0) {
69296929

69306930
TEST(RunCallDoubleCFunction1) {
69316931
RawMachineAssemblerTester<double> m(MachineType::Float64());
6932-
EXTERNAL_REF_FROM_FUNC(double_foo1)
6933-
IF_SIMULATOR_ADD_SIGNATURE
6932+
ExternalReference ref = ExternalRefFromFunc(&m, FUNCTION_ADDR(double_foo1));
69346933

69356934
Node* function = m.ExternalConstant(ref);
69366935
m.Return(
@@ -6942,8 +6941,7 @@ TEST(RunCallDoubleCFunction1) {
69426941
TEST(RunCallDoubleCFunction2) {
69436942
RawMachineAssemblerTester<double> m(MachineType::Float64(),
69446943
MachineType::Float64());
6945-
EXTERNAL_REF_FROM_FUNC(double_foo2)
6946-
IF_SIMULATOR_ADD_SIGNATURE
6944+
ExternalReference ref = ExternalRefFromFunc(&m, FUNCTION_ADDR(double_foo2));
69476945

69486946
Node* function = m.ExternalConstant(ref);
69496947
m.Return(
@@ -6961,8 +6959,7 @@ TEST(RunCallDoubleCFunction8) {
69616959
MachineType::Float64(), MachineType::Float64(), MachineType::Float64(),
69626960
MachineType::Float64(), MachineType::Float64(), MachineType::Float64(),
69636961
MachineType::Float64(), MachineType::Float64());
6964-
EXTERNAL_REF_FROM_FUNC(double_foo8)
6965-
IF_SIMULATOR_ADD_SIGNATURE
6962+
ExternalReference ref = ExternalRefFromFunc(&m, FUNCTION_ADDR(double_foo8));
69666963

69676964
Node* function = m.ExternalConstant(ref);
69686965
Node* param = m.Parameter(0);
@@ -6986,8 +6983,7 @@ TEST(RunCallDoubleCFunction9) {
69866983
MachineType::Float64(), MachineType::Float64(), MachineType::Float64(),
69876984
MachineType::Float64(), MachineType::Float64(), MachineType::Float64(),
69886985
MachineType::Float64(), MachineType::Float64(), MachineType::Float64());
6989-
EXTERNAL_REF_FROM_FUNC(double_foo9)
6990-
IF_SIMULATOR_ADD_SIGNATURE
6986+
ExternalReference ref = ExternalRefFromFunc(&m, FUNCTION_ADDR(double_foo9));
69916987

69926988
Node* function = m.ExternalConstant(ref);
69936989
Node* param = m.Parameter(0);
@@ -7022,8 +7018,7 @@ TEST(RunCallDoubleCFunction10) {
70227018
MachineType::Float64(), MachineType::Float64(), MachineType::Float64(),
70237019
MachineType::Float64(), MachineType::Float64(), MachineType::Float64(),
70247020
MachineType::Int64());
7025-
EXTERNAL_REF_FROM_FUNC(double_foo10)
7026-
IF_SIMULATOR_ADD_SIGNATURE
7021+
ExternalReference ref = ExternalRefFromFunc(&m, FUNCTION_ADDR(double_foo10));
70277022

70287023
Node* function = m.ExternalConstant(ref);
70297024
m.Return(
@@ -7051,8 +7046,7 @@ TEST(RunCallIntCFunction10) {
70517046
MachineType::Int64(), MachineType::Int64(), MachineType::Int64(),
70527047
MachineType::Int64(), MachineType::Int64(), MachineType::Int64(),
70537048
MachineType::Float64());
7054-
EXTERNAL_REF_FROM_FUNC(int_foo10)
7055-
IF_SIMULATOR_ADD_SIGNATURE
7049+
ExternalReference ref = ExternalRefFromFunc(&m, FUNCTION_ADDR(int_foo10));
70567050

70577051
Node* function = m.ExternalConstant(ref);
70587052
m.Return(

test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,32 @@ TEST_F(InstructionSelectorTest, Float64SelectWithRegisters) {
29932993
EXPECT_EQ(kNotEqual, s[0]->flags_condition());
29942994
}
29952995

2996+
TEST_F(InstructionSelectorTest, Word32SelectWithRegisters) {
2997+
StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(),
2998+
MachineType::Int32());
2999+
Node* cond = m.Int32Constant(1);
3000+
m.Return(m.Word32Select(cond, m.Parameter(0), m.Parameter(1)));
3001+
Stream s = m.Build();
3002+
EXPECT_EQ(kArm64Tst32, s[0]->arch_opcode());
3003+
EXPECT_EQ(4U, s[0]->InputCount());
3004+
EXPECT_EQ(1U, s[0]->OutputCount());
3005+
EXPECT_EQ(kFlags_select, s[0]->flags_mode());
3006+
EXPECT_EQ(kNotEqual, s[0]->flags_condition());
3007+
}
3008+
3009+
TEST_F(InstructionSelectorTest, Word64SelectWithRegisters) {
3010+
StreamBuilder m(this, MachineType::Int32(), MachineType::Int64(),
3011+
MachineType::Int64());
3012+
Node* cond = m.Int32Constant(1);
3013+
m.Return(m.Word64Select(cond, m.Parameter(0), m.Parameter(1)));
3014+
Stream s = m.Build();
3015+
EXPECT_EQ(kArm64Tst32, s[0]->arch_opcode());
3016+
EXPECT_EQ(4U, s[0]->InputCount());
3017+
EXPECT_EQ(1U, s[0]->OutputCount());
3018+
EXPECT_EQ(kFlags_select, s[0]->flags_mode());
3019+
EXPECT_EQ(kNotEqual, s[0]->flags_condition());
3020+
}
3021+
29963022
// -----------------------------------------------------------------------------
29973023
// Conversions.
29983024

0 commit comments

Comments
 (0)