Bug 67691 - [SH] Omit zero extension of shift amounts for dynamic shifts
Summary: [SH] Omit zero extension of shift amounts for dynamic shifts
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-23 02:55 UTC by Oleg Endo
Modified: 2024-08-06 05:03 UTC (History)
0 users

See Also:
Host:
Target: sh*-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oleg Endo 2015-09-23 02:55:46 UTC
In CSiBE I've seen code that goes like this ...

left shift:
     mov.b    @(...),r0
     extu.b   r0,r1
     ...
     shld     r1,r2

right shift:
     mov.b    @(...),r0
     extu.b   r0,r1
     neg      r1,r1
     ...
     shld     r1,r2

In both cases the zero extension can be omitted.  The shld/shad shift count is truncated to a 5 bit and as per C/C++ standard shift counts > 31 or negative shift counts are undefined behavior for int32_t/uint32_t.

If a shift count value is loaded from memory and is not explicitly AND'ed with 31, it can be assumed that the value is in the range 0..31.

For example

value in mem      signed ext.  unsigned ext.
0...31            0...31       0...31           OK
33                33           33               NG
255               255          -1               NG

I can't think of a case where keeping the zero extension would avoid undefined behavior.