@@ -3385,12 +3385,13 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
3385
3385
// TODO: apply range metadata for range check patterns?
3386
3386
}
3387
3387
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.
3392
3388
for (unsigned Idx = 0 ; Idx < II->getNumOperandBundles (); Idx++) {
3393
3389
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.
3394
3395
if (OBU.getTagName () == " separate_storage" ) {
3395
3396
assert (OBU.Inputs .size () == 2 );
3396
3397
auto MaybeSimplifyHint = [&](const Use &U) {
@@ -3404,6 +3405,32 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
3404
3405
MaybeSimplifyHint (OBU.Inputs [0 ]);
3405
3406
MaybeSimplifyHint (OBU.Inputs [1 ]);
3406
3407
}
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
+ }
3407
3434
}
3408
3435
3409
3436
// Convert nonnull assume like:
0 commit comments