I'm submitting code on the behalf of aykevl which is the author of this patch -
the original commit message[1] says:
I wrote a late IR pass a while ago to replace non-constant shift operations with a constant shift in a loop (see https://reviews.llvm.org/D96677). This worked, but wasn't optimal and there is a possibility later passes could again re-introduce such shift operations. But as a stopgap, it worked well enough. Now that constant 32-bit shift operations are optimized in a later stage, we can use the same code to lower shift operations to loops. This patch removes that IR pass and replaces it with one that runs during ISel lowering, like the constant shift operations. I did not expect this to affect binary size in any significant way, but apparently it does. The compiler-rt library (when compiled inside TinyGo) becomes 1.8% smaller, and picolibc becomes 0.4% smaller. That's a nice win for what was intended to be mostly just a refactor.
Issue fixed here was discovered in rustc[2] and I can confirm that this patch
fixes the problem; using simavr I've checked the left- and right-shifts, and
the rest of integer math operations, and everything seems to work as intended.
Since aykevl mentioned that they are not currently working on the AVR
backend[1], please let me know if anything can / should be adjusted here and
I'll do my best :-)
[1] https://github.com/rust-lang/compiler-builtins/issues/523#issuecomment-1500734938
[2] https://github.com/rust-lang/compiler-builtins/issues/523, https://github.com/rust-lang/rust/issues/112140
clang-format not found in user’s local PATH; not linting file.