Skip to content

Commit 084ca63

Browse files
committed
[EarlyCSE] Only combine metadata for load CSE
There is no need to combine metadata if we're performing store to load forwarding. In that case we would end up combining metadata on an unrelated load instruction.
1 parent a67a21b commit 084ca63

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

llvm/lib/Transforms/Scalar/EarlyCSE.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,13 @@ class EarlyCSE {
594594
unsigned Generation = 0;
595595
int MatchingId = -1;
596596
bool IsAtomic = false;
597+
bool IsLoad = false;
597598

598599
LoadValue() = default;
599600
LoadValue(Instruction *Inst, unsigned Generation, unsigned MatchingId,
600-
bool IsAtomic)
601+
bool IsAtomic, bool IsLoad)
601602
: DefInst(Inst), Generation(Generation), MatchingId(MatchingId),
602-
IsAtomic(IsAtomic) {}
603+
IsAtomic(IsAtomic), IsLoad(IsLoad) {}
603604
};
604605

605606
using LoadMapAllocator =
@@ -1492,8 +1493,9 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
14921493
LLVM_DEBUG(dbgs() << "Skipping due to debug counter\n");
14931494
continue;
14941495
}
1495-
if (auto *I = dyn_cast<Instruction>(Op))
1496-
combineMetadataForCSE(I, &Inst, false);
1496+
if (InVal.IsLoad)
1497+
if (auto *I = dyn_cast<Instruction>(Op))
1498+
combineMetadataForCSE(I, &Inst, false);
14971499
if (!Inst.use_empty())
14981500
Inst.replaceAllUsesWith(Op);
14991501
salvageKnowledge(&Inst, &AC);
@@ -1508,7 +1510,8 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
15081510
AvailableLoads.insert(MemInst.getPointerOperand(),
15091511
LoadValue(&Inst, CurrentGeneration,
15101512
MemInst.getMatchingId(),
1511-
MemInst.isAtomic()));
1513+
MemInst.isAtomic(),
1514+
MemInst.isLoad()));
15121515
LastStore = nullptr;
15131516
continue;
15141517
}
@@ -1632,7 +1635,8 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
16321635
AvailableLoads.insert(MemInst.getPointerOperand(),
16331636
LoadValue(&Inst, CurrentGeneration,
16341637
MemInst.getMatchingId(),
1635-
MemInst.isAtomic()));
1638+
MemInst.isAtomic(),
1639+
MemInst.isLoad()));
16361640

16371641
// Remember that this was the last unordered store we saw for DSE. We
16381642
// don't yet handle DSE on ordered or volatile stores since we don't

llvm/test/Transforms/EarlyCSE/flags.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ define void @load_first_nonnull_noundef(ptr %p) {
9393

9494
define ptr @store_to_load_forward(ptr %p, ptr %p2) {
9595
; CHECK-LABEL: @store_to_load_forward(
96-
; CHECK-NEXT: [[P3:%.*]] = load ptr, ptr [[P:%.*]], align 8
96+
; CHECK-NEXT: [[P3:%.*]] = load ptr, ptr [[P:%.*]], align 8, !nonnull !0
9797
; CHECK-NEXT: store ptr [[P3]], ptr [[P2:%.*]], align 8
9898
; CHECK-NEXT: ret ptr [[P3]]
9999
;

0 commit comments

Comments
 (0)