[Comb] Fix assertion failure in extractConcatToConcatExtract pattern (Fixes #9573)#9598
Draft
[Comb] Fix assertion failure in extractConcatToConcatExtract pattern (Fixes #9573)#9598
Conversation
Fixes llvm#9573 The extractConcatToConcatExtract canonicalization pattern crashed when attempting to replace an ExtractOp with a single value using replaceOpAndCopyNamehint(). The issue occurred because the pattern created a new ExtractOp and immediately tried to replace the original op with it, leading to an inconsistent IR state during erasure. This fix removes the special case for single-element results and always uses replaceOpWithNewOpAndCopyNamehint<ConcatOp>, which performs atomic operation creation and replacement. Single-operand ConcatOps are automatically optimized away by the ConcatOp folder. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
uenoku
reviewed
Feb 3, 2026
Member
uenoku
left a comment
There was a problem hiding this comment.
Could you add a test? I'm not certain why first one causes an issue.
Contributor
Author
Here is a test case. Here are details you should look at: #9573. module test_module(
input logic [1:0] in,
output logic [3:0] out
);
// Continuous assignments to output bits
assign out[0] = in[0] ^ in[1];
assign out[3] = 1'h0;
// Combinational always block with implicit sensitivity list
always @* begin
out[1] = in[0] & in[1];
out[2] = in[0] | in[1];
end
endmodule |
Contributor
Author
|
I must test it completely and make sure that all the issues have been resolved. This PR is therefore in draft status until the check is approved. |
Member
|
Sorry I meant to add a test to |
Contributor
Author
OK, I will add it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #9573
The
extractConcatToConcatExtractcanonicalization pattern crashed with an assertion failure when attempting to replace an ExtractOp with a single value usingreplaceOpAndCopyNamehint().Root Cause: When
reverseConcatArgs.size() == 1, the code created a new ExtractOp and immediately tried to replace the original op with it. This led to an inconsistent IR state becausereplaceOpAndCopyNamehint()callsrewriter.replaceOp()which expects the operation to be in a valid state for erasure.Fix: Remove the special case for single-element results and always use
replaceOpWithNewOpAndCopyNamehint<ConcatOp>, which performs atomic operation creation and replacement. Single-operand ConcatOps are automatically optimized away by theConcatOpfolder (line 1726-1727 returnsgetOperand(0)for single operand).Test plan
extractCatOnSinglePartialElementintest/Dialect/Comb/canonicalization.mlir:460-472covers the crash scenario