This is an archive of the discontinued LLVM Phabricator instance.

[MachineCombiner] Update iterator while deleting instructions
Needs ReviewPublic

Authored by DarshanRamakant on Feb 5 2022, 10:27 PM.

Details

Summary

This change will fix the accidental deletion of the instruction
which is pointed by the instruction iterator of the current MBB.

Diff Detail

Event Timeline

DarshanRamakant requested review of this revision.Feb 5 2022, 10:27 PM
craig.topper added a subscriber: craig.topper.EditedFeb 6 2022, 12:30 AM

Test case?

Test case?

Test case?

I did not find any existing test case which specifically tests the "insertDeleteInstructions()" function. Also, I did not find MIR test cases with many of the previous commits. Please provide me with some pointers on testing this specific change. I found this issue when experimenting with this transform for my company-specific backend.

arsenm added a comment.Feb 6 2022, 6:37 AM

I did not find any existing test case which specifically tests the "insertDeleteInstructions()" function. Also, I did not find MIR test cases with many of the previous commits. Please provide me with some pointers on testing this specific change. I found this issue when experimenting with this transform for my company-specific backend.

I would hope there were at least some IR tests in previous commits touching this pass. Perhaps you can use -stop-after to get a MIR starting point on one of them, and manually modify the MIR until it breaks?

I did not find any existing test case which specifically tests the "insertDeleteInstructions()" function. Also, I did not find MIR test cases with many of the previous commits. Please provide me with some pointers on testing this specific change. I found this issue when experimenting with this transform for my company-specific backend.

I would hope there were at least some IR tests in previous commits touching this pass. Perhaps you can use -stop-after to get a MIR starting point on one of them, and manually modify the MIR until it breaks?

Thanks for the suggestion. Let me try that approach.

I did not find any existing test case which specifically tests the "insertDeleteInstructions()" function. Also, I did not find MIR test cases with many of the previous commits. Please provide me with some pointers on testing this specific change. I found this issue when experimenting with this transform for my company-specific backend.

I would hope there were at least some IR tests in previous commits touching this pass. Perhaps you can use -stop-after to get a MIR starting point on one of them, and manually modify the MIR until it breaks?

Thanks for the suggestion. Let me try that approach.

I have tried to add a test case by tweaking existing ll tests. But the existing overloads of this transform will not hit this case since they always delete instructions that are previous to "Root". But nobody is stopping clients of this transform to mark currently pointed instruction as a to be deleted instruction. It has become very tricky to hit this case with a test. Please let me know how to proceed further.

arsenm added inline comments.Feb 21 2022, 6:13 PM
llvm/lib/CodeGen/MachineCombiner.cpp
489

Typo cuurent

492

I've never looked at this pass before, but this looks like a strange structure. Why can't this pre-increment the iterator before making changes to the function?

llvm/lib/CodeGen/MachineCombiner.cpp
489

Thanks will fix it.

492

BlockItr will be pointing to the next instruction to be processed. If the instruction marked for delete happens to be exactly that, then line 570 will become a dangling pointer and will have an undefined behavior.

Herald added a project: Restricted Project. · View Herald TranscriptNov 16 2022, 3:13 PM