diff options
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 0233d31..836fa94 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -952,7 +952,6 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP, } // Try to infer inbounds for GEPs of globals. - // TODO(gep_nowrap): Also infer nuw flag. if (!NW.isInBounds() && Offset.isNonNegative()) { bool CanBeNull, CanBeFreed; uint64_t DerefBytes = @@ -961,6 +960,10 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP, NW |= GEPNoWrapFlags::inBounds(); } + // nusw + nneg -> nuw + if (NW.hasNoUnsignedSignedWrap() && Offset.isNonNegative()) + NW |= GEPNoWrapFlags::noUnsignedWrap(); + // Otherwise canonicalize this to a single ptradd. LLVMContext &Ctx = Ptr->getContext(); return ConstantExpr::getGetElementPtr(Type::getInt8Ty(Ctx), Ptr, |