@@ -2715,7 +2715,8 @@ class llvm::sroa::AllocaSliceRewriter
2715
2715
2716
2716
// Do this after copyMetadataForLoad() to preserve the TBAA shift.
2717
2717
if (AATags)
2718
- NewLI->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
2718
+ NewLI->setAAMetadata (AATags.adjustForAccess (
2719
+ NewBeginOffset - BeginOffset, NewLI->getType (), DL));
2719
2720
2720
2721
// Try to preserve nonnull metadata
2721
2722
V = NewLI;
@@ -2736,8 +2737,11 @@ class llvm::sroa::AllocaSliceRewriter
2736
2737
LoadInst *NewLI =
2737
2738
IRB.CreateAlignedLoad (TargetTy, getNewAllocaSlicePtr (IRB, LTy),
2738
2739
getSliceAlign (), LI.isVolatile (), LI.getName ());
2740
+
2739
2741
if (AATags)
2740
- NewLI->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
2742
+ NewLI->setAAMetadata (AATags.adjustForAccess (
2743
+ NewBeginOffset - BeginOffset, NewLI->getType (), DL));
2744
+
2741
2745
if (LI.isVolatile ())
2742
2746
NewLI->setAtomic (LI.getOrdering (), LI.getSyncScopeID ());
2743
2747
NewLI->copyMetadata (LI, {LLVMContext::MD_mem_parallel_loop_access,
@@ -2807,7 +2811,8 @@ class llvm::sroa::AllocaSliceRewriter
2807
2811
Store->copyMetadata (SI, {LLVMContext::MD_mem_parallel_loop_access,
2808
2812
LLVMContext::MD_access_group});
2809
2813
if (AATags)
2810
- Store->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
2814
+ Store->setAAMetadata (AATags.adjustForAccess (NewBeginOffset - BeginOffset,
2815
+ V->getType (), DL));
2811
2816
Pass.DeadInsts .push_back (&SI);
2812
2817
2813
2818
// NOTE: Careful to use OrigV rather than V.
@@ -2834,7 +2839,8 @@ class llvm::sroa::AllocaSliceRewriter
2834
2839
Store->copyMetadata (SI, {LLVMContext::MD_mem_parallel_loop_access,
2835
2840
LLVMContext::MD_access_group});
2836
2841
if (AATags)
2837
- Store->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
2842
+ Store->setAAMetadata (AATags.adjustForAccess (NewBeginOffset - BeginOffset,
2843
+ V->getType (), DL));
2838
2844
2839
2845
migrateDebugInfo (&OldAI, IsSplit, NewBeginOffset * 8 , SliceSize * 8 , &SI,
2840
2846
Store, Store->getPointerOperand (),
@@ -2910,7 +2916,8 @@ class llvm::sroa::AllocaSliceRewriter
2910
2916
NewSI->copyMetadata (SI, {LLVMContext::MD_mem_parallel_loop_access,
2911
2917
LLVMContext::MD_access_group});
2912
2918
if (AATags)
2913
- NewSI->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
2919
+ NewSI->setAAMetadata (AATags.adjustForAccess (NewBeginOffset - BeginOffset,
2920
+ V->getType (), DL));
2914
2921
if (SI.isVolatile ())
2915
2922
NewSI->setAtomic (SI.getOrdering (), SI.getSyncScopeID ());
2916
2923
if (NewSI->isAtomic ())
@@ -3011,12 +3018,14 @@ class llvm::sroa::AllocaSliceRewriter
3011
3018
// a single value type, just emit a memset.
3012
3019
if (!CanContinue) {
3013
3020
Type *SizeTy = II.getLength ()->getType ();
3014
- Constant *Size = ConstantInt::get (SizeTy, NewEndOffset - NewBeginOffset);
3021
+ unsigned Sz = NewEndOffset - NewBeginOffset;
3022
+ Constant *Size = ConstantInt::get (SizeTy, Sz);
3015
3023
MemIntrinsic *New = cast<MemIntrinsic>(IRB.CreateMemSet (
3016
3024
getNewAllocaSlicePtr (IRB, OldPtr->getType ()), II.getValue (), Size,
3017
3025
MaybeAlign (getSliceAlign ()), II.isVolatile ()));
3018
3026
if (AATags)
3019
- New->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
3027
+ New->setAAMetadata (
3028
+ AATags.adjustForAccess (NewBeginOffset - BeginOffset, Sz));
3020
3029
3021
3030
migrateDebugInfo (&OldAI, IsSplit, NewBeginOffset * 8 , SliceSize * 8 , &II,
3022
3031
New, New->getRawDest (), nullptr , DL);
@@ -3092,7 +3101,8 @@ class llvm::sroa::AllocaSliceRewriter
3092
3101
New->copyMetadata (II, {LLVMContext::MD_mem_parallel_loop_access,
3093
3102
LLVMContext::MD_access_group});
3094
3103
if (AATags)
3095
- New->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
3104
+ New->setAAMetadata (AATags.adjustForAccess (NewBeginOffset - BeginOffset,
3105
+ V->getType (), DL));
3096
3106
3097
3107
migrateDebugInfo (&OldAI, IsSplit, NewBeginOffset * 8 , SliceSize * 8 , &II,
3098
3108
New, New->getPointerOperand (), V, DL);
@@ -3296,7 +3306,8 @@ class llvm::sroa::AllocaSliceRewriter
3296
3306
Load->copyMetadata (II, {LLVMContext::MD_mem_parallel_loop_access,
3297
3307
LLVMContext::MD_access_group});
3298
3308
if (AATags)
3299
- Load->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
3309
+ Load->setAAMetadata (AATags.adjustForAccess (NewBeginOffset - BeginOffset,
3310
+ Load->getType (), DL));
3300
3311
Src = Load;
3301
3312
}
3302
3313
@@ -3318,7 +3329,8 @@ class llvm::sroa::AllocaSliceRewriter
3318
3329
Store->copyMetadata (II, {LLVMContext::MD_mem_parallel_loop_access,
3319
3330
LLVMContext::MD_access_group});
3320
3331
if (AATags)
3321
- Store->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
3332
+ Store->setAAMetadata (AATags.adjustForAccess (NewBeginOffset - BeginOffset,
3333
+ Src->getType (), DL));
3322
3334
3323
3335
APInt Offset (DL.getIndexTypeSizeInBits (DstPtr->getType ()), 0 );
3324
3336
if (IsDest) {
@@ -3643,7 +3655,8 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
3643
3655
DL.getIndexSizeInBits (Ptr->getType ()->getPointerAddressSpace ()), 0 );
3644
3656
if (AATags &&
3645
3657
GEPOperator::accumulateConstantOffset (BaseTy, GEPIndices, DL, Offset))
3646
- Load->setAAMetadata (AATags.shift (Offset.getZExtValue ()));
3658
+ Load->setAAMetadata (
3659
+ AATags.adjustForAccess (Offset.getZExtValue (), Load->getType (), DL));
3647
3660
3648
3661
Agg = IRB.CreateInsertValue (Agg, Load, Indices, Name + " .insert" );
3649
3662
LLVM_DEBUG (dbgs () << " to: " << *Load << " \n " );
@@ -3694,8 +3707,10 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
3694
3707
APInt Offset (
3695
3708
DL.getIndexSizeInBits (Ptr->getType ()->getPointerAddressSpace ()), 0 );
3696
3709
GEPOperator::accumulateConstantOffset (BaseTy, GEPIndices, DL, Offset);
3697
- if (AATags)
3698
- Store->setAAMetadata (AATags.shift (Offset.getZExtValue ()));
3710
+ if (AATags) {
3711
+ Store->setAAMetadata (AATags.adjustForAccess (
3712
+ Offset.getZExtValue (), ExtractValue->getType (), DL));
3713
+ }
3699
3714
3700
3715
// migrateDebugInfo requires the base Alloca. Walk to it from this gep.
3701
3716
// If we cannot (because there's an intervening non-const or unbounded
@@ -4317,6 +4332,7 @@ bool SROAPass::presplitLoadsAndStores(AllocaInst &AI, AllocaSlices &AS) {
4317
4332
4318
4333
Value *StoreBasePtr = SI->getPointerOperand ();
4319
4334
IRB.SetInsertPoint (SI);
4335
+ AAMDNodes AATags = SI->getAAMetadata ();
4320
4336
4321
4337
LLVM_DEBUG (dbgs () << " Splitting store of load: " << *SI << " \n " );
4322
4338
@@ -4337,6 +4353,10 @@ bool SROAPass::presplitLoadsAndStores(AllocaInst &AI, AllocaSlices &AS) {
4337
4353
PStore->copyMetadata (*SI, {LLVMContext::MD_mem_parallel_loop_access,
4338
4354
LLVMContext::MD_access_group,
4339
4355
LLVMContext::MD_DIAssignID});
4356
+
4357
+ if (AATags)
4358
+ PStore->setAAMetadata (
4359
+ AATags.adjustForAccess (PartOffset, PLoad->getType (), DL));
4340
4360
LLVM_DEBUG (dbgs () << " +" << PartOffset << " :" << *PStore << " \n " );
4341
4361
}
4342
4362
0 commit comments