[PATCH] D54237: Constant folding and instcombine for saturating adds

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 9 10:49:11 PST 2018


bjope added a comment.

In https://reviews.llvm.org/D54237#1292144, @nlopes wrote:

> In https://reviews.llvm.org/D54237#1291405, @nikic wrote:
>
> > Regarding
> >
> >   // X + undef -> undef
> >   // undef + X -> undef
> >   if (match(Op1, m_Undef()) || match(Op0, m_Undef()))
> >     return UndefValue::get(ReturnType);
> >   
> >
> > I was initially planning to include these simplifications, but ultimately was not certain regarding their legality. In particular, if we have uadd.sat(MaxValue, Y), then the result is fully determined to be MaxValue, regardless of the value of Y. If we have something like sadd.sat(SignedMinValue, Y) then the result is known to be negative. In either case the intrinsic cannot have the full range of results of the result type, regardless of the value of Y. As such, I think folding operations on undef to undef would not be legal in this case.
> >
> > It should be possible to fold uadd.sat(X, undef) to MaxValue. Not sure how useful that is though.
>
>
> You can also assume that undef is 0 and fold X + undef -> X.


Is it perhaps "better" to fold `sadd_sat(X, undef) -> 0`` And `uadd_sat(X, undef) -> MaxValue` if we want to get rid of undef here? That way we get rid of the X operand as well.


https://reviews.llvm.org/D54237





More information about the llvm-commits mailing list