[llvm] [Value] Look through inttoptr (add ..) in accumulateConstantOffsets (PR #124981)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 30 05:42:01 PST 2025
================
@@ -775,6 +776,25 @@ const Value *Value::stripAndAccumulateConstantOffsets(
V = RV;
if (AllowInvariantGroup && Call->isLaunderOrStripInvariantGroup())
V = Call->getArgOperand(0);
+ } else if (auto *Int2Ptr = dyn_cast<Operator>(V)) {
+ // Try to accumulate across (inttoptr (add (ptrtoint p), off)).
+ if (!AllowNonInbounds || !LookThroughIntToPtr || !Int2Ptr ||
+ Int2Ptr->getOpcode() != Instruction::IntToPtr ||
+ Int2Ptr->getOperand(0)->getType()->getScalarSizeInBits() != BitWidth)
+ return V;
+
+ auto *Add = dyn_cast<AddOperator>(Int2Ptr->getOperand(0));
+ if (!Add)
+ return V;
+
+ auto *Ptr2Int = dyn_cast<PtrToIntOperator>(Add->getOperand(0));
+ auto *CI = dyn_cast<ConstantInt>(Add->getOperand(1));
+ if (!Ptr2Int || !CI)
+ return V;
+
+ const APInt &AddOffset = CI->getValue();
+ Offset += AddOffset;
----------------
nikic wrote:
```suggestion
Offset += CI->getValue();
```
https://github.com/llvm/llvm-project/pull/124981
More information about the llvm-commits
mailing list