-
Notifications
You must be signed in to change notification settings - Fork 13
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
Martien.kissfix #185
Conversation
// 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(); |
There was a problem hiding this comment.
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)))) { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
ec96e3c
to
dfbae40
Compare
if (!isPointerTypePHI(MRI, PhiA)) | ||
continue; | ||
auto PhiItB = PhiItA; | ||
for (++PhiItB++; PhiItB != End; ++PhiItB) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks interesting: ++PhiItB++
dfbae40
to
5c1a88b
Compare
I approved the competing PR |
dup phi elimination crashed in a supertest on a block with just two phi nodes