This is an archive of the discontinued LLVM Phabricator instance.

IR: Fix use-list-order round-tripping for call and invoke
ClosedPublic

Authored by dexonsmith on Jun 23 2021, 11:31 AM.

Details

Summary

Fix the use-list-order for call and invoke instructions by setting the
operands in order of their index. This matches the use-list-order
prediction. Note that the verifier precludes sharing arguments in
callbr, but I updated the code there as well for consistency.

Bug was found during review of https://reviews.llvm.org/D104740.

Diff Detail

Event Timeline

dexonsmith created this revision.Jun 23 2021, 11:31 AM
dexonsmith requested review of this revision.Jun 23 2021, 11:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2021, 11:31 AM

Can you please point me to the code where the use-list order prediction is made?

Minor update to the testcase:

  • Match the RUN: commands from uselistorder.ll.
  • Rename to call-arg-is-callee.ll, since this is not testing the uselistorder directive... it's testing calls that have an argument as a callee.

Can you please point me to the code where the use-list order prediction is made?

The relevant code for AsmWriter is:
https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/AsmWriter.cpp#L232

// LID and RID are equal, so we have different operands of the same user.
// Assume operands are added in order for all instructions.
if (GetsReversed)
  if (LID <= ID)
    return LU->getOperandNo() < RU->getOperandNo();
return LU->getOperandNo() > RU->getOperandNo();

I'll need a minute to find it for BitcodeWriter.

Can you please point me to the code where the use-list order prediction is made?

I'll need a minute to find it for BitcodeWriter.

Found it in ValueEnumerator.cpp:
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp#L249

// LID and RID are equal, so we have different operands of the same user.
// Assume operands are added in order for all instructions.
if (LID <= ID)
  if (!IsGlobalValue) // GlobalValue uses don't get reversed.
    return LU->getOperandNo() < RU->getOperandNo();
return LU->getOperandNo() > RU->getOperandNo();

Note that we could update the code in ValueEnumerator and AsmWriter instead, but IMO it's simpler to just assign the operands in order of index in the first place.

nikic accepted this revision.Jun 23 2021, 12:01 PM

Thanks for the references! I agree that this is the better way to fix it, so LGTM.

This revision is now accepted and ready to land.Jun 23 2021, 12:01 PM
This revision was landed with ongoing or failed builds.Jun 23 2021, 12:06 PM
This revision was automatically updated to reflect the committed changes.