[AggressiveInstCombine] Fold consecutive loads with a common variable shift
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
`foldConsecutiveLoads()` currently handles consecutive loads when each loaded value is shifted by a constant amount.
It does not recognize equivalent patterns where the shifts share a common variable base:
```llvm
%v0 = load i8, ptr %p0
%v1 = load i8, ptr %p1
%v2 = load i8, ptr %p2
%v3 = load i8, ptr %p3
%z0 = zext i8 %v0 to i64
%z1 = zext i8 %v1 to i64
%z2 = zext i8 %v2 to i64
%z3 = zext i8 %v3 to i64
%s1 = add i64 %shift, -8
%s2 = add i64 %shift, -16
%s3 = add i64 %shift, -24
%a0 = shl i64 %z0, %shift
%a1 = shl i64 %z1, %s1
%a2 = shl i64 %z2, %s2
%a3 = shl i64 %z3, %s3
```
The shift amounts still have a constant stride and could be represented as a common shift plus constant offsets.
It would be useful for `foldConsecutiveLoads()` to recognize this form so that the byte loads can be combined into a wider load.
This is one of the transformations required for the real-world case in #201107.
Contributor guide
Assessment
This issue has not been assessed yet.