diff options
author | Florian Hahn <flo@fhahn.com> | 2025-01-30 20:58:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-30 20:58:38 +0000 |
commit | 55815b621b3a8f56a36c93229de1356e325a136f (patch) | |
tree | b41456d4e22d70229b81bbbd3248e2acbbe63346 /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | 9b52dbe0e0c3298438fd0a32495dd796b1d33970 (diff) | |
download | llvm-55815b621b3a8f56a36c93229de1356e325a136f.zip llvm-55815b621b3a8f56a36c93229de1356e325a136f.tar.gz llvm-55815b621b3a8f56a36c93229de1356e325a136f.tar.bz2 |
[Value] Look through inttoptr (add ..) in accumulateConstantOffsets (#124981)
Look through inttoptr (add (ptrtoint P), C) when accumulating offsets.
Adds a missing fold after
https://github.com/llvm/llvm-project/pull/123518
Alive2 for the tests with changes: https://alive2.llvm.org/ce/z/VvPrzv
PR: https://github.com/llvm/llvm-project/pull/124981
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 80c1277..d645bf8 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -1258,11 +1258,16 @@ Constant *llvm::ConstantFoldCompareInstOperands( if (Ops0->getType()->isPointerTy() && !ICmpInst::isSigned(Predicate)) { unsigned IndexWidth = DL.getIndexTypeSizeInBits(Ops0->getType()); APInt Offset0(IndexWidth, 0); - Value *Stripped0 = - Ops0->stripAndAccumulateInBoundsConstantOffsets(DL, Offset0); + bool IsEqPred = ICmpInst::isEquality(Predicate); + Value *Stripped0 = Ops0->stripAndAccumulateConstantOffsets( + DL, Offset0, /*AllowNonInbounds=*/IsEqPred, + /*AllowInvariantGroup=*/false, /*ExternalAnalysis=*/nullptr, + /*LookThroughIntToPtr=*/IsEqPred); APInt Offset1(IndexWidth, 0); - Value *Stripped1 = - Ops1->stripAndAccumulateInBoundsConstantOffsets(DL, Offset1); + Value *Stripped1 = Ops1->stripAndAccumulateConstantOffsets( + DL, Offset1, /*AllowNonInbounds=*/IsEqPred, + /*AllowInvariantGroup=*/false, /*ExternalAnalysis=*/nullptr, + /*LookThroughIntToPtr=*/IsEqPred); if (Stripped0 == Stripped1) return ConstantInt::getBool( Ops0->getContext(), |