LSR reassociates constants as unfolded offsets when the constants fit as immediate add operands, which currently prevents such constants from being combined later with loop invariant registers.
This patch modifies GenerateCombinations() to generate a second formula which includes the unfolded offset in the combined loop-invariant register.
Could you reduce the test even more?
E.g., I usually had some success by adding an assert for the case that interests me and bugpoint on this specific assert (via custom script)
Could we check that the transformation looks good instead of checking the debug output?
Put differently can we write a test that works for release as well?