diff options
author | David Green <david.green@arm.com> | 2022-11-24 14:29:57 +0000 |
---|---|---|
committer | David Green <david.green@arm.com> | 2022-11-24 14:29:57 +0000 |
commit | ca78b5601466f8515f5f958ef8e63d787d9d812e (patch) | |
tree | 9de304391e767f31f3377fec70104b4f714ec297 /llvm/lib/CodeGen/SelectOptimize.cpp | |
parent | 0cb2dd5322f494769a7c31c8ed8aab930919f5f3 (diff) | |
download | llvm-ca78b5601466f8515f5f958ef8e63d787d9d812e.zip llvm-ca78b5601466f8515f5f958ef8e63d787d9d812e.tar.gz llvm-ca78b5601466f8515f5f958ef8e63d787d9d812e.tar.bz2 |
[SelectOpt] Don't treat LogicalAnd/LogicalOr as selects
A `select i1 %c, i1 true, i1 %d` is just an or and a `select i1 %c, i1 %d, i1 false`
is just an and. There are better treated as such in the logic of SelectOpt, allowing
the backend to optimize them to and/or directly.
Differential Revision: https://reviews.llvm.org/D138490
Diffstat (limited to 'llvm/lib/CodeGen/SelectOptimize.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectOptimize.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectOptimize.cpp b/llvm/lib/CodeGen/SelectOptimize.cpp index b5a8a80..a8144e4 100644 --- a/llvm/lib/CodeGen/SelectOptimize.cpp +++ b/llvm/lib/CodeGen/SelectOptimize.cpp @@ -515,12 +515,27 @@ void SelectOptimize::convertProfitableSIGroups(SelectGroups &ProfSIGroups) { } } +static bool isSpecialSelect(SelectInst *SI) { + using namespace llvm::PatternMatch; + + // If the select is a logical-and/logical-or then it is better treated as a + // and/or by the backend. + if (match(SI, m_CombineOr(m_LogicalAnd(m_Value(), m_Value()), + m_LogicalOr(m_Value(), m_Value())))) + return true; + + return false; +} + void SelectOptimize::collectSelectGroups(BasicBlock &BB, SelectGroups &SIGroups) { BasicBlock::iterator BBIt = BB.begin(); while (BBIt != BB.end()) { Instruction *I = &*BBIt++; if (SelectInst *SI = dyn_cast<SelectInst>(I)) { + if (isSpecialSelect(SI)) + continue; + SelectGroup SIGroup; SIGroup.push_back(SI); while (BBIt != BB.end()) { |