@@ -2914,7 +2914,8 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
29142914
29152915 // Do this after copyMetadataForLoad() to preserve the TBAA shift.
29162916 if (AATags)
2917- NewLI->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
2917+ NewLI->setAAMetadata (AATags.adjustForAccess (
2918+ NewBeginOffset - BeginOffset, NewLI->getType (), DL));
29182919
29192920 // Try to preserve nonnull metadata
29202921 V = NewLI;
@@ -2935,8 +2936,11 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
29352936 LoadInst *NewLI =
29362937 IRB.CreateAlignedLoad (TargetTy, getNewAllocaSlicePtr (IRB, LTy),
29372938 getSliceAlign (), LI.isVolatile (), LI.getName ());
2939+
29382940 if (AATags)
2939- NewLI->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
2941+ NewLI->setAAMetadata (AATags.adjustForAccess (
2942+ NewBeginOffset - BeginOffset, NewLI->getType (), DL));
2943+
29402944 if (LI.isVolatile ())
29412945 NewLI->setAtomic (LI.getOrdering (), LI.getSyncScopeID ());
29422946 NewLI->copyMetadata (LI, {LLVMContext::MD_mem_parallel_loop_access,
@@ -3011,7 +3015,8 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
30113015 Store->copyMetadata (SI, {LLVMContext::MD_mem_parallel_loop_access,
30123016 LLVMContext::MD_access_group});
30133017 if (AATags)
3014- Store->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
3018+ Store->setAAMetadata (AATags.adjustForAccess (NewBeginOffset - BeginOffset,
3019+ V->getType (), DL));
30153020 Pass.DeadInsts .push_back (&SI);
30163021
30173022 // NOTE: Careful to use OrigV rather than V.
@@ -3038,7 +3043,8 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
30383043 Store->copyMetadata (SI, {LLVMContext::MD_mem_parallel_loop_access,
30393044 LLVMContext::MD_access_group});
30403045 if (AATags)
3041- Store->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
3046+ Store->setAAMetadata (AATags.adjustForAccess (NewBeginOffset - BeginOffset,
3047+ V->getType (), DL));
30423048
30433049 migrateDebugInfo (&OldAI, IsSplit, NewBeginOffset * 8 , SliceSize * 8 , &SI,
30443050 Store, Store->getPointerOperand (),
@@ -3098,7 +3104,8 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
30983104 NewSI->copyMetadata (SI, {LLVMContext::MD_mem_parallel_loop_access,
30993105 LLVMContext::MD_access_group});
31003106 if (AATags)
3101- NewSI->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
3107+ NewSI->setAAMetadata (AATags.adjustForAccess (NewBeginOffset - BeginOffset,
3108+ V->getType (), DL));
31023109 if (SI.isVolatile ())
31033110 NewSI->setAtomic (SI.getOrdering (), SI.getSyncScopeID ());
31043111 if (NewSI->isAtomic ())
@@ -3200,12 +3207,14 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
32003207 // a single value type, just emit a memset.
32013208 if (!CanContinue) {
32023209 Type *SizeTy = II.getLength ()->getType ();
3203- Constant *Size = ConstantInt::get (SizeTy, NewEndOffset - NewBeginOffset);
3210+ unsigned Sz = NewEndOffset - NewBeginOffset;
3211+ Constant *Size = ConstantInt::get (SizeTy, Sz);
32043212 MemIntrinsic *New = cast<MemIntrinsic>(IRB.CreateMemSet (
32053213 getNewAllocaSlicePtr (IRB, OldPtr->getType ()), II.getValue (), Size,
32063214 MaybeAlign (getSliceAlign ()), II.isVolatile ()));
32073215 if (AATags)
3208- New->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
3216+ New->setAAMetadata (
3217+ AATags.adjustForAccess (NewBeginOffset - BeginOffset, Sz));
32093218
32103219 migrateDebugInfo (&OldAI, IsSplit, NewBeginOffset * 8 , SliceSize * 8 , &II,
32113220 New, New->getRawDest (), nullptr , DL);
@@ -3281,7 +3290,8 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
32813290 New->copyMetadata (II, {LLVMContext::MD_mem_parallel_loop_access,
32823291 LLVMContext::MD_access_group});
32833292 if (AATags)
3284- New->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
3293+ New->setAAMetadata (AATags.adjustForAccess (NewBeginOffset - BeginOffset,
3294+ V->getType (), DL));
32853295
32863296 migrateDebugInfo (&OldAI, IsSplit, NewBeginOffset * 8 , SliceSize * 8 , &II,
32873297 New, New->getPointerOperand (), V, DL);
@@ -3486,7 +3496,8 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
34863496 Load->copyMetadata (II, {LLVMContext::MD_mem_parallel_loop_access,
34873497 LLVMContext::MD_access_group});
34883498 if (AATags)
3489- Load->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
3499+ Load->setAAMetadata (AATags.adjustForAccess (NewBeginOffset - BeginOffset,
3500+ Load->getType (), DL));
34903501 Src = Load;
34913502 }
34923503
@@ -3508,7 +3519,8 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
35083519 Store->copyMetadata (II, {LLVMContext::MD_mem_parallel_loop_access,
35093520 LLVMContext::MD_access_group});
35103521 if (AATags)
3511- Store->setAAMetadata (AATags.shift (NewBeginOffset - BeginOffset));
3522+ Store->setAAMetadata (AATags.adjustForAccess (NewBeginOffset - BeginOffset,
3523+ Src->getType (), DL));
35123524
35133525 APInt Offset (DL.getIndexTypeSizeInBits (DstPtr->getType ()), 0 );
35143526 if (IsDest) {
@@ -3836,7 +3848,8 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
38363848 DL.getIndexSizeInBits (Ptr->getType ()->getPointerAddressSpace ()), 0 );
38373849 if (AATags &&
38383850 GEPOperator::accumulateConstantOffset (BaseTy, GEPIndices, DL, Offset))
3839- Load->setAAMetadata (AATags.shift (Offset.getZExtValue ()));
3851+ Load->setAAMetadata (
3852+ AATags.adjustForAccess (Offset.getZExtValue (), Load->getType (), DL));
38403853
38413854 Agg = IRB.CreateInsertValue (Agg, Load, Indices, Name + " .insert" );
38423855 LLVM_DEBUG (dbgs () << " to: " << *Load << " \n " );
@@ -3887,8 +3900,10 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
38873900 APInt Offset (
38883901 DL.getIndexSizeInBits (Ptr->getType ()->getPointerAddressSpace ()), 0 );
38893902 GEPOperator::accumulateConstantOffset (BaseTy, GEPIndices, DL, Offset);
3890- if (AATags)
3891- Store->setAAMetadata (AATags.shift (Offset.getZExtValue ()));
3903+ if (AATags) {
3904+ Store->setAAMetadata (AATags.adjustForAccess (
3905+ Offset.getZExtValue (), ExtractValue->getType (), DL));
3906+ }
38923907
38933908 // migrateDebugInfo requires the base Alloca. Walk to it from this gep.
38943909 // If we cannot (because there's an intervening non-const or unbounded
@@ -4542,6 +4557,7 @@ bool SROA::presplitLoadsAndStores(AllocaInst &AI, AllocaSlices &AS) {
45424557
45434558 Value *StoreBasePtr = SI->getPointerOperand ();
45444559 IRB.SetInsertPoint (SI);
4560+ AAMDNodes AATags = SI->getAAMetadata ();
45454561
45464562 LLVM_DEBUG (dbgs () << " Splitting store of load: " << *SI << " \n " );
45474563
@@ -4561,6 +4577,10 @@ bool SROA::presplitLoadsAndStores(AllocaInst &AI, AllocaSlices &AS) {
45614577 PStore->copyMetadata (*SI, {LLVMContext::MD_mem_parallel_loop_access,
45624578 LLVMContext::MD_access_group,
45634579 LLVMContext::MD_DIAssignID});
4580+
4581+ if (AATags)
4582+ PStore->setAAMetadata (
4583+ AATags.adjustForAccess (PartOffset, PLoad->getType (), DL));
45644584 LLVM_DEBUG (dbgs () << " +" << PartOffset << " :" << *PStore << " \n " );
45654585 }
45664586
0 commit comments