[LLVMdev] nsw/nuw for trunc

John McCall rjmccall at apple.com
Thu Aug 11 10:34:35 PDT 2011


On Aug 11, 2011, at 7:31 AM, Florian Merz wrote:
> If we had nsw and nuw flags for truncations we'd know when to check for this 
> kind of overflow and when not. The compiler likely doesn't need these flags and 
> can still ignore them, for us they would be useful.

Duncan's point is that this is totally different from the semantics of
nsw/nuw on other instructions, which means it would be
inappropriate to reuse nsw/nuw.  That's especially true because
knowing that a trunc is nsw/nuw would be very useful to a lot of
clients — the only problem is that nobody can think of any languages
or situations where truncations actually have undefined behavior
semantics.

You should probably just modify your frontend to emit explicit range
checks in the cases you want.

John.



More information about the llvm-dev mailing list