diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2019-08-24 06:49:51 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2019-08-24 06:49:51 +0000 |
commit | 9cf08c6de1da1174986a8b198134121450832941 (patch) | |
tree | e83928e55cb619a08ead27cdb521735ad16289a3 /llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | |
parent | de19f749e0e6108de7eff4d77e8e6afa8c9f64cb (diff) | |
download | bcm5719-llvm-9cf08c6de1da1174986a8b198134121450832941.tar.gz bcm5719-llvm-9cf08c6de1da1174986a8b198134121450832941.zip |
[Constant] Add 'isElementWiseEqual()' method
Promoting it from InstCombine's tryToReuseConstantFromSelectInComparison().
Return true if this constant and a constant 'Y' are element-wise equal.
This is identical to just comparing the pointers, with the exception that
for vectors, if only one of the constants has an `undef` element in some
lane, the constants still match.
llvm-svn: 369842
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index d5de10c32c4..50f6b2bdfd8 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1296,18 +1296,6 @@ tryToReuseConstantFromSelectInComparison(SelectInst &Sel, ICmpInst &Cmp, // FIXME: are there any magic icmp predicate+constant pairs we must not touch? - auto ConstantsAreElementWiseEqual = [](Constant *Cx, Value *Y) { - // Are they fully identical? - if (Cx == Y) - return true; - // They may still be identical element-wise (if they have `undef`s). - auto *Cy = dyn_cast<Constant>(Y); - if (!Cy) - return false; - return match(ConstantExpr::getICmp(ICmpInst::Predicate::ICMP_EQ, Cx, Cy), - m_One()); - }; - Value *SelVal0, *SelVal1; // We do not care which one is from where. match(&Sel, m_Select(m_Value(), m_Value(SelVal0), m_Value(SelVal1))); // At least one of these values we are selecting between must be a constant @@ -1317,10 +1305,8 @@ tryToReuseConstantFromSelectInComparison(SelectInst &Sel, ICmpInst &Cmp, return nullptr; // Does this constant C match any of the `select` values? - auto MatchesSelectValue = [ConstantsAreElementWiseEqual, SelVal0, - SelVal1](Constant *C) { - return ConstantsAreElementWiseEqual(C, SelVal0) || - ConstantsAreElementWiseEqual(C, SelVal1); + auto MatchesSelectValue = [SelVal0, SelVal1](Constant *C) { + return C->isElementWiseEqual(SelVal0) || C->isElementWiseEqual(SelVal1); }; // If C0 *already* matches true/false value of select, we are done. |