Skip to content

Commit

Permalink
Simplify; no significant functionality change.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133086 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
eefriedman committed Jun 15, 2011
1 parent 0ad2dc4 commit b53c793
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions lib/Transforms/Utils/Local.cpp
Expand Up @@ -706,39 +706,15 @@ bool llvm::EliminateDuplicatePHINodes(BasicBlock *BB) {
///
static unsigned enforceKnownAlignment(Value *V, unsigned Align,
unsigned PrefAlign) {
V = V->stripPointerCasts();

User *U = dyn_cast<User>(V);
if (!U) return Align;

switch (Operator::getOpcode(U)) {
default: break;
case Instruction::BitCast:
return enforceKnownAlignment(U->getOperand(0), Align, PrefAlign);
case Instruction::GetElementPtr: {
// If all indexes are zero, it is just the alignment of the base pointer.
bool AllZeroOperands = true;
for (User::op_iterator i = U->op_begin() + 1, e = U->op_end(); i != e; ++i)
if (!isa<Constant>(*i) ||
!cast<Constant>(*i)->isNullValue()) {
AllZeroOperands = false;
break;
}

if (AllZeroOperands) {
// Treat this like a bitcast.
return enforceKnownAlignment(U->getOperand(0), Align, PrefAlign);
}
return Align;
}
case Instruction::Alloca: {
AllocaInst *AI = cast<AllocaInst>(V);
if (AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
// If there is a requested alignment and if this is an alloca, round up.
if (AI->getAlignment() >= PrefAlign)
return AI->getAlignment();
AI->setAlignment(PrefAlign);
return PrefAlign;
}
}

if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
// If there is a large requested alignment and we can, bump up the alignment
Expand Down

0 comments on commit b53c793

Please sign in to comment.