fold_shift rotates s_mask for rotl/rotr by a constant. For I32 the INT32_MIN OR in fold_masks_zosa_int can turn the result into a bogus sign mask, and the next sign extension is dropped (ARM sxtb; ror #1; sxtb, i386 movsbl; roll $31; movsbl). Patch 1 handles rotates like 5fe51606146 handled the logical right shift, patch 2 adds tests, patch 3 builds the test-i386-opt-shr test that the meson conversion dropped.
Found by differential testing of GCC output under qemu-arm. Tested: make check-tcg for arm, aarch64, i386 and x86_64 linux-user on 9c88811b81, 312/312 pass. The two new tests fail without patch 1. AI disclosure: these patches were prepared with an AI assistant (Claude, Anthropic); each commit carries an Assisted-by: trailer. I know docs/devel/code-provenance.rst declines such contributions and that checkpatch.pl rejects the trailer. I am sending them openly and leave acceptance to the maintainers. If they cannot be taken, please treat this as a bug report; the reproducers are in patch 1. Dominic P (3): tcg/optimize: Do not derive s_mask from rotated s_mask tests/tcg: Add tests for sign extension after rotate tests/tcg/i386: Build test-i386-opt-shr tcg/optimize.c | 7 +++++-- tests/tcg/arm/meson.build | 1 + tests/tcg/arm/test-arm-opt-ror.c | 21 +++++++++++++++++++++ tests/tcg/i386/meson.build | 2 ++ tests/tcg/i386/test-i386-opt-rol.c | 21 +++++++++++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/tcg/arm/test-arm-opt-ror.c create mode 100644 tests/tcg/i386/test-i386-opt-rol.c -- 2.55.0
