@@ -3199,12 +3199,13 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
31993199 // TODO: apply range metadata for range check patterns?
32003200 }
32013201
3202- // Separate storage assumptions apply to the underlying allocations, not any
3203- // particular pointer within them. When evaluating the hints for AA purposes
3204- // we getUnderlyingObject them; by precomputing the answers here we can
3205- // avoid having to do so repeatedly there.
32063202 for (unsigned Idx = 0 ; Idx < II->getNumOperandBundles (); Idx++) {
32073203 OperandBundleUse OBU = II->getOperandBundleAt (Idx);
3204+
3205+ // Separate storage assumptions apply to the underlying allocations, not
3206+ // any particular pointer within them. When evaluating the hints for AA
3207+ // purposes we getUnderlyingObject them; by precomputing the answers here
3208+ // we can avoid having to do so repeatedly there.
32083209 if (OBU.getTagName () == " separate_storage" ) {
32093210 assert (OBU.Inputs .size () == 2 );
32103211 auto MaybeSimplifyHint = [&](const Use &U) {
@@ -3218,6 +3219,28 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
32183219 MaybeSimplifyHint (OBU.Inputs [0 ]);
32193220 MaybeSimplifyHint (OBU.Inputs [1 ]);
32203221 }
3222+
3223+ // Try to remove redundant alignment assumptions.
3224+ if (OBU.getTagName () == " align" && OBU.Inputs .size () == 2 ) {
3225+ RetainedKnowledge RK = getKnowledgeFromBundle (
3226+ *cast<AssumeInst>(II), II->bundle_op_info_begin ()[Idx]);
3227+ if (!RK || RK.AttrKind != Attribute::Alignment ||
3228+ !isPowerOf2_64 (RK.ArgValue ))
3229+ continue ;
3230+
3231+ // Try to get the instruction before the assumption to use as context.
3232+ Instruction *CtxI = nullptr ;
3233+ if (CtxI && II->getParent ()->begin () != II->getIterator ())
3234+ CtxI = II->getPrevNode ();
3235+
3236+ auto Known = computeKnownBits (RK.WasOn , 1 , CtxI);
3237+ unsigned KnownAlign = 1 << Known.countMinTrailingZeros ();
3238+ if (KnownAlign < RK.ArgValue )
3239+ continue ;
3240+
3241+ auto *New = CallBase::removeOperandBundle (II, OBU.getTagID ());
3242+ return New;
3243+ }
32213244 }
32223245
32233246 // Convert nonnull assume like:
0 commit comments