summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2018-09-15 12:04:13 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2018-09-15 12:04:13 +0000
commit1b7fc870206a44474ea72b1b6c0c2653582a7987 (patch)
treed639de43c9de26b17075ce829454c000cbc9684c /llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
parent9e8b4de3b3ab0ad27ef27ce948e00e3a3b26aa3c (diff)
downloadbcm5719-llvm-1b7fc870206a44474ea72b1b6c0c2653582a7987.tar.gz
bcm5719-llvm-1b7fc870206a44474ea72b1b6c0c2653582a7987.zip
[InstCombine] Inefficient pattern for high-bits checking 3 (PR38708)
Summary: It is sometimes important to check that some newly-computed value is non-negative and only n bits wide (where n is a variable.) There are many ways to check that: https://godbolt.org/z/o4RB8D The last variant seems best? (I'm sure there are some other variations i haven't thought of..) The last (as far i know?) pattern, non-canonical due to the extra use. https://godbolt.org/z/aCMsPk https://rise4fun.com/Alive/I6f https://bugs.llvm.org/show_bug.cgi?id=38708 Reviewers: spatel, craig.topper, RKSimon Reviewed By: spatel Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D52062 llvm-svn: 342321
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index a295f65f387..5f8bf84092c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -4624,8 +4624,8 @@ static Instruction *canonicalizeICmpBool(ICmpInst &I,
}
// Transform pattern like:
-// (1 << Y) u<= X or ~(-1 << Y) u< X
-// (1 << Y) u> X or ~(-1 << Y) u>= X
+// (1 << Y) u<= X or ~(-1 << Y) u< X or ((1 << Y)+(-1)) u< X
+// (1 << Y) u> X or ~(-1 << Y) u>= X or ((1 << Y)+(-1)) u>= X
// Into:
// (X l>> Y) != 0
// (X l>> Y) == 0
@@ -4649,10 +4649,15 @@ static Instruction *foldICmpWithHighBitMask(ICmpInst &Cmp,
default:
return nullptr;
}
- } else if (match(&Cmp,
- m_c_ICmp(Pred,
- m_OneUse(m_Not(m_Shl(m_AllOnes(), m_Value(Y)))),
- m_Value(X)))) {
+ } else if (match(&Cmp, m_c_ICmp(Pred,
+ m_OneUse(m_CombineOr(
+ m_Not(m_Shl(m_AllOnes(), m_Value(Y))),
+ m_Add(m_Shl(m_One(), m_Value(Y)),
+ m_AllOnes()))),
+ m_Value(X)))) {
+ // The variant with 'add' is not canonical, (the variant with 'not' is)
+ // we only get it because it has extra uses, and can't be canonicalized,
+
// We want X to be the icmp's second operand, so swap predicate if it isn't.
if (Cmp.getOperand(0) == X)
Pred = Cmp.getSwappedPredicate();
OpenPOWER on IntegriCloud