[llvm] [InstCombine] ptrmask of gep for dynamic pointer aligment (PR #80002)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 16 10:18:33 PST 2024
================
@@ -995,6 +995,44 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
I, 1, (DemandedMask & ~LHSKnown.Zero).zextOrTrunc(MaskWidth)))
return I;
+ // Combine:
+ // (ptrmask (getelementptr i8, ptr p, imm i), imm mask)
+ // -> (ptrmask (getelementptr i8, ptr p, imm (i & mask)), imm mask)
+ // where only the low bits known to be zero in the pointer are changed
+ Value *InnerPtr;
+ uint64_t GEPIndex;
+ uint64_t PtrMaskImmediate;
+ if (match(I, m_Intrinsic<Intrinsic::ptrmask>(
+ m_PtrAdd(m_Value(InnerPtr), m_ConstantInt(GEPIndex)),
+ m_ConstantInt(PtrMaskImmediate)))) {
+
+ const unsigned trailingZeros =
+ computeKnownBits(InnerPtr, Depth + 1, I).countMinTrailingZeros();
+
+ if (trailingZeros < 64) {
+ uint64_t PointerAlignBits = (uint64_t(1) << trailingZeros) - 1;
+
+ uint64_t HighBitsGEPIndex = GEPIndex & ~PointerAlignBits;
+ uint64_t MaskedLowBitsGEPIndex =
+ GEPIndex & PointerAlignBits & PtrMaskImmediate;
+
+ uint64_t MaskedGEPIndex = HighBitsGEPIndex | MaskedLowBitsGEPIndex;
+
+ if (MaskedGEPIndex != GEPIndex) {
+ auto *GEP = cast<GetElementPtrInst>(II->getArgOperand(0));
+ Type *I64 = Type::getInt64Ty(I->getContext());
----------------
goldsteinn wrote:
Think this should be using `Q.DL.getIndexTypeSizeInBits`.
https://github.com/llvm/llvm-project/pull/80002
More information about the llvm-commits
mailing list