diff options
author | Nikita Popov <npopov@redhat.com> | 2024-12-09 16:44:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-09 16:44:05 +0100 |
commit | 10f315dc9c96ec2413881ab55a285e35d80def88 (patch) | |
tree | 1d1646eb052be70f00b6a17a49faeb507741ac35 /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | 646d1854c04e508bd4203fdaead5447ecb72398e (diff) | |
download | llvm-10f315dc9c96ec2413881ab55a285e35d80def88.zip llvm-10f315dc9c96ec2413881ab55a285e35d80def88.tar.gz llvm-10f315dc9c96ec2413881ab55a285e35d80def88.tar.bz2 |
[ConstantFolding] Infer getelementptr nuw flag (#119214)
Infer nuw from nusw and nneg. This is the constant expression variant of
https://github.com/llvm/llvm-project/pull/111144.
Proof: https://alive2.llvm.org/ce/z/ihztLy
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, |