[cfe-dev] Why no NSW/NUW with SHL instruction?

David Chisnall David.Chisnall at cl.cam.ac.uk
Fri Nov 21 09:54:46 PST 2014

On 21 Nov 2014, at 17:39, Ryan Taylor <ryta1203 at gmail.com> wrote:

> I don't care if clang only produces shl, I'm more curious how to get the signed info to the backend for shl when it's not producing a nsw/nuw flag? I'm currently not sure how this would be done, is there another arch that manages this somehow?

I think the point is that the only difference between the two is the overflow flag, which is not something that C exposes, and LLVM IR tends to be driven by the needs of the front ends.  

If you wanted an IR instruction that represented a left shift that set a flag, then you'd need something that returned both the result and the overflow flag (look at the existing overflow checked addition intrinsics for inspiration).  This sort of thing tends only to be added when someone needs it.  If the first someone to need it is you, then... patches welcome.  I think that you'd probably want to implement it as a shift-with-overflow intrinsic rather than a variation on the shl instruction and you'd probably need to provide some expansion for it for processors that don't have a direct mapping.


More information about the cfe-dev mailing list