Skip to content

Commit 7c2fd23

Browse files
authored
Fix OptimizeInstructions for general Cmpxchg expected types (#8495)
OptimizeInstructions previously assumed incorrectly that the expected field of a StructCmpxchg would be a subtype of the accessed field type. In fact, it can be a supertype as long as it is a subtype of eq (or shared eq).
1 parent 410256a commit 7c2fd23

2 files changed

Lines changed: 180 additions & 69 deletions

File tree

src/passes/OptimizeInstructions.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,13 @@ struct OptimizeInstructions
21082108
// Just like other RMW operations, lower to basic operations when operating
21092109
// on unshared memory.
21102110
auto ref = builder.addVar(getFunction(), curr->ref->type);
2111-
auto expected = builder.addVar(getFunction(), curr->type);
2111+
auto expectedType = curr->type;
2112+
if (expectedType.isRef()) {
2113+
expectedType =
2114+
Type(HeapTypes::eq.getBasic(expectedType.getHeapType().getShared()),
2115+
Nullable);
2116+
}
2117+
auto expected = builder.addVar(getFunction(), expectedType);
21122118
auto replacement = builder.addVar(getFunction(), curr->type);
21132119
auto result = builder.addVar(getFunction(), curr->type);
21142120
auto* block =
@@ -2122,7 +2128,7 @@ struct OptimizeInstructions
21222128
MemoryOrder::Unordered,
21232129
curr->type),
21242130
curr->type);
2125-
auto* rhs = builder.makeLocalGet(expected, curr->type);
2131+
auto* rhs = builder.makeLocalGet(expected, expectedType);
21262132
Expression* pred = nullptr;
21272133
if (curr->type.isRef()) {
21282134
pred = builder.makeRefEq(lhs, rhs);

0 commit comments

Comments
 (0)