summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-02-19 22:14:21 +0000
committerSanjay Patel <spatel@rotateright.com>2019-02-19 22:14:21 +0000
commitc1e018431795165dd3313cbc4e52e656909f678c (patch)
tree5d1c59372095430fe28bcf2adb08196aefe1b399 /llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
parentbf223e9d59f47753e1d94e9c7e6dd4b497e3a1d7 (diff)
downloadbcm5719-llvm-c1e018431795165dd3313cbc4e52e656909f678c.tar.gz
bcm5719-llvm-c1e018431795165dd3313cbc4e52e656909f678c.zip
[InstCombine] reduce even 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: uaddsat, -1 fval %notx = xor i32 %x, -1 %a = add i32 %x, %y %c = icmp ugt i32 %notx, %y %r = select i1 %c, i32 %a, i32 -1 => %a = add i32 %x, %y %c2 = icmp ugt i32 %y, %a %r = select i1 %c2, i32 -1, i32 %a Name: uaddsat, -1 fval + ult %notx = xor i32 %x, -1 %a = add i32 %x, %y %c = icmp ult i32 %y, %notx %r = select i1 %c, i32 %a, i32 -1 => %a = add i32 %x, %y %c2 = icmp ugt i32 %y, %a %r = select i1 %c2, i32 -1, i32 %a https://rise4fun.com/Alive/nTp llvm-svn: 354393
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 0e9d6f05275..d153c848d38 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -695,22 +695,30 @@ static Value *canonicalizeSaturatedAdd(ICmpInst *Cmp, Value *TVal, Value *FVal,
return Builder.CreateSelect(NewCmp, FVal, TVal);
}
- // Canonicalize to 'ULT' to simplify matching below.
+ // Match unsigned saturated add of 2 variables with an unnecessary 'not'.
+ // There are 8 commuted variants.
+ // Canonicalize -1 (saturated result) to true value of the select.
+ if (match(FVal, m_AllOnes())) {
+ std::swap(TVal, FVal);
+ std::swap(Cmp0, Cmp1);
+ }
+ if (!match(TVal, m_AllOnes()))
+ return nullptr;
+
+ // Canonicalize predicate to 'ULT'.
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 *Y;
- if (match(TVal, m_AllOnes()) && match(Cmp0, m_Not(m_Value(X))) &&
+ if (match(Cmp0, m_Not(m_Value(X))) &&
match(FVal, m_c_Add(m_Specific(X), m_Value(Y))) && Y == Cmp1) {
// Change the comparison to use the sum (false value of the select). That is
- // the canonical pattern match form for uadd.with.overflow and eliminates a
+ // a canonical pattern match form for uadd.with.overflow and eliminates a
// use of the 'not' op:
// (~X u< Y) ? -1 : (X + Y) --> ((X + Y) u< Y) ? -1 : (X + Y)
// (~X u< Y) ? -1 : (Y + X) --> ((Y + X) u< Y) ? -1 : (Y + X)
OpenPOWER on IntegriCloud