summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-02-17 16:48:50 +0000
committerSanjay Patel <spatel@rotateright.com>2019-02-17 16:48:50 +0000
commitb341ee7071c1e836d8ebd3d2ef25a78fdab8da32 (patch)
tree77593ee72e823d4005baada98fdaecee1d3b010d /llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
parentdb02293d9dd572e146f85a65d103f08f59449dc6 (diff)
downloadbcm5719-llvm-b341ee7071c1e836d8ebd3d2ef25a78fdab8da32.tar.gz
bcm5719-llvm-b341ee7071c1e836d8ebd3d2ef25a78fdab8da32.zip
[InstCombine] reduce more unsigned saturated add with 'not' op
We want to use the sum in the icmp to allow matching with m_UAddWithOverflow and eliminate the 'not'. This is discussed in D51929 and is another step towards solving PR14613: https://bugs.llvm.org/show_bug.cgi?id=14613 Name: not op %notx = xor i32 %x, -1 %a = add i32 %x, %y %c = icmp ult i32 %notx, %y %r = select i1 %c, i32 -1, i32 %a => %a = add i32 %x, %y %c2 = icmp ult i32 %a, %y %r = select i1 %c2, i32 -1, i32 %a Name: not op ugt %notx = xor i32 %x, -1 %a = add i32 %x, %y %c = icmp ugt i32 %y, %notx %r = select i1 %c, i32 -1, i32 %a => %a = add i32 %x, %y %c2 = icmp ult i32 %a, %y %r = select i1 %c2, i32 -1, i32 %a https://rise4fun.com/Alive/niom (The matching here is still incomplete.) llvm-svn: 354224
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 8b5dd7923c4..3ee418feb0e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -677,13 +677,23 @@ static Value *canonicalizeSaturatedSubtract(const ICmpInst *ICI,
static Value *canonicalizeSaturatedAdd(ICmpInst *Cmp, Value *TVal, Value *FVal,
InstCombiner::BuilderTy &Builder) {
- if (!Cmp->hasOneUse() || Cmp->getPredicate() != ICmpInst::ICMP_ULT)
+ if (!Cmp->hasOneUse())
return nullptr;
- // Match unsigned saturated add of 2 variables with an unnecessary 'not'.
- // TODO: There are more variations of this pattern.
+ // Canonicalize to 'ULT' to simplify matching below.
Value *Cmp0 = Cmp->getOperand(0);
Value *Cmp1 = Cmp->getOperand(1);
+ ICmpInst::Predicate Pred = Cmp->getPredicate();
+ if (Pred == ICmpInst::ICMP_UGT) {
+ Pred = ICmpInst::ICMP_ULT;
+ std::swap(Cmp0, Cmp1);
+ }
+
+ if (Pred != ICmpInst::ICMP_ULT)
+ return nullptr;
+
+ // Match unsigned saturated add of 2 variables with an unnecessary 'not'.
+ // TODO: There are more variations of this pattern.
Value *X, *Y;
if (match(TVal, m_AllOnes()) && match(Cmp0, m_Not(m_Value(X))) &&
match(FVal, m_c_Add(m_Specific(X), m_Value(Y))) && Y == Cmp1) {
OpenPOWER on IntegriCloud