diff --git a/src/base/SMPBasicBlock.cpp b/src/base/SMPBasicBlock.cpp index 813ba74433a8f94a23ea1fc9957f18ee0c854929..2d42586265954e475662eea43fb024346a0bc51e 100644 --- a/src/base/SMPBasicBlock.cpp +++ b/src/base/SMPBasicBlock.cpp @@ -1225,7 +1225,7 @@ void SMPBasicBlock::SCCPGlobalPropagationHelper(const STARSOpndTypePtr &GlobalOp // Three cases: // (1) GlobalOp/DefSSANum is a Phi USE, in which case we re-eval the Phi Function and return. // (2) GlobalOp/DefSSANum is upward exposed, in which case we find the UpExposed USEs and re-eval those statements and recurse if LiveOut. - // (3) GlobalOp/DefSSANum is the pass-through case, so it must be LiveOut and we recurse. + // (3) GlobalOp/DefSSANum is LiveOut (either pass-through case or DEFed in this block) and we recurse. bool FoundReDEF = true; enum STARSBranchConst BranchEval; BranchEval = STARS_BRANCH_UNKNOWN; @@ -1366,10 +1366,13 @@ void SMPBasicBlock::SCCPGatherStatistics(void) { int UseHashIndex = HashGlobalNameAndSSA(MoveSourceOp, UseSSANum); map<int, struct STARS_SCCP_Const_Struct>::iterator ConstIter = this->GetFunc()->FindConstValue(UseHashIndex); if (ConstIter != this->GetFunc()->GetLastConstValueIter()) { // found an SCCP const entry - ++SCCPConstantOutgoingArgWriteCount; - ConstArgFound = true; + if ((*ConstIter).second.ConstType == STARS_CONST_HAS_VALUE) { // not STARS_CONST_BOTTOM + ++SCCPConstantOutgoingArgWriteCount; + ConstArgFound = true; + } } } + // NOTE: Deal with read-only memory lookup. !!!!****!!!! } } else if ((DataFlowType == CALL) || (DataFlowType == INDIR_CALL)) { diff --git a/src/base/SMPFunction.cpp b/src/base/SMPFunction.cpp index ea5a97ef3fc15926766e55d275f09e4492b424a3..5538927490cceb764613f8e29aa66fb55decd2f8 100644 --- a/src/base/SMPFunction.cpp +++ b/src/base/SMPFunction.cpp @@ -4737,6 +4737,9 @@ void SMPFunction::SparseConditionalConstantPropagation(void) { // endfor // endif // endif + // NOTE: We differ slightly from the published implementation. We don't maintain an SSA def-use chain explicitly, + // so we add the current block to the SSAWorkList when we find a new constant DEF, and search that block for + // further USEs of that operand with that SSA number. assert(CurrBlock->IsSCCPVisited()); // a local name is only added to SSAWorkList from within the block vector<SMPInstr *>::iterator InstIter; bool FoundReDEF = false; diff --git a/src/base/SMPInstr.cpp b/src/base/SMPInstr.cpp index 7b57dd2497e5e7c5400362941866cd695eafb900..56caab8c7873896b6707cfb0f26c21d69b3c940e 100644 --- a/src/base/SMPInstr.cpp +++ b/src/base/SMPInstr.cpp @@ -7976,40 +7976,50 @@ void SMPInstr::SCCPFetchConstUseValue(const STARSOpndTypePtr &UseOp, STARS_SCCP_ if (GoodAddr) { STARS_Segment_t *MemSeg = global_stars_interface->getseg(MemAddr); if (NULL != MemSeg) { - if (!(MemSeg->IsWriteableSegment())) { + if (MemSeg->IsWriteableSegment()) { + ConstStruct.ConstType = STARS_CONST_BOTTOM; // cannot know writable memory value without alias analysis, etc. + } + else { size_t UseOpByteWidth = UseOp->GetByteWidth(); if (UseOpByteWidth == 8) { uint64_t MemValue; if (MemSeg->GetReadOnlyMem64BitValue(MemAddr, MemValue)) { ConstStruct.ConstType = STARS_CONST_HAS_VALUE; - ConstStruct.ConstValue = (STARS_uval_t)MemValue; + ConstStruct.ConstValue = (STARS_uval_t) MemValue; } } else if (UseOpByteWidth == 4) { uint32_t MemValue; if (MemSeg->GetReadOnlyMem32BitValue(MemAddr, MemValue)) { ConstStruct.ConstType = STARS_CONST_HAS_VALUE; - ConstStruct.ConstValue = (STARS_uval_t)MemValue; + ConstStruct.ConstValue = (STARS_uval_t) MemValue; } } else if (UseOpByteWidth == 2) { uint16_t MemValue; if (MemSeg->GetReadOnlyMem16BitValue(MemAddr, MemValue)) { ConstStruct.ConstType = STARS_CONST_HAS_VALUE; - ConstStruct.ConstValue = (STARS_uval_t)MemValue; + ConstStruct.ConstValue = (STARS_uval_t) MemValue; } } else if (UseOpByteWidth == 1) { uint8_t MemValue; if (MemSeg->GetReadOnlyMem8BitValue(MemAddr, MemValue)) { ConstStruct.ConstType = STARS_CONST_HAS_VALUE; - ConstStruct.ConstValue = (STARS_uval_t)MemValue; + ConstStruct.ConstValue = (STARS_uval_t) MemValue; } } } } } + else { // not GoodAddr + ConstStruct.ConstType = STARS_CONST_BOTTOM; + } } + else if (UseOp->IsMemOp()) { // Any memory operand that is not a StaticMemOp + ConstStruct.ConstType = STARS_CONST_BOTTOM; + } + return; } // end of SMPInstr::SCCPFetchConstUseValue()