https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49263
--- Comment #34 from Oleg Endo <olegendo at gcc dot gnu.org> --- (In reply to Alexander Klepikov from comment #33) > Created attachment 55142 [details] > Disable dynamic shift instructions patch First of all, thanks for digging into this. This issue has been a can of worms, due to all sorts of reasons. As you have discovered, some code patterns take the shift instruction route, which is basically decided earlier by the various middle-end optimizations. There have also been some changes to those parts recently, but I haven't been watching what it does for SH. > unsigned int f(char v){ > return (v & FLAG) == FLAG; > } Bit-tests of char and unsigned char should be covered by the test-suite and should work -- at least originally. However, what might be triggering this problem is the '== FLAG' comparison. When I was working on this issue I only used '== 0' or '!= 0' comparison. I can imagine that your test code triggers some other middle end optimizations and hence we get this. Can you try to rewrite your test code to something like this? unsigned int f(char v){ return (v & FLAG) != 0; } ... and see if it generates the tst instruction as expected? > I also compiled my project with '-m2e' and new '-mdisable-dynshift' > options and tested it in SH-2E mone on Renesas's emulator that comes > with High-performance Embedded Workshop and all unit tests run as expected. I'm not sure what the purpose of the '-mdisable-dynshift' option would be here though. For '-m2e' TARGET_DYNSHIFT is already 'false'. So the option seems misnamed.