Skip to content

Commit 9d5628c

Browse files
authored
Remove unnecessary fence in GTO output (#7310)
GlobalTypeOptimization removes struct fields that have no reads, then optimizes out any sets of those fields. We were previously being overly conservative and replacing optimized seqcst sets with fences, but in fact those sets cannot possibly synchronize with anything because there are no reads. Stop emitting the unnecessary fences.
1 parent e4f4784 commit 9d5628c

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

src/passes/GlobalTypeOptimization.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -532,15 +532,9 @@ struct GlobalTypeOptimization : public Pass {
532532
needEHFixups = true;
533533
Expression* replacement =
534534
builder.makeDrop(builder.makeRefAs(RefAsNonNull, flipped));
535-
if (curr->order == MemoryOrder::SeqCst) {
536-
// If the removed set is sequentially consistent, we must insert a
537-
// seqcst fence to preserve the effect on the global order of seqcst
538-
// operations. No fence is necessary for release sets because there
539-
// are no reads for them to synchronize with given that we are
540-
// removing the field.
541-
replacement =
542-
builder.makeSequence(replacement, builder.makeAtomicFence());
543-
}
535+
// We only remove fields with no reads, so if this set is atomic,
536+
// there are no reads it can possibly synchronize with and we do not
537+
// need a fence.
544538
replaceCurrent(replacement);
545539
}
546540
}

test/lit/passes/gto-removals.wast

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,18 +1593,15 @@
15931593
;; CHECK-NEXT: )
15941594
;; CHECK-NEXT: )
15951595
;; CHECK-NEXT: )
1596-
;; CHECK-NEXT: (block
1597-
;; CHECK-NEXT: (drop
1598-
;; CHECK-NEXT: (ref.as_non_null
1599-
;; CHECK-NEXT: (block (result (ref $A))
1600-
;; CHECK-NEXT: (drop
1601-
;; CHECK-NEXT: (i32.const 1)
1602-
;; CHECK-NEXT: )
1603-
;; CHECK-NEXT: (local.get $0)
1596+
;; CHECK-NEXT: (drop
1597+
;; CHECK-NEXT: (ref.as_non_null
1598+
;; CHECK-NEXT: (block (result (ref $A))
1599+
;; CHECK-NEXT: (drop
1600+
;; CHECK-NEXT: (i32.const 1)
16041601
;; CHECK-NEXT: )
1602+
;; CHECK-NEXT: (local.get $0)
16051603
;; CHECK-NEXT: )
16061604
;; CHECK-NEXT: )
1607-
;; CHECK-NEXT: (atomic.fence)
16081605
;; CHECK-NEXT: )
16091606
;; CHECK-NEXT: )
16101607
(func $sets (param (ref $A))
@@ -1619,8 +1616,7 @@
16191616
(local.get 0)
16201617
(i32.const 1)
16211618
)
1622-
;; This requires a fence to keep the effect on the global order of seqcst
1623-
;; operations.
1619+
;; Same with a seqcst set.
16241620
(struct.atomic.set $A 0
16251621
(local.get 0)
16261622
(i32.const 1)

0 commit comments

Comments
 (0)