Skip to content

Commit 8441043

Browse files
committed
step
1 parent 4f21639 commit 8441043

File tree

2 files changed

+49
-42
lines changed

2 files changed

+49
-42
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

-36
Original file line numberDiff line numberDiff line change
@@ -3226,42 +3226,6 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
32263226
MaybeSimplifyHint(OBU.Inputs[0]);
32273227
MaybeSimplifyHint(OBU.Inputs[1]);
32283228
}
3229-
3230-
if (OBU.getTagName() == "align" && OBU.Inputs.size() == 2) {
3231-
RetainedKnowledge RK = getKnowledgeFromBundle(
3232-
*cast<AssumeInst>(II), II->bundle_op_info_begin()[Idx]);
3233-
if (!RK || RK.AttrKind != Attribute::Alignment ||
3234-
!isPowerOf2_64(RK.ArgValue))
3235-
continue;
3236-
SetVector<const Instruction *> WorkList;
3237-
bool AlignNeeded = false;
3238-
WorkList.insert(II);
3239-
for (unsigned I = 0; I != WorkList.size(); ++I) {
3240-
if (auto *LI = dyn_cast<LoadInst>(WorkList[I])) {
3241-
if (auto *AlignMD = LI->getMetadata(LLVMContext::MD_align)) {
3242-
auto *A = mdconst::extract<ConstantInt>(AlignMD->getOperand(0));
3243-
3244-
if (A->getZExtValue() % RK.ArgValue != 0) {
3245-
AlignNeeded = true;
3246-
break;
3247-
}
3248-
}
3249-
}
3250-
if (isa<ICmpInst>(WorkList[I])) {
3251-
AlignNeeded = true;
3252-
break;
3253-
}
3254-
if (WorkList.size() > 16) {
3255-
AlignNeeded = true;
3256-
break;
3257-
}
3258-
3259-
for (const User *U : WorkList[I]->users())
3260-
WorkList.insert(cast<Instruction>(U));
3261-
}
3262-
auto *New = CallBase::removeOperandBundle(II, OBU.getTagID());
3263-
return New;
3264-
}
32653229
}
32663230

32673231
// Convert nonnull assume like:

llvm/lib/Transforms/Scalar/EarlyCSE.cpp

+49-6
Original file line numberDiff line numberDiff line change
@@ -1606,15 +1606,58 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
16061606
// alignment assumption. Note that this doesn't use salavageKnowledge,
16071607
// as we need to create the assumption for the value we replaced the
16081608
// load with.
1609-
if (Inst.hasMetadata(LLVMContext::MD_noundef)) {
1610-
if (auto *AlignMD = Inst.getMetadata(LLVMContext::MD_align)) {
1609+
if (auto *AlignMD = Inst.getMetadata(LLVMContext::MD_align)) {
1610+
if (Inst.hasMetadata(LLVMContext::MD_noundef) ||
1611+
programUndefinedIfPoison(&Inst)) {
16111612
Inst.setMetadata(LLVMContext::MD_align, nullptr);
1612-
auto *A = mdconst::extract<ConstantInt>(AlignMD->getOperand(0));
1613+
auto *B = mdconst::extract<ConstantInt>(AlignMD->getOperand(0));
16131614
auto KB = computeKnownBits(Op, SQ.DL);
16141615
unsigned AlignFromKB = 1 << KB.countMinTrailingZeros();
1615-
if (AlignFromKB < A->getZExtValue()) {
1616-
IRBuilder B(&Inst);
1617-
B.CreateAlignmentAssumption(SQ.DL, Op, A);
1616+
if (AlignFromKB < B->getZExtValue()) {
1617+
SetVector<const Value *> WorkList;
1618+
bool AlignNeeded = false;
1619+
for (const User *U : Inst.users())
1620+
if (auto *I = dyn_cast<Instruction>(U))
1621+
WorkList.insert(I);
1622+
1623+
for (unsigned I = 0; I != WorkList.size(); ++I) {
1624+
auto *Curr = WorkList[I];
1625+
if (auto *LI = dyn_cast<LoadInst>(Curr)) {
1626+
if (LI->getAlign().value() < B->getZExtValue()) {
1627+
AlignNeeded = true;
1628+
break;
1629+
}
1630+
continue;
1631+
}
1632+
if (auto *SI = dyn_cast<StoreInst>(Curr)) {
1633+
if (SI->getAlign().value() < B->getZExtValue()) {
1634+
AlignNeeded = true;
1635+
break;
1636+
}
1637+
continue;
1638+
}
1639+
if (isa<ReturnInst>(Curr)) {
1640+
AlignNeeded = true;
1641+
break;
1642+
}
1643+
if (isa<ICmpInst>(Curr) &&
1644+
!isa<Constant>(cast<Instruction>(Curr)->getOperand(0)) &&
1645+
!isa<Constant>(cast<Instruction>(Curr)->getOperand(1))) {
1646+
AlignNeeded = true;
1647+
break;
1648+
}
1649+
if (WorkList.size() > 16) {
1650+
AlignNeeded = true;
1651+
break;
1652+
}
1653+
1654+
for (const User *U : Curr->users())
1655+
WorkList.insert(cast<Instruction>(U));
1656+
}
1657+
if (AlignNeeded) {
1658+
IRBuilder Builder(&Inst);
1659+
Builder.CreateAlignmentAssumption(SQ.DL, Op, B);
1660+
}
16181661
}
16191662
}
16201663
}

0 commit comments

Comments
 (0)