diff --git a/polly/lib/Transform/ForwardOpTree.cpp b/polly/lib/Transform/ForwardOpTree.cpp index f2cb80db71a6..d9b19ca11cc3 100644 --- a/polly/lib/Transform/ForwardOpTree.cpp +++ b/polly/lib/Transform/ForwardOpTree.cpp @@ -166,11 +166,14 @@ struct ForwardingAction { } /// Named ctor: The value can just be used without any preparation. - static ForwardingAction triviallyForwardable(bool IsProfitable) { + static ForwardingAction triviallyForwardable(bool IsProfitable, Value *Val) { ForwardingAction Result; Result.Decision = IsProfitable ? FD_CanForwardProfitably : FD_CanForwardLeaf; - Result.Execute = []() { return true; }; + Result.Execute = [=]() { + LLVM_DEBUG(dbgs() << " trivially forwarded: " << *Val << "\n"); + return true; + }; return Result; } @@ -637,6 +640,8 @@ public: Access = TargetStmt->ensureValueRead(Inst); Access->setNewAccessRelation(SameVal); + LLVM_DEBUG(dbgs() << " forwarded known content of " << *Inst + << " which is " << SameVal << "\n"); TotalReloads++; NumReloads++; return false; @@ -703,6 +708,9 @@ public: // operands. This ensures that its operands are inserted before the // instruction using them. TargetStmt->prependInstruction(UseInst); + + LLVM_DEBUG(dbgs() << " forwarded speculable instruction: " << *UseInst + << "\n"); NumInstructionsCopied++; TotalInstructionsCopied++; return true; @@ -736,7 +744,7 @@ public: case VirtualUse::Block: case VirtualUse::Hoisted: // These can be used anywhere without special considerations. - return ForwardingAction::triviallyForwardable(false); + return ForwardingAction::triviallyForwardable(false, UseVal); case VirtualUse::Synthesizable: { // Check if the value is synthesizable at the new location as well. This @@ -752,7 +760,7 @@ public: VirtualUse TargetUse = VirtualUse::create( S, TargetStmt, TargetStmt->getSurroundingLoop(), UseVal, true); if (TargetUse.getKind() == VirtualUse::Synthesizable) - return ForwardingAction::triviallyForwardable(false); + return ForwardingAction::triviallyForwardable(false, UseVal); LLVM_DEBUG( dbgs() << " Synthesizable would not be synthesizable anymore: " @@ -761,11 +769,15 @@ public: } case VirtualUse::ReadOnly: { + if (!ModelReadOnlyScalars) + return ForwardingAction::triviallyForwardable(false, UseVal); + // If we model read-only scalars, we need to create a MemoryAccess for it. auto ExecAction = [this, TargetStmt, UseVal]() { - if (ModelReadOnlyScalars) - TargetStmt->ensureValueRead(UseVal); + TargetStmt->ensureValueRead(UseVal); + LLVM_DEBUG(dbgs() << " forwarded read-only value " << *UseVal + << "\n"); NumReadOnlyCopied++; TotalReadOnlyCopied++; diff --git a/polly/test/ForwardOpTree/forward_readonly.ll b/polly/test/ForwardOpTree/forward_readonly.ll index 215af70d1573..f046b851e755 100644 --- a/polly/test/ForwardOpTree/forward_readonly.ll +++ b/polly/test/ForwardOpTree/forward_readonly.ll @@ -42,7 +42,8 @@ return: ; STATS: Statistics { ; STATS: Instructions copied: 1 -; STATS: Read-only accesses copied: 1 +; MODEL: Read-only accesses copied: 1 +; NOMODEL: Read-only accesses copied: 0 ; STATS: Operand trees forwarded: 1 ; STATS: Statements with forwarded operand trees: 1 ; STATS: }