@@ -3385,12 +3385,13 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
33853385 // TODO: apply range metadata for range check patterns?
33863386 }
33873387
3388- // Separate storage assumptions apply to the underlying allocations, not any
3389- // particular pointer within them. When evaluating the hints for AA purposes
3390- // we getUnderlyingObject them; by precomputing the answers here we can
3391- // avoid having to do so repeatedly there.
33923388 for (unsigned Idx = 0 ; Idx < II->getNumOperandBundles (); Idx++) {
33933389 OperandBundleUse OBU = II->getOperandBundleAt (Idx);
3390+
3391+ // Separate storage assumptions apply to the underlying allocations, not
3392+ // any particular pointer within them. When evaluating the hints for AA
3393+ // purposes we getUnderlyingObject them; by precomputing the answers here
3394+ // we can avoid having to do so repeatedly there.
33943395 if (OBU.getTagName () == " separate_storage" ) {
33953396 assert (OBU.Inputs .size () == 2 );
33963397 auto MaybeSimplifyHint = [&](const Use &U) {
@@ -3404,6 +3405,32 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
34043405 MaybeSimplifyHint (OBU.Inputs [0 ]);
34053406 MaybeSimplifyHint (OBU.Inputs [1 ]);
34063407 }
3408+
3409+ // Try to remove redundant alignment assumptions.
3410+ if (OBU.getTagName () == " align" && OBU.Inputs .size () == 2 ) {
3411+ RetainedKnowledge RK = getKnowledgeFromOperandInAssume (
3412+ *cast<AssumeInst>(II), II->arg_size () + Idx);
3413+ if (!RK || RK.AttrKind != Attribute::Alignment ||
3414+ !isPowerOf2_64 (RK.ArgValue ) || !isa<ConstantInt>(RK.IRArgValue ))
3415+ continue ;
3416+
3417+ // Don't try to remove align assumptions for pointers derived from
3418+ // arguments. We might lose information if the function gets inline and
3419+ // the align argument attribute disappears.
3420+ Value *UO = getUnderlyingObject (RK.WasOn );
3421+ if (!UO || isa<Argument>(UO))
3422+ continue ;
3423+
3424+ // Compute known bits for the pointer, passing nullptr as context to
3425+ // avoid computeKnownBits using the assumption we are about to remove
3426+ // for reasoning.
3427+ KnownBits Known = computeKnownBits (RK.WasOn , /* CtxI=*/ nullptr );
3428+ unsigned TZ = std::min (Known.countMinTrailingZeros (),
3429+ Value::MaxAlignmentExponent);
3430+ if ((1ULL << TZ) < RK.ArgValue )
3431+ continue ;
3432+ return CallBase::removeOperandBundle (II, OBU.getTagID ());
3433+ }
34073434 }
34083435
34093436 // Convert nonnull assume like:
0 commit comments