From b86b771c020725e7f2113898e841a6f29b919548 Mon Sep 17 00:00:00 2001 From: Amjad Aboud Date: Wed, 31 Jan 2018 22:39:05 +0000 Subject: [AggressiveInstCombine] Fixed TruncCombine class to handle TruncInst leaf node correctly. This covers the case where TruncInst leaf node is a constant expression. See PR36121 for more details. Differential Revision: https://reviews.llvm.org/D42622 llvm-svn: 323926 --- .../AggressiveInstCombine/TruncInstCombine.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp') diff --git a/llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp index 0378ea79ef7..d62b6434f00 100644 --- a/llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp +++ b/llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp @@ -317,6 +317,7 @@ void TruncInstCombine::ReduceExpressionDag(Type *SclTy) { // just return the source. There's no need to insert it because it is not // new. if (I->getOperand(0)->getType() == Ty) { + assert(!isa(I) && "Cannot reach here with TruncInst"); NodeInfo.NewValue = I->getOperand(0); continue; } @@ -326,11 +327,18 @@ void TruncInstCombine::ReduceExpressionDag(Type *SclTy) { Opc == Instruction::SExt); // Update Worklist entries with new value if needed. - if (auto *NewCI = dyn_cast(Res)) { - auto Entry = find(Worklist, I); - if (Entry != Worklist.end()) + // There are three possible changes to the Worklist: + // 1. Update Old-TruncInst -> New-TruncInst. + // 2. Remove Old-TruncInst (if New node is not TruncInst). + // 3. Add New-TruncInst (if Old node was not TruncInst). + auto Entry = find(Worklist, I); + if (Entry != Worklist.end()) { + if (auto *NewCI = dyn_cast(Res)) *Entry = NewCI; - } + else + Worklist.erase(Entry); + } else if (auto *NewCI = dyn_cast(Res)) + Worklist.push_back(NewCI); break; } case Instruction::Add: -- cgit v1.2.3