forked from OSchip/llvm-project
[Attributor] Remove function pointer restriction for AAAlign
This check is not compatible with opaque pointers. We can avoid it by adjusting the getPointerAlignment() implementation to avoid creating unnecessary ptrtoint expressions for bitcasted pointers. The code already uses OnlyIfReduced to not create an expression if it does not simplify, and this makes sure that folding a bitcast and ptrtoint into a ptrtoint doesn't count as a simplification. Differential Revision: https://reviews.llvm.org/D120904
This commit is contained in:
parent
43b638241a
commit
a9b03d9e2e
|
@ -964,6 +964,9 @@ Align Value::getPointerAlignment(const DataLayout &DL) const {
|
|||
return Align(CI->getLimitedValue());
|
||||
}
|
||||
} else if (auto *CstPtr = dyn_cast<Constant>(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<ConstantInt>(ConstantExpr::getPtrToInt(
|
||||
const_cast<Constant *>(CstPtr), DL.getIntPtrType(getType()),
|
||||
/*OnlyIfReduced=*/true))) {
|
||||
|
|
|
@ -4521,13 +4521,7 @@ struct AAAlignImpl : AAAlign {
|
|||
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() ||
|
||||
|
|
Loading…
Reference in New Issue