[PATCH] D54274: Constant folding and instcombine for saturating subs

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 8 14:01:53 PST 2018


nikic created this revision.
nikic added reviewers: leonardchan, craig.topper, RKSimon.
Herald added subscribers: llvm-commits, kristina, dexonsmith.

This is a continuation of https://reviews.llvm.org/D54237 for the subtraction case. The following simplifications / folds have been implemented:

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

I've also changed the computeOverflowForUnsignedSub() implementation to return AlwaysOverflows results, for parity with the computeOverflowForUnsignedAdd() implementation. The results were weirdly asymmetric previously.


Repository:
  rL LLVM

https://reviews.llvm.org/D54274

Files:
  include/llvm/ADT/APInt.h
  lib/Analysis/ConstantFolding.cpp
  lib/Analysis/InstructionSimplify.cpp
  lib/Analysis/ValueTracking.cpp
  lib/Support/APInt.cpp
  lib/Transforms/InstCombine/InstCombineCalls.cpp
  test/Transforms/InstCombine/saturating-sub.ll
  unittests/ADT/APIntTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54274.173220.patch
Type: text/x-patch
Size: 15078 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181108/3b3d8dd9/attachment.bin>


More information about the llvm-commits mailing list