Skip to content

Commit

Permalink
[Attributor] Remove function pointer restriction for AAAlign
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikic committed Mar 7, 2022
1 parent 43b6382 commit a9b03d9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/IR/Value.cpp
Expand Up @@ -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))) {
Expand Down
8 changes: 1 addition & 7 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Expand Up @@ -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() ||
Expand Down

0 comments on commit a9b03d9

Please sign in to comment.