Sequence of same shift instructions with constant operands can be combined into
a single shift instruction.
Details
Diff Detail
Event Timeline
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
1551–1553 | Change to assert(). | |
1562 | I don't think Shl2Def can ever be null here, can it? | |
1588 | "Imm" instead of "MatchInfo.Imm" | |
1588 | Logically you want the size of the first operand here, not the size of the immediate. I'm not sure if they are guaranteed to be the same. | |
1595 | Typo "than". |
- Addressed review comments.
- Updated comment at the start of match function.
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
1562 | I guess if the MIR is valid it should never be null. This match is the very similar to the one above (matchPtrAddImmedChain). |
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
1590 | This is undefined, not 0. I don't think this needs to specially consider this case |
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
1590 | No, this is handling cases like X >> 20 >> 25 where the sum (20 + 25) exceeds the width of the type. |
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
1596–1597 | You could also handle G_USHLSAT and G_SSHLSAT the same way as G_ASHR. |
- Using RegisterImmPair, removed ShiftChain struct.
- Supported G_SSHLSAT and G_USHLSAT.
- Added .mir tests
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
1592–1594 | This is wrong. With 8-bit ints: |
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
1596–1597 | Sorry, I was wrong about G_USHLSAT. You can't handle it quite the same way as G_ASHR. With 8-bit ints: If the combined shift amount for ushlsat is >= 8 then you could replace it with "x == 0 ? 0 : 0xff" but it's probably not worth doing this. |
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
1587 | Shouldn't construct a new MachineIRBuilder here |
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
1599 | I think you mean "saturating signed or unsigned left shift" here. But this does not work for saturating unsigned left shift. There is no good replacement for "x ushlsat 20 ushlsat 25" where 20 + 25 exceeds the width of the type. I suggest catching this case in the match func and returning false. |
LGTM modulo minor comment inline.
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
1577–1578 | The comment could be improved. (What you wrote is also true of all the other shifts.) How about "there is no simple replacement for a saturating unsigned left shift that exceeds the scalar size"? |
Can't this just reuse RegisterImmPair?