This is an archive of the discontinued LLVM Phabricator instance.

[MachineVerifier] Use the for Range loop to instead llvm::any_of
ClosedPublic

Authored by ZhangKang on May 13 2020, 8:46 AM.

Details

Summary

In the patch https://reviews.llvm.org/D78849, it uses llvm::any_of to instead of for loop to simplify the function addRequired ():
Below function

bool addRequired(const RegSet &RS) {
   bool changed = false;
   for (RegSet::const_iterator I = RS.begin(), E = RS.end(); I != E; ++I)
     if (addRequired(*I))
       changed = true;
   return changed;
}

will be simplified to:

bool addRequired(const RegSet &RS) {
     return llvm::any_of(
         RS, [this](unsigned Reg) { return this->addRequired(Reg); });
}

It's obvious that above code is not a NFC conversion. Because any_of will return if any addRequired(Reg) is true immediately, but we want all element to call addRequired(Reg).

This bug has caused 248 cases error for the Machine Verfication of LiveVariable pass.
This patch uses for range loop to fix llvm::any_of bug.

Diff Detail

Event Timeline

ZhangKang created this revision.May 13 2020, 8:46 AM
ZhangKang edited the summary of this revision. (Show Details)May 13 2020, 8:48 AM
ZhangKang added a reviewer: nickdesaulniers.
ZhangKang edited the summary of this revision. (Show Details)May 13 2020, 8:56 AM
MaskRay added inline comments.May 13 2020, 9:08 AM
llvm/lib/CodeGen/MachineVerifier.cpp
172

s/const auto &/unsigned/

nickdesaulniers accepted this revision.May 13 2020, 9:32 AM

My mistake. Thanks for the fix.

This revision is now accepted and ready to land.May 13 2020, 9:32 AM
ZhangKang updated this revision to Diff 263762.May 13 2020, 9:54 AM

Modify const auto &I to unsigned Reg.

ZhangKang marked 2 inline comments as done.May 13 2020, 9:55 AM
ZhangKang added inline comments.
llvm/lib/CodeGen/MachineVerifier.cpp
172

Done.

MaskRay accepted this revision.May 13 2020, 10:18 AM

Thanks!

nickdesaulniers accepted this revision.May 13 2020, 10:18 AM

This bug has caused 248 cases error for the Machine Verfication of LiveVariable pass.

It might be good to add a test case that exercising this code.

ZhangKang marked an inline comment as done.May 13 2020, 6:05 PM

This bug has caused 248 cases error for the Machine Verfication of LiveVariable pass.

It might be good to add a test case that exercising this code.

The existed bug will exposed if we use EXPENSIVE_CHECKS and enable the machine verification for LiveVariable pass.
Unfortunately, we can't enable machine verification for LiveVariable pass now, because this machine verification pass has other bugs.
This is why we didn't find this bug before, so there is no case until we fix all bug of machine verification for LiveVariable pass and enable it.

ZhangKang updated this revision to Diff 263904.May 13 2020, 6:12 PM

Fix the format.

This comment was removed by ZhangKang.
This revision was automatically updated to reflect the committed changes.