Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions llvm/lib/IR/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,14 +1000,12 @@ Align Value::getPointerAlignment(const DataLayout &DL) const {
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
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))) {
size_t TrailingZeros = CstInt->getValue().countr_zero();
} else if (auto *CE = dyn_cast<ConstantExpr>(this)) {
// Determine the alignment of inttoptr(C).
if (CE->getOpcode() == Instruction::IntToPtr &&
isa<ConstantInt>(CE->getOperand(0))) {
ConstantInt *IntPtr = cast<ConstantInt>(CE->getOperand(0));
size_t TrailingZeros = IntPtr->getValue().countr_zero();
// While the actual alignment may be large, elsewhere we have
// an arbitrary upper alignmet limit, so let's clamp to it.
return Align(TrailingZeros < Value::MaxAlignmentExponent
Expand Down