Commit 084ca632 authored by Nikita Popov's avatar Nikita Popov
Browse files

[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.
parent a67a21bf
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -594,12 +594,13 @@ public:
    unsigned Generation = 0;
    int MatchingId = -1;
    bool IsAtomic = false;
    bool IsLoad = false;

    LoadValue() = default;
    LoadValue(Instruction *Inst, unsigned Generation, unsigned MatchingId,
              bool IsAtomic)
              bool IsAtomic, bool IsLoad)
        : DefInst(Inst), Generation(Generation), MatchingId(MatchingId),
          IsAtomic(IsAtomic) {}
          IsAtomic(IsAtomic), IsLoad(IsLoad) {}
  };

  using LoadMapAllocator =
@@ -1492,6 +1493,7 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
          LLVM_DEBUG(dbgs() << "Skipping due to debug counter\n");
          continue;
        }
        if (InVal.IsLoad)
          if (auto *I = dyn_cast<Instruction>(Op))
            combineMetadataForCSE(I, &Inst, false);
        if (!Inst.use_empty())
@@ -1508,7 +1510,8 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
      AvailableLoads.insert(MemInst.getPointerOperand(),
                            LoadValue(&Inst, CurrentGeneration,
                                      MemInst.getMatchingId(),
                                      MemInst.isAtomic()));
                                      MemInst.isAtomic(),
                                      MemInst.isLoad()));
      LastStore = nullptr;
      continue;
    }
@@ -1632,7 +1635,8 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
        AvailableLoads.insert(MemInst.getPointerOperand(),
                              LoadValue(&Inst, CurrentGeneration,
                                        MemInst.getMatchingId(),
                                        MemInst.isAtomic()));
                                        MemInst.isAtomic(),
                                        MemInst.isLoad()));

        // Remember that this was the last unordered store we saw for DSE. We
        // don't yet handle DSE on ordered or volatile stores since we don't
+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ define void @load_first_nonnull_noundef(ptr %p) {

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