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

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 8 05:42:24 PST 2018


RKSimon added inline comments.


================
Comment at: lib/Support/APInt.cpp:1953
+  APInt Res = sadd_ov(RHS, Overflow);
+  if (Overflow) {
+    if (isNegative()) {
----------------
bjope wrote:
> nikic wrote:
> > bjope wrote:
> > > Coding style: skip all braces here.
> > I've left the braces on the overflow branch, otherwise there's a dangling else compiler warning.
> Yes, this is ok (not sure why I wrote "skip all", that was confusing).
It might be cleaner as:
```
if (!Overflow)
  return Res;

return isNegative() ? APInt::getSignedMinValue(Res.getBitWidth())
                    : APInt::getSignedMaxValue(Res.getBitWidth());
```


https://reviews.llvm.org/D54237





More information about the llvm-commits mailing list