Skip to content

Commit abfd197

Browse files
committed
Remove align assumptions if possible.
1 parent 92457cd commit abfd197

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,6 +3226,42 @@ 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+
}
32293265
}
32303266

32313267
// Convert nonnull assume like:

0 commit comments

Comments
 (0)