diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -964,6 +964,9 @@ return Align(CI->getLimitedValue()); } } else if (auto *CstPtr = dyn_cast(this)) { + // Strip pointer casts to avoid creating unnecessary ptrtoint expression + // if the only "reduction" is combining a bitcast + ptrtoint. + CstPtr = CstPtr->stripPointerCasts(); if (auto *CstInt = dyn_cast_or_null(ConstantExpr::getPtrToInt( const_cast(CstPtr), DL.getIntPtrType(getType()), /*OnlyIfReduced=*/true))) { diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -4521,13 +4521,7 @@ takeKnownMaximum(Attr.getValueAsInt()); Value &V = getAssociatedValue(); - // TODO: This is a HACK to avoid getPointerAlignment to introduce a ptr2int - // use of the function pointer. This was caused by D73131. We want to - // avoid this for function pointers especially because we iterate - // their uses and int2ptr is not handled. It is not a correctness - // problem though! - if (!V.getType()->getPointerElementType()->isFunctionTy()) - takeKnownMaximum(V.getPointerAlignment(A.getDataLayout()).value()); + takeKnownMaximum(V.getPointerAlignment(A.getDataLayout()).value()); if (getIRPosition().isFnInterfaceKind() && (!getAnchorScope() ||