This sequence of instructions can be simplified if they are single use and
some operands are constants. Additional combines may be applied afterwards.
Details
Diff Detail
Unit Tests
Event Timeline
This patch is basically a global-isel version of combineShiftOfShiftedLogic() from DAGCombiner.
llvm/test/CodeGen/AMDGPU/GlobalISel/combine-shift-of-shifted-logic.ll | ||
---|---|---|
7–8 | This can be simplified to a single instruction: Same goes for a few more cases below. |
llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h | ||
---|---|---|
248–249 | I know you copied this comment from SelectionDAG but I think it really improves latency, not throughput, because the new shifts are independent. Also you don't mention the other reason for doing this, which is that one of the new shifts might constant-fold away. | |
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
1609 | Also handle G_USHLSAT and G_SSHLSAT? | |
1653–1656 | I don't see why this check is necessary. All we care about is the shift amount, as a uint64_t. | |
1664–1666 | First, it would be simpler to check this by line 1690 where you're already computing the sum. Second, I would expect the > to be >=. Third, you're comparing against BitWidth which is the width of the shift amount, not the value being shifted. | |
1700 | Don't create this. CombinerHelper already has a MIRBuilder. | |
1707 | ShlType is wrong here and below. You want the type of the result, not the type of the shift amount. | |
1717–1719 | It's probably not worth doing this. I think you can rely on dead code elimination. |
- Supported G_SSHLSAT and G_USHLSAT and addressed other comments.
- Added .mir test for G_SSHLSAT and G_USHLSAT.
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
1609 | Comment still needs updating. |
I know you copied this comment from SelectionDAG but I think it really improves latency, not throughput, because the new shifts are independent.
Also you don't mention the other reason for doing this, which is that one of the new shifts might constant-fold away.