|
31 | 31 | #include "llvm/ADT/SmallVector.h" |
32 | 32 | #include "llvm/ADT/Statistic.h" |
33 | 33 | #include "llvm/ADT/iterator_range.h" |
| 34 | +#include "llvm/Analysis/CodeMetrics.h" |
34 | 35 | #include "llvm/Analysis/LoopInfo.h" |
35 | 36 | #include "llvm/Analysis/LoopPass.h" |
36 | 37 | #include "llvm/Analysis/MemorySSA.h" |
@@ -1859,35 +1860,16 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) { |
1859 | 1860 | } |
1860 | 1861 | } |
1861 | 1862 |
|
1862 | | - // If the loop body uses a convergence token defined within the loop, skip |
1863 | | - // predication. This is to avoid changing the convergence behavior of the |
1864 | | - // loop. |
1865 | | - SmallVector<BasicBlock *, 16> blocks = ExitingBlocks; |
1866 | | - SmallVector<Value *, 16> tokens = {}; |
1867 | | - size_t index = 0; // Assume Exiting Blocks are sorted. |
1868 | | - while (index < blocks.size()) { |
1869 | | - BasicBlock *BB = blocks[index]; |
1870 | | - index++; |
1871 | | - const auto exitingBlockName = BB->getName(); |
1872 | | - for (Instruction &I : *BB) { |
1873 | | - // Check if the instruction uses any convergence tokens. |
1874 | | - if (auto *CB = dyn_cast<CallBase>(&I); |
1875 | | - CB && !isa<ConvergenceControlInst>(&I)) { |
1876 | | - auto token = CB->getConvergenceControlToken(); |
1877 | | - if (token && llvm::is_contained(tokens, token)) { |
1878 | | - return false; |
1879 | | - } |
1880 | | - } |
1881 | | - if (isa<ConvergenceControlInst>(&I)) { |
1882 | | - tokens.push_back(cast<Value>(&I)); |
1883 | | - } |
1884 | | - } |
| 1863 | + CodeMetrics Metrics; |
| 1864 | + SmallPtrSet<const Value *, 32> EphValues; |
| 1865 | + for (BasicBlock *BB : L->blocks()) { |
| 1866 | + Metrics.analyzeBasicBlock(BB, *TTI, EphValues, /* PrepareForLTO= */ false, |
| 1867 | + L); |
| 1868 | + } |
1885 | 1869 |
|
1886 | | - for (BasicBlock *Succ : successors(BB)) { |
1887 | | - const auto succName = Succ->getName(); |
1888 | | - if (Succ != L->getLoopLatch() && !llvm::is_contained(blocks, Succ)) |
1889 | | - blocks.push_back(Succ); |
1890 | | - } |
| 1870 | + if (Metrics.Convergence == ConvergenceKind::ExtendedLoop) { |
| 1871 | + // Do not predicate loops with extended convergence. |
| 1872 | + return false; |
1891 | 1873 | } |
1892 | 1874 |
|
1893 | 1875 | bool Changed = false; |
|
0 commit comments