@@ -3199,12 +3199,13 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
3199
3199
// TODO: apply range metadata for range check patterns?
3200
3200
}
3201
3201
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.
3206
3202
for (unsigned Idx = 0 ; Idx < II->getNumOperandBundles (); Idx++) {
3207
3203
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.
3208
3209
if (OBU.getTagName () == " separate_storage" ) {
3209
3210
assert (OBU.Inputs .size () == 2 );
3210
3211
auto MaybeSimplifyHint = [&](const Use &U) {
@@ -3218,6 +3219,28 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
3218
3219
MaybeSimplifyHint (OBU.Inputs [0 ]);
3219
3220
MaybeSimplifyHint (OBU.Inputs [1 ]);
3220
3221
}
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
+ }
3221
3244
}
3222
3245
3223
3246
// Convert nonnull assume like:
0 commit comments