Index: include/polly/ScopInfo.h =================================================================== --- include/polly/ScopInfo.h +++ include/polly/ScopInfo.h @@ -889,6 +889,21 @@ /// Return the access value of this memory access. Value *getAccessValue() const { return AccessValue; } + /// Return llvm::Value that is stored by this access, if available. + /// + /// PHI nodes may not have a unique value available that is stored, as in + /// case of region statements one out of possibly several llvm::Values + /// might be stored. In this case nullptr is returned. + Value *tryGetValueStored() { + assert(isWrite() && "Only write statement store values"); + if (isPHIKind()) { + if (Incoming.size() == 1) + return Incoming[0].second; + return nullptr; + } + return AccessValue; + } + /// Return the access instruction of this memory access. Instruction *getAccessInstruction() const { return AccessInstruction; } Index: lib/Transform/Simplify.cpp =================================================================== --- lib/Transform/Simplify.cpp +++ lib/Transform/Simplify.cpp @@ -238,13 +238,7 @@ if (!isa(WA->getAccessInstruction()) && !WA->isPHIKind()) continue; - auto ReadingValue = WA->getAccessValue(); - - if (WA->isPHIKind()) { - PHINode *PHI = cast(WA->getAccessValue()); - BasicBlock *BB = Stmt.getBasicBlock(); - ReadingValue = PHI->getIncomingValueForBlock(BB); - } + llvm::Value *ReadingValue = WA->tryGetValueStored(); if (!ReadingValue) continue;