diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-12 00:39:19 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-12 00:39:19 +0800 |
| commit | 524aad16ef496c849e812e972ed31b9d0db8c373 (patch) | |
| tree | bd032e32a2751134c76706d9c954c58490595daf | |
| parent | 384d524b497826e0760f1bb3b54f0533e0f33957 (diff) | |
| download | rcc-project-524aad16ef496c849e812e972ed31b9d0db8c373.tar.gz rcc-project-524aad16ef496c849e812e972ed31b9d0db8c373.tar.xz | |
[CodeGen] Accept pointer comparisons in G_ICMP
| -rw-r--r-- | backend/lib/CodeGen/GenericOpcodes.cpp | 16 | ||||
| -rw-r--r-- | backend/unittests/CodeGen/GenericOpcodesTest.cpp | 13 |
2 files changed, 24 insertions, 5 deletions
diff --git a/backend/lib/CodeGen/GenericOpcodes.cpp b/backend/lib/CodeGen/GenericOpcodes.cpp index 4c60675..c6967d5 100644 --- a/backend/lib/CodeGen/GenericOpcodes.cpp +++ b/backend/lib/CodeGen/GenericOpcodes.cpp @@ -43,6 +43,11 @@ using GO = GenericOpcode; return {LLT::Kind::AnyScalar, LLT::Kind::Integer, LLT::Kind::VectorAny, LLT::Kind::VectorInteger}; } +[[nodiscard]] LLTKindSet integerOrPointerKinds() { + return {LLT::Kind::AnyScalar, LLT::Kind::Integer, LLT::Kind::Pointer, + LLT::Kind::VectorAny, LLT::Kind::VectorInteger, LLT::Kind::VectorPointer}; +} + [[nodiscard]] LLTKindSet scalarIntegerKinds() { return {LLT::Kind::AnyScalar, LLT::Kind::Integer}; } @@ -393,8 +398,7 @@ private: if (Payload == nullptr) return semanticError("G_FCONSTANT requires a floating-point immediate"); const LLT DestinationType = TypeAt(0); - const std::optional<FloatSemantics> DestinationSemantics = - DestinationType.floatSemantics(); + const std::optional<FloatSemantics> DestinationSemantics = DestinationType.floatSemantics(); if ((DestinationSemantics && Payload->Bits.semantics() != *DestinationSemantics) || (!DestinationSemantics && Payload->Bits.bitWidth() != DestinationType.scalarBitWidth())) { return semanticError("G_FCONSTANT semantics must match its destination LLT"); @@ -1137,6 +1141,7 @@ void configureCoreOpcodes(DescriptorRegistry &Registry) { void configureGenericOpcodes(DescriptorRegistry &Registry) { const LLTKindSet AnyTypes = anyValueKinds(); const LLTKindSet IntTypes = integerKinds(); + const LLTKindSet IntegerOrPointers = integerOrPointerKinds(); const LLTKindSet ScalarValues = scalarValueKinds(); const LLTKindSet ScalarInts = scalarIntegerKinds(); const LLTKindSet ScalarIntegerOrPointers = scalarIntegerOrPointerKinds(); @@ -1155,6 +1160,7 @@ void configureGenericOpcodes(DescriptorRegistry &Registry) { const auto IntDef1 = typedRegister(RegisterOperandRole::Def, IntTypes, 1); const auto IntUse0 = typedRegister(RegisterOperandRole::Use, IntTypes, 0); const auto IntUse1 = typedRegister(RegisterOperandRole::Use, IntTypes, 1); + const auto IntegerOrPointerUse1 = typedRegister(RegisterOperandRole::Use, IntegerOrPointers, 1); const auto ScalarIntDef0 = typedRegister(RegisterOperandRole::Def, ScalarInts, 0); const auto ScalarIntDef1 = typedRegister(RegisterOperandRole::Def, ScalarInts, 1); const auto ScalarIntUse0 = typedRegister(RegisterOperandRole::Use, ScalarInts, 0); @@ -1314,8 +1320,10 @@ void configureGenericOpcodes(DescriptorRegistry &Registry) { {GO::G_SHL, GO::G_LSHR, GO::G_ASHR, GO::G_ROTR, GO::G_ROTL, GO::G_USHLSAT, GO::G_SSHLSAT}, {IntDef0, IntUse0, IntUse1}, 1); Registry.configure({GO::G_FSHL, GO::G_FSHR}, {IntDef0, IntUse0, IntUse0, IntUse1}, 1); - Registry.configure({GO::G_ICMP}, - {IntDef0, kind(MachineOperand::Kind::Predicate), IntUse1, IntUse1}, 1); + Registry.configure( + {GO::G_ICMP}, + {IntDef0, kind(MachineOperand::Kind::Predicate), IntegerOrPointerUse1, IntegerOrPointerUse1}, + 1); Registry.configure({GO::G_FCMP}, {IntDef0, kind(MachineOperand::Kind::Predicate), FloatUse1, FloatUse1}, 1); Registry.configure({GO::G_SCMP, GO::G_UCMP}, {IntDef0, IntUse1, IntUse1}, 1); diff --git a/backend/unittests/CodeGen/GenericOpcodesTest.cpp b/backend/unittests/CodeGen/GenericOpcodesTest.cpp index 2463fce..c9ed8d5 100644 --- a/backend/unittests/CodeGen/GenericOpcodesTest.cpp +++ b/backend/unittests/CodeGen/GenericOpcodesTest.cpp @@ -456,9 +456,20 @@ void testShapesAndTypes(TestContext &Context) { .has_value(), "G_ICMP must accept an i1 result and homogeneous integer sources"); CompareOperands[0] = registerOperand(*Dst32, true); + Context.expect(Set->validateExplicitOperands(rcc::opcode(rcc::GenericOpcode::G_ICMP), + CompareOperands, (*Function)->registerInfo()) + .has_value(), + "G_ICMP must accept a legalized integer result container"); + CompareOperands[2] = registerOperand(*Address, false); + CompareOperands[3] = registerOperand(*NewAddress, false); + Context.expect(Set->validateExplicitOperands(rcc::opcode(rcc::GenericOpcode::G_ICMP), + CompareOperands, (*Function)->registerInfo()) + .has_value(), + "G_ICMP must accept homogeneous pointer sources"); + CompareOperands[3] = registerOperand(*Src32B, false); Context.expect(!Set->validateExplicitOperands(rcc::opcode(rcc::GenericOpcode::G_ICMP), CompareOperands, (*Function)->registerInfo()), - "G_ICMP must reject a non-i1 result"); + "G_ICMP must reject mixed pointer and integer sources"); std::vector<rcc::MachineOperand> FloatingLoad; FloatingLoad.push_back(registerOperand(Float64, true)); |
