// by every program that can detect any optimisation of that kind: either
// it is racy (undefined) or there is a release followed by an acquire
// between the pair of accesses under consideration.
- bool HasSeenAcquire = false;
if (isLoad && QueryInst) {
LoadInst *LI = dyn_cast<LoadInst>(QueryInst);
// Atomic loads have complications involved.
// A Monotonic (or higher) load is OK if the query inst is itself not atomic.
- // An Acquire (or higher) load sets the HasSeenAcquire flag, so that any
- // release store will know to return getClobber.
// FIXME: This is overly conservative.
if (LI->isAtomic() && LI->getOrdering() > Unordered) {
if (!QueryInst)
return MemDepResult::getClobber(LI);
+ if (LI->getOrdering() != Monotonic)
+ return MemDepResult::getClobber(LI);
if (auto *QueryLI = dyn_cast<LoadInst>(QueryInst)) {
if (!QueryLI->isSimple())
return MemDepResult::getClobber(LI);
} else if (QueryInst->mayReadOrWriteMemory()) {
return MemDepResult::getClobber(LI);
}
-
- if (isAtLeastAcquire(LI->getOrdering()))
- HasSeenAcquire = true;
}
AliasAnalysis::Location LoadLoc = AA->getLocation(LI);
if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
// Atomic stores have complications involved.
// A Monotonic store is OK if the query inst is itself not atomic.
- // A Release (or higher) store further requires that no acquire load
- // has been seen.
// FIXME: This is overly conservative.
if (!SI->isUnordered()) {
if (!QueryInst)
return MemDepResult::getClobber(SI);
+ if (SI->getOrdering() != Monotonic)
+ return MemDepResult::getClobber(SI);
if (auto *QueryLI = dyn_cast<LoadInst>(QueryInst)) {
if (!QueryLI->isSimple())
return MemDepResult::getClobber(SI);
} else if (QueryInst->mayReadOrWriteMemory()) {
return MemDepResult::getClobber(SI);
}
-
- if (HasSeenAcquire && isAtLeastRelease(SI->getOrdering()))
- return MemDepResult::getClobber(SI);
}
// FIXME: this is overly conservative.
ret void
}
-; DSE across seq_cst load (allowed)
-define i32 @test2() {
-; CHECK-LABEL: test2
-; CHECK-NOT: store i32 0
-; CHECK: store i32 1
- store i32 0, i32* @x
- %x = load atomic i32, i32* @y seq_cst, align 4
- store i32 1, i32* @x
- ret i32 %x
-}
-
-; DSE across seq_cst store (allowed)
-define void @test3() {
-; CHECK-LABEL: test3
-; CHECK-NOT: store i32 0
-; CHECK: store atomic i32 2
- store i32 0, i32* @x
- store atomic i32 2, i32* @y seq_cst, align 4
- store i32 1, i32* @x
- ret void
-}
-
; DSE remove unordered store (allowed)
define void @test4() {
; CHECK-LABEL: test4
ret void
}
-; DSE is allowed across a pair of an atomic read and then write.
-define i32 @test13() {
-; CHECK-LABEL: test13
-; CHECK-NOT: store i32 0
-; CHECK: store i32 1
- store i32 0, i32* @x
- %x = load atomic i32, i32* @y seq_cst, align 4
- store atomic i32 %x, i32* @y seq_cst, align 4
- store i32 1, i32* @x
- ret i32 %x
-}
-
-; Same if it is acquire-release instead of seq_cst/seq_cst
-define i32 @test14() {
-; CHECK-LABEL: test14
-; CHECK-NOT: store i32 0
-; CHECK: store i32 1
- store i32 0, i32* @x
- %x = load atomic i32, i32* @y acquire, align 4
- store atomic i32 %x, i32* @y release, align 4
- store i32 1, i32* @x
- ret i32 %x
-}
-
; But DSE is not allowed across a release-acquire pair.
define i32 @test15() {
; CHECK-LABEL: test15
ret i32 %z
}
-; GVN across seq_cst store (allowed)
-define i32 @test2() nounwind uwtable ssp {
-; CHECK-LABEL: test2
-; CHECK: add i32 %x, %x
-entry:
- %x = load i32, i32* @y
- store atomic i32 %x, i32* @x seq_cst, align 4
- %y = load i32, i32* @y
- %z = add i32 %x, %y
- ret i32 %z
-}
-
; GVN across unordered load (allowed)
define i32 @test3() nounwind uwtable ssp {
; CHECK-LABEL: test3
ret i32 %b
}
-; GVN across acquire load (allowed as the original load was not atomic)
-define i32 @test4() nounwind uwtable ssp {
-; CHECK-LABEL: test4
-; CHECK: load atomic i32, i32* @x
-; CHECK-NOT: load i32, i32* @y
-entry:
- %x = load i32, i32* @y
- %y = load atomic i32, i32* @x seq_cst, align 4
- %x2 = load i32, i32* @y
- %x3 = add i32 %x, %x2
- %y2 = add i32 %y, %x3
- ret i32 %y2
-}
-
; GVN load to unordered load (allowed)
define i32 @test5() nounwind uwtable ssp {
; CHECK-LABEL: test5
ret i32 %z
}
-; GVN across acquire-release pair (allowed)
-define i32 @test8() nounwind uwtable ssp {
-; CHECK-LABEL: test8
-; CHECK: add i32 %x, %x
-entry:
- %x = load i32, i32* @y
- %w = load atomic i32, i32* @x acquire, align 4
- store atomic i32 %x, i32* @x release, align 4
- %y = load i32, i32* @y
- %z = add i32 %x, %y
- ret i32 %z
-}
-
; GVN across monotonic store (allowed)
define i32 @test9() nounwind uwtable ssp {
; CHECK-LABEL: test9
ret i32 %z
}
+define i32 @PR22708(i1 %flag) {
+; CHECK-LABEL: PR22708
+entry:
+ br i1 %flag, label %if.then, label %if.end
+
+if.then:
+ store i32 43, i32* @y, align 4
+; CHECK: store i32 43, i32* @y, align 4
+ br label %if.end
+
+if.end:
+ load atomic i32, i32* @x acquire, align 4
+ %load = load i32, i32* @y, align 4
+; CHECK: load atomic i32, i32* @x acquire, align 4
+; CHECK: load i32, i32* @y, align 4
+ ret i32 %load
+}