diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-12 02:26:15 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-12 02:26:15 +0800 |
| commit | 5ee4740bc864a8aaddb50e8e7a43cb5a18df0fcf (patch) | |
| tree | 13770500cd8f0b55d73c5b2eedee5c4a0312c314 /backend/unittests/Target/RISCVCodeGenTest.cpp | |
| parent | 33c887caf02b28fd45cf7cf966537e123081ff53 (diff) | |
| download | rcc-project-5ee4740bc864a8aaddb50e8e7a43cb5a18df0fcf.tar.gz rcc-project-5ee4740bc864a8aaddb50e8e7a43cb5a18df0fcf.tar.xz | |
[RISCV] Legalize G_PTR_ADD with s64 offsets
Diffstat (limited to 'backend/unittests/Target/RISCVCodeGenTest.cpp')
| -rw-r--r-- | backend/unittests/Target/RISCVCodeGenTest.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/backend/unittests/Target/RISCVCodeGenTest.cpp b/backend/unittests/Target/RISCVCodeGenTest.cpp index d07387a..ddacb1b 100644 --- a/backend/unittests/Target/RISCVCodeGenTest.cpp +++ b/backend/unittests/Target/RISCVCodeGenTest.cpp @@ -1675,6 +1675,32 @@ void testFrameIndexLegalization(TestContext &Context) { "RV64GC must reject G_FRAME_INDEX outside p0"); } +void testPointerArithmeticLegalization(TestContext &Context) { + auto Target = rcc::riscv::createTargetDescription(); + Context.expect(Target.has_value(), "RV64GC target must be available for pointer legalization"); + if (!Target) + return; + auto Pointer = rcc::LLT::makePointer(0, 64); + auto S64 = rcc::LLT::makeAnyScalar(64); + auto S32 = rcc::LLT::makeAnyScalar(32); + if (!Pointer || !S64 || !S32) + return; + auto Legal = createRegisterOnlyFunction(Context, *Target, rcc::GenericOpcode::G_PTR_ADD, + {*Pointer}, {*Pointer, *S64}); + auto Unsupported = createRegisterOnlyFunction(Context, *Target, rcc::GenericOpcode::G_PTR_ADD, + {*Pointer}, {*Pointer, *S32}); + if (!Legal || !Unsupported) + return; + auto LegalAction = rcc::riscv::legalizerInfo().classify(*Legal->firstBlock()->firstInstruction(), + *Legal, *Target); + auto UnsupportedAction = rcc::riscv::legalizerInfo().classify( + *Unsupported->firstBlock()->firstInstruction(), *Unsupported, *Target); + Context.expect(LegalAction && *LegalAction == rcc::LegalizationAction::Legal, + "RV64GC must legalize G_PTR_ADD for p0 and s64"); + Context.expect(UnsupportedAction && *UnsupportedAction == rcc::LegalizationAction::Unsupported, + "RV64GC must reject G_PTR_ADD with a non-XLen offset"); +} + void testMemoryOffsetSelection(TestContext &Context) { auto Target = rcc::riscv::createTargetDescription(); Context.expect(Target.has_value(), "RV64GC target must be available for memory selection"); @@ -1761,6 +1787,7 @@ int main() { testVACopyLegalization(Context); testVAArgLegalization(Context); testFrameIndexLegalization(Context); + testPointerArithmeticLegalization(Context); testMemoryOffsetSelection(Context); return Context.result(); } |
