This is an archive of the discontinued LLVM Phabricator instance.

[RegUsageInfoCollector] Don't assume the alias of a defined reg is always already in the set.
ClosedPublic

Authored by jonpa on Apr 2 2018, 2:41 AM.

Details

Summary

As the test case in https://bugs.llvm.org/show_bug.cgi?id=36587 discovered, it is wrong to assume that all the aliases of the defined register in the *current function* is already present in the UsedPhysRegsMask.

This patch changes this so that any definition in the current function of a phys-reg always results in all its aliases inserted into the set of defined registers.

Diff Detail

Event Timeline

jonpa created this revision.Apr 2 2018, 2:41 AM
jonpa removed a subscriber: uweigand.
fhahn added a subscriber: fhahn.Apr 16 2018, 2:51 AM

I am not sure I like the patch in the sense that the comment for UsedPhysRegsMask (in ’MachineRegisterInfo.h) explicitly said that it should contain all the aliases.

So either, we change this assumption (which that patch does) and we update the patch to change the comment *and* we make sure it does not break anything else if other targets start to not put the aliases in that set, or we fix that target to add the aliases when it creates the set.

From a high level point of view, it looks riskier to take the first approach. Can't we change the code that set this mask in SystemZ?

@jonpa from the PR, I didn't get if the mask was "wrong" before RegCollectUsage starts or if it is RegCollectUsage that fails to update it. IIRC, RegCollectUsage does not change UsedPhysRegsMask, so I was assuming the state was wrong to begin with.

jonpa added a comment.Apr 28 2018, 9:16 AM

I am not sure I like the patch in the sense that the comment for UsedPhysRegsMask (in ’MachineRegisterInfo.h) explicitly said that it should contain all the aliases.

/// UsedPhysRegMask - Additional used physregs including aliases.                                                                                                                                                              
/// This bit vector represents all the registers clobbered by function calls.                                                                                                                                                  
BitVector UsedPhysRegMask;

I read this not as all aliases of all registers are included, but merely those actually clobbered. In the test case, fn1 clobbers %r0l, so %r0l and it's aliases (%r0d and %r0q) are also in UsedPhysRegMask. However, %r0h is *not* clobbered (the other subreg of %r0d).

So either, we change this assumption (which that patch does) and we update the patch to change the comment *and* we make sure it does not break anything else if other targets start to not put the aliases in that set, or we fix that target to add the aliases when it creates the set.

From a high level point of view, it looks riskier to take the first approach. Can't we change the code that set this mask in SystemZ?

@jonpa from the PR, I didn't get if the mask was "wrong" before RegCollectUsage starts or if it is RegCollectUsage that fails to update it. IIRC, RegCollectUsage does not change UsedPhysRegsMask, so I was assuming the state was wrong to begin with.

My understanding is that when RegInfoUsageCollector looks at @fn1, it only adds %r0l (and superregs), but not %r0h. @fn1 only clobbers %r0l. @fn2 however does clobber %r0d, which is already in the set after visiting @fn1. So here it is not true that all aliases of %r0d are in the set!

I am not aware that the backend should set this mask somehow, I have so far assumed that it is the RegCollectUsage/Propagate passes that sets the call regmask.

Perhaps we should change the comment to "... including clobbered aliases..." ?

qcolombet accepted this revision.May 3 2018, 3:48 PM

You're right, re-reading the comment indeed, not all the aliases are here (nor should they be!).

test/CodeGen/SystemZ/ipra.ll
15

Nit: Please use opt -instnamer to get rid of the implicit variables

This revision is now accepted and ready to land.May 3 2018, 3:48 PM
jonpa closed this revision.May 4 2018, 12:54 AM
jonpa marked an inline comment as done.

Thanks for review.

r331509.