Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

This work updates the IR type legalization handling for CoopMat.MapElement to rebuild the intrinsic when its operands or result type are legalized, and it adds a regression test for the minimal repro.

Changes Made

  • Update legalizeCoopMatMapElementIFunc to re-emit the instruction when operands/types are legalized and to drop invalid this arguments.
  • Add tests/bugs/coopmat-map-element-crash.slang regression test (self-contained repro).

Testing

  • ./build/Debug/bin/slang-test tests/bugs/coopmat-map-element-crash.slang (currently fails with “replaced inst still has use” and needs follow-up).
Original prompt

This section details on the original issue you should resolve

<issue_title>CoopMat.MapElement crashes the compiler</issue_title>
<issue_description>```
// Minimal repro for CoopMat.MapElement crash.
// Keep this file self-contained: no external includes required.

struct ReproParams
{
half* output; // output buffer
int outputW;
};

[numthreads(256, 1, 1)]
void coopmat_map_element_repro(
ConstantBuffer params,
uint3 groupThreadId : SV_GroupThreadID,
uint3 groupId : SV_GroupID)
{
static const int TILE_M = 64;
static const int TILE_N = 32;
// Fill accumulator with a constant to exercise MapElement.
linalg::CoopMat<float, MemoryScope.Workgroup, TILE_M, TILE_N, linalg::CoopMatMatrixUse.MatrixAccumulator> matC;
matC.fill(1.0f);

// Direct write via MapElement.
matC = matC.MapElement((uint row, uint col, float acc) => {
    int outIdx = col * params.outputW;
    params.output[outIdx] = half(acc);
    return acc;
});

}


Crashes in 

slang-compiler.dll!Slang::handleSignal(Slang::SignalType type, const char * message) Line 115 C++

slang-compiler.dll!Slang::IRTypeLegalizationPass::processModule(Slang::IRModule * module) Line 3669 C++
slang-compiler.dll!Slang::legalizeTypes(Slang::IRTypeLegalizationContext * context) Line 3780 C++
slang-compiler.dll!Slang::legalizeResourceTypes(Slang::IRModule * module, Slang::TargetProgram * target, Slang::DiagnosticSink * sink) Line 3926 C++
slang-compiler.dll!Slang::linkAndOptimizeIR'::159'::<lambda_87>::operator()<Slang::IRModule,Slang::TargetProgram * &,Slang::DiagnosticSink * &>(Slang::IRModule * m, Slang::TargetProgram * & <a_0>, Slang::DiagnosticSink * & <a_1>) Line 1361 C++
slang-compiler.dll!Slang::wrapPass<Slang::linkAndOptimizeIR'::159'::<lambda_87>,Slang::TargetProgram * &,Slang::DiagnosticSink * &>(Slang::CodeGenContext * codeGenContext, const char * passName, Slang::linkAndOptimizeIR::__l159::<lambda_87> && passFunc, Slang::IRModule * irModule, Slang::TargetProgram * & <args_0>, Slang::DiagnosticSink * & <args_1>) Line 60 C++
slang-compiler.dll!Slang::linkAndOptimizeIR(Slang::CodeGenContext * codeGenContext, const Slang::LinkingAndOptimizationOptions & options, Slang::LinkedIR & outLinkedIR) Line 1361 C++
slang-compiler.dll!Slang::emitSPIRVForEntryPointsDirectly(Slang::CodeGenContext * codeGenContext, Slang::ComPtrSlang::IArtifact & outArtifact) Line 2767 C++
slang-compiler.dll!Slang::CodeGenContext::_emitEntryPoints(Slang::ComPtrSlang::IArtifact & outArtifact) Line 1145 C++
slang-compiler.dll!Slang::CodeGenContext::emitEntryPoints(Slang::ComPtrSlang::IArtifact & outArtifact) Line 1234 C++
slang-compiler.dll!Slang::TargetProgram::_createWholeProgramResult(Slang::DiagnosticSink * sink, Slang::EndToEndCompileRequest * endToEndReq) Line 40 C++
slang-compiler.dll!Slang::EndToEndCompileRequest::generateOutput(Slang::TargetProgram * targetProgram) Line 474 C++
slang-compiler.dll!Slang::EndToEndCompileRequest::generateOutput(Slang::ComponentType * program) Line 725 C++
slang-compiler.dll!Slang::EndToEndCompileRequest::generateOutput() Line 732 C++
slang-compiler.dll!Slang::EndToEndCompileRequest::executeActionsInner() Line 267 C++
slang-compiler.dll!Slang::EndToEndCompileRequest::executeActions() Line 277 C++
slang-compiler.dll!Slang::EndToEndCompileRequest::compile() Line 1473 C++
slang-compiler.dll!spCompile(slang::ICompileRequest * request) Line 757 C++


## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@csyonghe
Copy link
Collaborator

@copilot continue.

@csyonghe
Copy link
Collaborator

Closing this, a diagnostic has been added to report this as an unsupported case.

@csyonghe csyonghe closed this Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CoopMat.MapElement crashes the compiler

2 participants