This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][transforms] Fix `cloneInto()` error in `RemoveDeadValues` pass

Authored by srishti-pm on Aug 26 2023, 11:08 AM.



This commit fixes an error in the RemoveDeadValues pass that is
associated with its incorrect usage of the cloneInto() function.

The setOperands() function that is used by the cloneInto() function
requires all operands to not be null. But, that is not possible in this
pass because we drop uses of dead values, thus making them null. It is
only at the end of the pass that we are assured that such null values
won't exist but during the execution of the pass, there could be null

To fix this, we replace the usage of the cloneInto() function to copy
a region with moveBlock() to move each block of the region one by one.
This function does not require the presence of non-null values and is
thus the right choice here. This implementation is also more opttimized
because we are moving things instead of copying them. The goal was
always moving.

Signed-off-by: Srishti Srivastava <>

Diff Detail

Event Timeline

srishti-pm created this revision.Aug 26 2023, 11:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2023, 11:08 AM
srishti-pm requested review of this revision.Aug 26 2023, 11:08 AM

I'm planning on accepting and landing this change soon because it is trivial and crucial.

Rebase to main.

srishti-pm accepted this revision.Aug 26 2023, 12:10 PM
This revision is now accepted and ready to land.Aug 26 2023, 12:10 PM

Did you get this reviewed? It's quite unexpected to see "self approved" patch (actually I didn't even know it was possible).

Also when you fix a GitHub issue, add Fixes #64997 to the commit message to automatically close the issue.


The temp block is a cute trick, but it clobbered the intent here, this is not the kind of idiom you will find in MLIR.

The right API here should be, I believe, newOp->getRegion(index).takeBody(region);

mehdi_amini added inline comments.Sep 25 2023, 1:57 PM

Ping here?

srishti-pm added inline comments.Sep 30 2023, 3:21 PM

I'm currently in school, busy with schoolwork. I will make this minor modification when I find time.