From 55815b621b3a8f56a36c93229de1356e325a136f Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Thu, 30 Jan 2025 20:58:38 +0000 Subject: [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 --- llvm/lib/Analysis/ConstantFolding.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Analysis/ConstantFolding.cpp') 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(), -- cgit v1.1