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

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 7 16:18:31 PST 2018


nikic created this revision.
nikic added a reviewer: leonardchan.
Herald added subscribers: llvm-commits, kristina, dexonsmith, JDevlieghere.

We'd like to make use of the new saturating add intrinsics in Rust (in part because some obvious patterns don't optimize when implemented via with.overflow intrinsics). However right now saturing adds seems to be completely opaque to the optimizer.

This patch implements some basic optimization support for saturating add intrinsics, namely:

- Constant folding sat(C1 + C2) -> C3
- sat(X + 0) -> X
- sat(X uadd MAX) -> MAX
- sat(sat(X + C1) + C2) -> sat(X + C3) where legal
- sat(X1 + X2) -> add nuw/nsw where possible


Repository:
  rL LLVM

https://reviews.llvm.org/D54237

Files:
  include/llvm/ADT/APInt.h
  lib/Analysis/ConstantFolding.cpp
  lib/Support/APInt.cpp
  lib/Transforms/InstCombine/InstCombineCalls.cpp
  test/Transforms/InstCombine/saturating-add.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54237.173074.patch
Type: text/x-patch
Size: 10455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181108/2aade065/attachment.bin>


More information about the llvm-commits mailing list