diff options
| author | Hongtao Yu <hoy@meta.com> | 2025-02-11 20:07:21 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-11 20:07:21 -0800 |
| commit | 4a63ff4330342aeb4a4f62cca32cfcd07ba91cab (patch) | |
| tree | 120a72e0731def455d70a6dc1792d69da6405e0f /mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp | |
| parent | cc7e83601d759349b0ded7d75b5550f3c625dfcf (diff) | |
Revert "[mlir] Enable LICM for ops with only read side effects in scf.for" (#126840)
Reverts llvm/llvm-project#120302
Diffstat (limited to 'mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp')
| -rw-r--r-- | mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp b/mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp index 094db01176a2..7460746934a7 100644 --- a/mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp +++ b/mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp @@ -60,18 +60,13 @@ size_t mlir::moveLoopInvariantCode( ArrayRef<Region *> regions, function_ref<bool(Value, Region *)> isDefinedOutsideRegion, function_ref<bool(Operation *, Region *)> shouldMoveOutOfRegion, - function_ref<void(Operation *)> moveOutOfRegionWithoutGuard, - function_ref<void(Operation *)> moveOutOfRegionWithGuard) { + function_ref<void(Operation *, Region *)> moveOutOfRegion) { size_t numMoved = 0; for (Region *region : regions) { LLVM_DEBUG(llvm::dbgs() << "Original loop:\n" << *region->getParentOp() << "\n"); - bool anyOpHoistedWithGuard = false; - bool loopSideEffectFreeOrHasOnlyReadSideEffect = - isMemoryEffectFreeOrOnlyRead(region->getParentOp()); - std::queue<Operation *> worklist; // Add top-level operations in the loop body to the worklist. for (Operation &op : region->getOps()) @@ -89,26 +84,12 @@ size_t mlir::moveLoopInvariantCode( continue; LLVM_DEBUG(llvm::dbgs() << "Checking op: " << *op << "\n"); - if (!shouldMoveOutOfRegion(op, region) || !canBeHoisted(op, definedOutside)) continue; - // Can only hoist pure ops (side-effect free) when there is an op with - // write and/or unknown side effects in the loop. - if (!loopSideEffectFreeOrHasOnlyReadSideEffect && !isMemoryEffectFree(op)) - continue; - bool moveWithoutGuard = !anyOpHoistedWithGuard && isMemoryEffectFree(op); - if (moveWithoutGuard) { - LLVM_DEBUG(llvm::dbgs() << "Moving loop-invariant op: " << *op - << " without guard\n"); - moveOutOfRegionWithoutGuard(op); - } else { - LLVM_DEBUG(llvm::dbgs() - << "Moving loop-invariant op: " << *op << " with guard\n"); - moveOutOfRegionWithGuard(op); - anyOpHoistedWithGuard = true; - } + LLVM_DEBUG(llvm::dbgs() << "Moving loop-invariant op: " << *op << "\n"); + moveOutOfRegion(op, region); ++numMoved; // Since the op has been moved, we need to check its users within the @@ -125,14 +106,13 @@ size_t mlir::moveLoopInvariantCode( size_t mlir::moveLoopInvariantCode(LoopLikeOpInterface loopLike) { return moveLoopInvariantCode( loopLike.getLoopRegions(), - [&](Value value, Region *region) { - return !region->isAncestor(value.getParentRegion()); + [&](Value value, Region *) { + return loopLike.isDefinedOutsideOfLoop(value); }, [&](Operation *op, Region *) { - return isSpeculatable(op) && isMemoryEffectFreeOrOnlyRead(op); + return isMemoryEffectFree(op) && isSpeculatable(op); }, - [&](Operation *op) { loopLike.moveOutOfLoop(op); }, - [&](Operation *op) { loopLike.moveOutOfLoopWithGuard(op); }); + [&](Operation *op, Region *) { loopLike.moveOutOfLoop(op); }); } namespace { |
