This is an archive of the discontinued LLVM Phabricator instance.

RegBankSelect: Fix copy insertion point for terminators
ClosedPublic

Authored by arsenm on Dec 18 2018, 5:54 PM.

Details

Summary

If a copy was needed to handle the condition of brcond, it was being
inserted before the defining instruction. Add tests for iterator edge
cases.

I find the existing code here suspect for the case where it's looking
for terminators that modify the register. It's going to insert a copy
in the middle of the terminators, which isn't allowed (it might be
necessary to have a COPY_terminator if anybody actually needs this).

Also legalize brcond for AMDGPU.

Diff Detail

Event Timeline

arsenm created this revision.Dec 18 2018, 5:54 PM

Hi Matt,

I find the existing code here suspect for the case where it's looking for terminators that modify the register. It's going to insert a copy in the middle of the terminators, which isn't allowed (it might be necessary to have a COPY_terminator if anybody actually needs this).

This patch does not address that part right?
And I agree, this is wrong, we would need to do some basic block splitting.

Looking back at this code, I wonder if instead of being "clever" about the placement of split point we shouldn't always put then right after the definition of the related instruction and let the machine sinking do the right placement.

Cheers,
-Quentin

lib/CodeGen/GlobalISel/RegBankSelect.cpp
727

Add a comment that at this point we are sure to be right before the first terminator.

arsenm updated this revision to Diff 179186.Dec 20 2018, 3:47 PM

Assert if a copy is needed between terminators

Hi Matt,

I find the existing code here suspect for the case where it's looking for terminators that modify the register. It's going to insert a copy in the middle of the terminators, which isn't allowed (it might be necessary to have a COPY_terminator if anybody actually needs this).

This patch does not address that part right?

No, I switched it to an assert in version 2

And I agree, this is wrong, we would need to do some basic block splitting.

Looking back at this code, I wonder if instead of being "clever" about the placement of split point we shouldn't always put then right after the definition of the related instruction and let the machine sinking do the right placement.

I thought about this, but figured since in this case it's most likely for not really copyable condition registers it might end up being problematic

qcolombet accepted this revision.Dec 20 2018, 4:34 PM

I thought about this, but figured since in this case it's most likely for not really copyable condition registers it might end up being problematic

Good point. Also we have to potentially deal with physical registers (because of ABI constraints for instance) and I think the idea was to keep the live-ranges as small as possible when repairing.

Something that occurred to me is that originally I planned to declare an insertion point between two terminators as being a split point (using InsertionPoint::HasSplit). I gave up on the idea because

  1. I didn't have a use case
  2. The APIs for querying the terminators are actually clunky and don't allow to properly update the successors list.

See the comments in InstrInsertPoint::materialize if you're curious, but that would be the right way of doing IMHO.

Anyway, LGTM.

Cheers,
-Quentin

This revision is now accepted and ready to land.Dec 20 2018, 4:34 PM
arsenm closed this revision.Jan 7 2019, 5:26 PM

r350595