Loop coalescing: fix pointer chainsing in use-chain traversal

In the replaceAllUsesExcept utility function called from loop coalescing the
iteration over the use-chain is incorrect. The use list nodes (IROperands) have
next/prev links, and bluntly resetting the use would make the loop to continue
on uses of the value that was replaced instead of the original one. As a
result, it could miss the existing uses and update the wrong ones. Make sure we
increment the iterator before updating the use in the loop body.

Reported-by: Uday Bondhugula <uday@polymagelabs.com>

Closes #291.

PiperOrigin-RevId: 283754195
Change-Id: Ia9478e50544b2cd30b42e18262e3038009cf05b3
This commit is contained in:
A. Unique TensorFlower 2019-12-04 07:41:55 -08:00 committed by TensorFlower Gardener
parent 4820014828
commit 45dc6b7be1

View File

@ -979,7 +979,7 @@ TileLoops mlir::extractFixedOuterLoops(loop::ForOp rootForOp,
static void
replaceAllUsesExcept(Value *orig, Value *replacement,
const SmallPtrSetImpl<Operation *> &exceptions) {
for (auto &use : orig->getUses()) {
for (auto &use : llvm::make_early_inc_range(orig->getUses())) {
if (exceptions.count(use.getOwner()) == 0)
use.set(replacement);
}