Skip to content

Commit bd15339

Browse files
committed
!fixup only preserve AA metadata on store if it executes.
1 parent 6365998 commit bd15339

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,7 @@ class LoopPromoter : public LoadAndStorePromoter {
18261826
ICFLoopSafetyInfo &SafetyInfo;
18271827
bool CanInsertStoresInExitBlocks;
18281828
ArrayRef<const Instruction *> Uses;
1829+
bool StoreIsGuanteedToExecute;
18291830

18301831
// We're about to add a use of V in a loop exit block. Insert an LCSSA phi
18311832
// (if legal) if doing so would add an out-of-loop use to an instruction
@@ -1852,13 +1853,15 @@ class LoopPromoter : public LoadAndStorePromoter {
18521853
SmallVectorImpl<MemoryAccess *> &MSSAIP, PredIteratorCache &PIC,
18531854
MemorySSAUpdater &MSSAU, LoopInfo &li, DebugLoc dl,
18541855
Align Alignment, bool UnorderedAtomic, const AAMDNodes &AATags,
1855-
ICFLoopSafetyInfo &SafetyInfo, bool CanInsertStoresInExitBlocks)
1856+
ICFLoopSafetyInfo &SafetyInfo, bool CanInsertStoresInExitBlocks,
1857+
bool StoreIsGuanteedToExecute)
18561858
: LoadAndStorePromoter(Insts, S), SomePtr(SP), LoopExitBlocks(LEB),
18571859
LoopInsertPts(LIP), MSSAInsertPts(MSSAIP), PredCache(PIC), MSSAU(MSSAU),
18581860
LI(li), DL(std::move(dl)), Alignment(Alignment),
18591861
UnorderedAtomic(UnorderedAtomic), AATags(AATags),
18601862
SafetyInfo(SafetyInfo),
1861-
CanInsertStoresInExitBlocks(CanInsertStoresInExitBlocks), Uses(Insts) {}
1863+
CanInsertStoresInExitBlocks(CanInsertStoresInExitBlocks), Uses(Insts),
1864+
StoreIsGuanteedToExecute(StoreIsGuanteedToExecute) {}
18621865

18631866
void insertStoresInLoopExitBlocks() {
18641867
// Insert stores after in the loop exit blocks. Each exit block gets a
@@ -1892,7 +1895,7 @@ class LoopPromoter : public LoadAndStorePromoter {
18921895
NewSI->setMetadata(LLVMContext::MD_DIAssignID, NewID);
18931896
}
18941897

1895-
if (AATags)
1898+
if (AATags && StoreIsGuanteedToExecute)
18961899
NewSI->setAAMetadata(AATags);
18971900

18981901
MemoryAccess *MSSAInsertPoint = MSSAInsertPts[i];
@@ -2090,7 +2093,8 @@ bool llvm::promoteLoopAccessesToScalars(
20902093
FoundLoadToPromote = true;
20912094

20922095
Align InstAlignment = Load->getAlign();
2093-
LoadIsGuaranteedToExecut |= SafetyInfo->isGuaranteedToExecute(*UI, DT, CurLoop);
2096+
LoadIsGuaranteedToExecute |=
2097+
SafetyInfo->isGuaranteedToExecute(*UI, DT, CurLoop);
20942098

20952099
// Note that proving a load safe to speculate requires proving
20962100
// sufficient alignment at the target location. Proving it guaranteed
@@ -2237,7 +2241,7 @@ bool llvm::promoteLoopAccessesToScalars(
22372241
LoopPromoter Promoter(SomePtr, LoopUses, SSA, ExitBlocks, InsertPts,
22382242
MSSAInsertPts, PIC, MSSAU, *LI, DL, Alignment,
22392243
SawUnorderedAtomic, AATags, *SafetyInfo,
2240-
StoreSafety == StoreSafe);
2244+
StoreSafety == StoreSafe, StoreIsGuanteedToExecute);
22412245

22422246
// Set up the preheader to have a definition of the value. It is the live-out
22432247
// value from the preheader that uses in the loop will use.

llvm/test/Transforms/LICM/hoist-metadata.ll

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ define void @noalias_metadata_load_may_not_execute() {
9292
; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_HEADER]], label [[EXIT]]
9393
; CHECK: exit:
9494
; CHECK-NEXT: [[ADD2:%.*]] = phi i32 [ [[ADD]], [[LOOP_LATCH]] ], [ [[ADD1]], [[LOOP_HEADER]] ]
95-
; CHECK-NEXT: store i32 [[ADD2]], ptr [[GEP]], align 4, !tbaa [[TBAA3:![0-9]+]], !noalias [[META7:![0-9]+]]
95+
; CHECK-NEXT: store i32 [[ADD2]], ptr [[GEP]], align 4
9696
; CHECK-NEXT: ret void
9797
;
9898
entry:
@@ -132,11 +132,4 @@ exit:
132132
; CHECK: [[RNG0]] = !{i32 0, i32 10}
133133
; CHECK: [[META1]] = !{}
134134
; CHECK: [[META2]] = !{i64 4}
135-
; CHECK: [[TBAA3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
136-
; CHECK: [[META4]] = !{!"short", [[META5:![0-9]+]], i64 0}
137-
; CHECK: [[META5]] = !{!"omnipotent char", [[META6:![0-9]+]], i64 0}
138-
; CHECK: [[META6]] = !{!"Simple C/C++ TBAA"}
139-
; CHECK: [[META7]] = !{[[META8:![0-9]+]]}
140-
; CHECK: [[META8]] = distinct !{[[META8]], [[META9:![0-9]+]]}
141-
; CHECK: [[META9]] = distinct !{[[META9]]}
142135
;.

0 commit comments

Comments
 (0)