Generally speaking, we lower to an optimal rotate sequence for nodes visible in the SDAG. However, there are instances where the two rotates are not visible at ISEL time - most notably those in a very common sequence when lowering switch statements to jump tables.
A common situation is a switch on a 32-bit integer. This value has to have the upper 32 bits cleared and because jump table offsets are word offsets, the value needs to be shifted left by 2 bits. We currently emit the clear and the left shift as two separate instructions, but this is not needed as we can lower it to a single RLDIC.
This patch just cleans that up.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Cleaned up the comments and the MB parameter for RLDIC does not need to include the shift that was originally on the RLDICL.
The patch does what we want it to do in most cases (including the example that motivated it) but some boundary conditions need to be considered before it is safe in all cases.
lib/Target/PowerPC/PPCMIPeephole.cpp | ||
---|---|---|
51 | nit: | |
785 | The value for NewMB can be negative. %1:g8rc = RLDICL %0, 10, 1 %2:g8rc = RLDICR %1, 10, 43 In this case NewMB = -9 We may still be able to handle the negative case (because this is a rotate) but it may require another if statement and special handling. | |
793 | The value for (63 - NewSH) can also be negative and I think it needs to be a special case. | |
test/CodeGen/PowerPC/collapse-rotates.mir | ||
53 | Had to delete this line on the machine I was running on to get this test to pass... error: YAML:53:23: unknown key 'machineFunctionInfo' machineFunctionInfo: {} I'm not sure what the issue is here but I feel like that line is not universally supported. |
lib/Target/PowerPC/PPCMIPeephole.cpp | ||
---|---|---|
51 | Good catch, thanks. | |
793 | These are very good points. I will add a check to bail out if either NewMB or NewSH are larger than 63. | |
test/CodeGen/PowerPC/collapse-rotates.mir | ||
53 | I am not sure what that's about. Perhaps you were on an older revision where that wasn't part of MIR? |
Added a check for wrapping in the computation of the new shift amount and mask start bit.
LGTM.
The one very minor comment I have I think can be addressed on commit.
test/CodeGen/PowerPC/collapse-rotates.mir | ||
---|---|---|
53 | I have tried to reproduce this since but I have not been able to. I would say don't worry about this. | |
test/CodeGen/PowerPC/jump-tables-collapse-rotate.ll | ||
3 | nit: |
nit:
collapsed