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

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 8 01:59:57 PST 2018


bjope added a comment.

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.


Ok, I did not really think about it that way, but you definitely got a point there.
But for example, sadd.sat(undef, undef) can still be folded to undef, right?
Anyway, I'm not sure how important folds involving undef are here at all. I just noticed that undef was handled for sadd_with_overflow etc, and figured we needed it for "completeness".


Repository:
  rL LLVM

https://reviews.llvm.org/D54237





More information about the llvm-commits mailing list