This is an archive of the discontinued LLVM Phabricator instance.

[TailDuplicator] Don't constrain register classes due to debug instructions
ClosedPublic

Authored by uabelho on Apr 25 2023, 4:56 AM.

Details

Summary

If cloning a DBG_VALUE instruction, register uses in that instruction could
lead to constraining of a virtual register that would not happen if the
DBG_VALUE was not present at all. This lead to different code with/without
debug info.

Now we only do that register class constraining if we dealing with a non
debug instruction.

Diff Detail

Event Timeline

uabelho created this revision.Apr 25 2023, 4:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 4:56 AM
uabelho requested review of this revision.Apr 25 2023, 4:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 4:56 AM

I don't know if this is the best fix for the problem but it does solve a case where we got different codegen with/without debug info present. Originally found for my out of tree target but I think the attached AArch64 testcase exposes the problem as well.

I'm also not sure who can review this. Added @kparzysz since I think you wrote the original code and @foad and @arsenm since I think I've seen you in other reviews of TailDuplicator.

foad added inline comments.Apr 25 2023, 5:05 AM
llvm/lib/CodeGen/TailDuplicator.cpp
434

Just a cosmetic thing, I'd prefer you swap the "if" and "else" cases so you don't have an "else" after an already negated condition.

uabelho updated this revision to Diff 516757.Apr 25 2023, 5:14 AM

Swap if/else according to comment.

uabelho marked an inline comment as done.Apr 25 2023, 5:14 AM
uabelho added inline comments.
llvm/lib/CodeGen/TailDuplicator.cpp
434

Sure, done!

arsenm accepted this revision.Apr 25 2023, 7:23 PM
arsenm added inline comments.
llvm/lib/CodeGen/TailDuplicator.cpp
434

ConstRC = isDebug ? MappedRC : MRI->constrain()?

Could you also just initialize ConstRC with MappedRC above?

This revision is now accepted and ready to land.Apr 25 2023, 7:23 PM
uabelho added inline comments.Apr 25 2023, 10:34 PM
llvm/lib/CodeGen/TailDuplicator.cpp
434

I guess initializing

const TargetRegisterClass *ConstrRC = Mapped;

plus then doing

if (!NewMI.isDebugInstr())
  ConstRC = MRI->constrainRegClass(VI->second.Reg, OrigRC);

would be the same thing.

I think I prefer just

ConstrRC = NewMI.isDebugInstr()
               ? MappedRC
               : MRI->constrainRegClass(VI->second.Reg, OrigRC);

though so I'll update the patch with that.

uabelho updated this revision to Diff 517059.Apr 25 2023, 10:35 PM

Change if/else to ? accordiing to review comment.

This revision was landed with ongoing or failed builds.Apr 25 2023, 11:22 PM
This revision was automatically updated to reflect the committed changes.