This is an archive of the discontinued LLVM Phabricator instance.

[llvm-reduce] Fix incorrect indices in argument reduction pass
ClosedPublic

Authored by arichardson on Jul 18 2020, 7:08 AM.

Details

Summary

The function extractArgumentsFromModule() was passing a one-based index to,
but replaceFunctionCalls() was expecting a zero-based argument index. This
resulted in assertion errors when reducing function call arguments with
different types. Additionally, the

Diff Detail

Event Timeline

arichardson created this revision.Jul 18 2020, 7:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2020, 7:08 AM
lebedev.ri added inline comments.
llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
83–86

Let's take this one step further, shall we?

std::set<int> ArgIndexesToKeep;
for (auto &Arg : enumerate(F->args()))
  if (ArgsToKeep.count(&Arg.value()))
    ArgIndexesToKeep.insert(Arg.index());
arichardson marked an inline comment as done.Jul 18 2020, 8:05 AM
arichardson added inline comments.
llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp
83–86

Yes, much better! I realized just after submitting this patch that the index is not always being incremented so my non-minimal test case still crashed. Will add a better test case.

Fix missing increment using @lebedev.ri's suggestion
Improve test case to crash without this change.

arichardson retitled this revision from [llvm-reduce] Fix off-by one in argument reduction pass to [llvm-reduce] Fix incorrect indices in argument reduction pass.Jul 19 2020, 8:27 AM
arichardson edited the summary of this revision. (Show Details)
lebedev.ri accepted this revision.Jul 19 2020, 8:42 AM

LG, thank you.

llvm/test/Reduce/remove-args-2.ll
5

I guess i will indeed have to cleanup all the existing tests :S

This revision is now accepted and ready to land.Jul 19 2020, 8:42 AM
This revision was automatically updated to reflect the committed changes.
dblaikie added inline comments.Jul 20 2020, 1:55 PM
llvm/test/Reduce/remove-args-2.ll
4–5

Sorry I've only been watching this work superficially - but it looked like some other patches were moving towards using FileCheck directly (as the test program) for new llvm-reduce tests? Could that be done here too?

arichardson marked an inline comment as done.Jul 20 2020, 11:25 PM
arichardson added inline comments.
llvm/test/Reduce/remove-args-2.ll
4–5

Yeah that would definitely work. I didn't do it here since the test I used as a baseline didn't and I was able to reuse the same script.

I can commit a follow-up change to use Filecheck for this test unless @lebedev.ri already has a change to clean up the existing tests.

lebedev.ri added inline comments.Jul 20 2020, 11:58 PM
llvm/test/Reduce/remove-args-2.ll
4–5

I can commit a follow-up change to use Filecheck for this test

Please feel free to. See latest tests i've added for examples.

arichardson marked 2 inline comments as done.Jul 21 2020, 1:05 AM
arichardson added inline comments.
llvm/test/Reduce/remove-args-2.ll
4–5