[LLVMdev] On semantics of add instruction - nsw,nuw flags
Andrew Trick
atrick at apple.com
Thu Jul 24 15:05:04 PDT 2014
> On Jul 23, 2014, at 7:18 AM, Rekha R <rekharamapai at nitc.ac.in> wrote:
>
> Hi Tim,
> If:
> It means that the person who wrote the IR has guaranteed that there's
> no overflow (by some means) so LLVM can assume it during optimisation.
> then
> In both cases the add with nsw can be removed in favour of the one
> without. Order is completely irrelevant for normal LLVM arithmetic
> instructions.
>
> why can't we retain add nsw and remove add (in the example Cases)? Because there is a guarantee overflow wouldn't occur.
You can’t do this because the add’s have a different set of uses. This is valid IR modulo any typos I make:
%safeidx = add nsw i32 %a, %b
%idx = add i32 %a, %b
%cmp = cmp <some condition that guarantees no overflow>
br i1 %cmp, label %maynotoverflow, label %mayoverflow
maynotoverflow:
%p = getelementptr inbounds i32* %o, i32 %idx
load i32* %p
mayoverflow:
sext i32 %idx to i64
—
That’s why we need the concept of a “poison” value.
-Andy
>
> Thanks,
> --
> Rekha
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list