summaryrefslogtreecommitdiff
path: root/src/passes/ConstantFieldPropagation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/ConstantFieldPropagation.cpp')
-rw-r--r--src/passes/ConstantFieldPropagation.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/passes/ConstantFieldPropagation.cpp b/src/passes/ConstantFieldPropagation.cpp
index c5b95b15a..f97b440ea 100644
--- a/src/passes/ConstantFieldPropagation.cpp
+++ b/src/passes/ConstantFieldPropagation.cpp
@@ -27,6 +27,8 @@
// wasm GC programs we need to check for type escaping.
//
+#include "ir/bits.h"
+#include "ir/gc-type-utils.h"
#include "ir/module-utils.h"
#include "ir/possible-constant.h"
#include "ir/struct-utils.h"
@@ -105,6 +107,15 @@ struct FunctionOptimizer : public WalkerPass<PostWalker<FunctionOptimizer>> {
// constant value. (Leave it to further optimizations to get rid of the
// ref.)
Expression* value = info.makeExpression(*getModule());
+ auto field = GCTypeUtils::getField(type, curr->index);
+ assert(field);
+ if (field->isPacked()) {
+ // We cannot just pass through a value that is packed, as the input gets
+ // truncated.
+ auto mask = Bits::lowBitMask(field->getByteSize() * 8);
+ value =
+ builder.makeBinary(AndInt32, value, builder.makeConst(int32_t(mask)));
+ }
replaceCurrent(builder.makeSequence(
builder.makeDrop(builder.makeRefAs(RefAsNonNull, curr->ref)), value));
changed = true;