diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 922751fe3d13..8deade345fe4 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -2722,11 +2722,12 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) { HasNUW = true; if (OBO->hasNoSignedWrap()) HasNSW = true; - } else if (isa(BEValueV)) { + } else if (const GEPOperator *GEP = + dyn_cast(BEValueV)) { // If the increment is a GEP, then we know it won't perform an // unsigned overflow, because the address space cannot be // wrapped around. - HasNUW = true; + HasNUW |= GEP->isInBounds(); } const SCEV *StartVal = getSCEV(StartValueV);