This is an archive of the discontinued LLVM Phabricator instance.

Ignore modified attribute list if it yields invalid IR
ClosedPublic

Authored by Nirhar on Jul 3 2023, 7:11 AM.

Details

Summary

If modified attribute list is invalid, reverting the change is a
low-cost maintainence solution as compared to examples like
this.
This will ensure that the ListReducer maintains the sanctity of any
new attribute dependencies added in the future/already present.

Diff Detail

Event Timeline

Nirhar created this revision.Jul 3 2023, 7:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 3 2023, 7:11 AM
Nirhar requested review of this revision.Jul 3 2023, 7:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 3 2023, 7:11 AM

Unfortunately, I haven't touched this code since about 2004. @modocache I see you've touched this somewhat more recently, can you take a look at this?

lattner edited reviewers, added: modocache; removed: lattner.Jul 3 2023, 2:19 PM
lattner added a subscriber: lattner.Jul 3 2023, 2:22 PM
lattner added inline comments.
llvm/tools/bugpoint/CrashDebugger.cpp
386

Can you use llvm::verifyModule instead of running the pass?

Nirhar added inline comments.Jul 4 2023, 7:47 AM
llvm/tools/bugpoint/CrashDebugger.cpp
386

Other parts of the CrashDebugger run the pass to verify llvm IR, hence I kept it the same. Let me know if I should still change to llvm::verifyModule.

Nirhar marked an inline comment as not done.Jul 4 2023, 7:47 AM
modocache added inline comments.Jul 4 2023, 12:55 PM
llvm/tools/bugpoint/CrashDebugger.cpp
386

You bring up a good point, @Nirhar -- there's actually a lot of duplication in this file. I count 7 spots where the verifier pass is run, and this makes 8! Here's an example: https://github.com/llvm/llvm-project/blob/b4b532a9562a1ebca347edc566363fba0531115b/llvm/tools/bugpoint/CrashDebugger.cpp#L512-L520

I agree that it would be nicer to use llvm::verifyModule here; it accomplishes the same thing, but in a much simpler way.

(And, I think it would be even better, in a separate patch, to change the other 7 spots to use verifyModule too -- and, ideally, have them print "verify failed!" and exit, like many of them seem to do.)

modocache added inline comments.Jul 4 2023, 1:14 PM
llvm/tools/bugpoint/CrashDebugger.cpp
386

ideally, have them print "verify failed!" and exit, like many of them seem to do

Sorry, typo here. I meant to write that it would be nice to 1) have these other spots use verifyModule, AND 2) unify them with a static helper function or something, such that we had one function that could verify a module and print "verify failed!" if verification failed. Right now that logic is duplicated a ton in this file.

arsenm added a subscriber: arsenm.Jul 4 2023, 2:37 PM
arsenm added inline comments.
llvm/tools/bugpoint/CrashDebugger.cpp
386

It would be easier yet to just delete bugpoint altogether and switch to using llvm-reduce. The attribute reducer there takes care to avoid introducing invalid attribute combinations

but bugpoint has a waaay cuter name than llvm-reduce! :-)

Nirhar added inline comments.Jul 5 2023, 12:25 AM
llvm/tools/bugpoint/CrashDebugger.cpp
386

I agree with you, let me refactor the code and then update the diff to incorporate your suggestions.

Nirhar marked an inline comment as not done.Jul 5 2023, 12:25 AM
Nirhar updated this revision to Diff 537433.EditedJul 5 2023, 10:59 AM

Code Refactor
Used llvm::verifyModule to verify modules modified by CrashDebugger
Introduced function isValidModule to verify correctness of IR, for
the needs of CrashDebugger.

Please have a look at these changes.

Changing from running verification passes to llvm::verifyModule leads to the failure of the following test: Bugpoint/invalid-debuginfo.ll. I'm currently trying to understand why its failing.

modocache requested changes to this revision.Jul 5 2023, 11:16 AM

Looks great!! Thank you for also updating the other call sites. I had a few additional comments, but once those are taken care of I can accept. (When I do, will you need me to merge this commit on your behalf?)

llvm/tools/bugpoint/CrashDebugger.cpp
73

Please run clang-format on this patch; I can tell from some of the spacing here that this is not typical formatting. I believe clang-format should format this as static bool isValidModule(std::unique_ptr<Module> &M, bool exitOnFailure = true) {. There may be other formatting changes that would be applied to other parts of your patch as well.

Also, there's a mix of capitalization conventions here. I believe the Coding Standards here -- https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly -- would have you name this ExitOnFailure, with a capital 'E'.

74

I believe you don't need the parentheses here.

75

I think this would be a little simpler if you checked the inverse:

if (!llvm::verifyModule(*M.get(), &llvm::errs()))
  return true;

if (ExitOnFailure) {
  llvm::errs() << "verify failed!\n";
  exit(1);
}
return false;

This removes a lot of nesting in your if statements, and I think looks nicer.

795

No need to update this comment, IMHO.

796

I believe this should use ExitOnFailure = false, right?

865

Same as above; I don't believe this comment should change. Same goes for the 2 spots below in this patch.

866

Same as above; I believe the previous behavior was to not exit. Same goes for the 2 spots below in this patch.

This revision now requires changes to proceed.Jul 5 2023, 11:16 AM
Nirhar updated this revision to Diff 538182.Jul 7 2023, 10:03 AM

Refactor code with clang format

Nirhar marked 7 inline comments as done.Jul 7 2023, 10:04 AM

Please have a look at these changes.

@modocache Can you please merge this commit on my behalf once you are satisfied with the changes?

modocache accepted this revision.Jul 10 2023, 9:30 PM

Looks great, thanks!

Can you please merge this commit on my behalf once you are satisfied with the changes?

Sure thing!

This revision is now accepted and ready to land.Jul 10 2023, 9:30 PM
This revision was automatically updated to reflect the committed changes.