This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Narrow 128-bit regs to 64-bit regs in emitTestBit
ClosedPublic

Authored by paquette on Dec 4 2020, 4:15 PM.

Details

Summary

When we have a 128-bit register, emitTestBit would incorrectly narrow to 32 bits always. If the bit number was > 32, then we would need a TB(N)ZX. This would cause a crash, as we'd have the wrong register class. (PR48379)

This generalizes narrowExtReg into narrowOrWidenScalarIfNeeded.

This also allows us to remove widenGPRBankRegIfNeeded entirely, since selectCopy correctly handles SUBREG_TO_REG etc.

This does create some codegen changes (since selectCopy uses the all regclass variants). However, I think that these will likely be optimized away, and we can always improve the selectCopy code.

Diff Detail

Event Timeline

paquette created this revision.Dec 4 2020, 4:15 PM
paquette requested review of this revision.Dec 4 2020, 4:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2020, 4:15 PM

Thanks, Jessica!

lanza added a subscriber: tstellar.Dec 4 2020, 4:29 PM
aemerson added inline comments.Dec 4 2020, 11:46 PM
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
5650

This function is confusing to me now. It's called narrowOrWidenScalar but no actual widening or narrowing happens. If selectCopy really does handle these then I think we need a comment explaining that. Also, maybe this could be renamed to something like moveToGPRRegClass()? I'm not sure if it's better though. What do you think?

Can you also check if there's any code size impact at -O0 and -Os. I'm wary of regressing -O0 and leaving extra unnecessary moves around.

paquette added inline comments.Dec 7 2020, 9:39 AM
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
5650

Maybe just moveToRegClass?

With -O0 and -Os on CTMark, there is no change in size.__text.

aemerson accepted this revision.Dec 7 2020, 11:21 AM
aemerson added inline comments.
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
5650

It doesn't handle vectors so I think having some reference to scalar or GPR is needed. I'll leave it up to you for the exact name.

This revision is now accepted and ready to land.Dec 7 2020, 11:21 AM