Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Martien.kissfix #185

Closed
wants to merge 3 commits into from
Closed

Martien.kissfix #185

wants to merge 3 commits into from

Conversation

martien-de-jong
Copy link
Collaborator

dup phi elimination crashed in a supertest on a block with just two phi nodes

// Ensure that next MI is valid
auto NextMI = std::next(MachineBasicBlock::instr_iterator(MI));
if (NextMI == MBB.instr_end() || NextMI == LastPHI)
const auto End = MBB.end();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are comparing every pointer PHI node in the block to any other pointer PHI node in that block. We know that all PHI nodes are consecutive at the start of the block. The transformation only changes operands in other instructions, so iterators stay intact. By writing the loops using basic iterator idiom reveals the symmetry between the two loops. It also avoids using constructs like .phis() and .getFirstNonPhi() that both perform exactly the same iteration as the main loops.

break;

for (auto &PHI : make_early_inc_range(make_range(
NextMI, MachineBasicBlock::instr_iterator(*LastPHI)))) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error was here. LastPHI was at .end(), which means you cannot dereference it to create an instr_iterator. Note that in that case the validity check reads if (NextMI == end || NextMI == end)

@@ -120,26 +120,26 @@ class AIEEliminateDuplicatePHI : public MachineFunctionPass {
bool processMBB(MachineBasicBlock &MBB, MachineRegisterInfo &MRI,
MachineIRBuilder &MIB, GISelObserverWrapper &Observer) {
bool Changed = false;
auto LastPHI = MBB.getFirstNonPHI();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would normally expect an iterator with this name to point to the last phi, not the the first non-phi.


bb.3:
%3:_(p0) = G_PHI %2:_(p0), %bb.1, %3:_(p0), %bb.2
%4:_(p0) = G_PHI %2:_(p0), %bb.1, %3:_(p0), %bb.2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just triggering the crash. These are equivalent phis, and the test can be strengthened by using %4 in a downstream block.

if (!isPointerTypePHI(MRI, PhiA))
continue;
auto PhiItB = PhiItA;
for (++PhiItB++; PhiItB != End; ++PhiItB) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks interesting: ++PhiItB++

@martien-de-jong
Copy link
Collaborator Author

I approved the competing PR

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.

2 participants