Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
20e051a
Propate to exact types in struct-utils.h
tlively Sep 6, 2025
df76cfe
Merge branch 'main' into exact-cfp-fix
tlively Sep 8, 2025
f35f60d
Merge branch 'main' into exact-cfp-fix
tlively Sep 8, 2025
be904ae
[NFC] Add tests for missing exact CFP optimizations
tlively Sep 8, 2025
edb1d95
Merge branch 'cfp-missing-opts-tests' into exact-cfp-fix
tlively Sep 8, 2025
65eff0c
udpate test
tlively Sep 8, 2025
fe62381
Merge branch 'main' into exact-cfp-fix
tlively Sep 9, 2025
a310e7f
fix
tlively Sep 9, 2025
c567e37
comment
tlively Sep 9, 2025
fd3ec9c
Improve CFP by removing rawNewInfos
tlively Sep 9, 2025
7d0445e
Comment about convenience subscripting.
tlively Sep 9, 2025
89751b1
lambda
tlively Sep 9, 2025
49dcfc7
comment on exact propagation
tlively Sep 9, 2025
80a65e1
Merge branch 'main' into exact-cfp-fix
tlively Sep 9, 2025
3f2de02
Merge branch 'exact-cfp-fix' into cfp-no-newinfos
tlively Sep 9, 2025
56720bc
Merge branch 'main' into exact-cfp-fix
tlively Sep 10, 2025
0587147
Merge branch 'exact-cfp-fix' into cfp-no-newinfos
tlively Sep 10, 2025
6403073
update comment
tlively Sep 10, 2025
bb4db86
Merge branch 'exact-cfp-fix' into cfp-no-newinfos
tlively Sep 10, 2025
04fe19a
Merge branch 'main' into exact-cfp-fix
tlively Sep 11, 2025
1f618de
Merge branch 'exact-cfp-fix' into cfp-no-newinfos
tlively Sep 11, 2025
13b7a0f
Merge branch 'main' into exact-cfp-fix
tlively Sep 12, 2025
8ff8c97
Merge branch 'exact-cfp-fix' into cfp-no-newinfos
tlively Sep 12, 2025
1d61606
remove complexity of avoiding exactness
tlively Sep 12, 2025
cd0f81a
Merge branch 'exact-cfp-fix' into cfp-no-newinfos
tlively Sep 12, 2025
7974701
[NFC] Note copies between any fields in struct-utils.h
tlively Sep 9, 2025
76aec7d
Handle arbitrary copies in CFP
tlively Sep 9, 2025
ac9e64e
Merge branch 'main' into cfp-no-newinfos
tlively Sep 13, 2025
821f1fc
Merge branch 'cfp-no-newinfos' into struct-utils-precise-copying
tlively Sep 13, 2025
4d88690
Merge branch 'struct-utils-precise-copying' into cfp-copying
tlively Sep 13, 2025
ad676eb
Merge branch 'main' into cfp-no-newinfos
tlively Sep 18, 2025
8218a60
Merge branch 'cfp-no-newinfos' into struct-utils-precise-copying
tlively Sep 18, 2025
cda1f6e
Merge branch 'struct-utils-precise-copying' into cfp-copying
tlively Sep 18, 2025
2eeb2f6
packForField comment
tlively Sep 18, 2025
d021ea8
CopyInfo comment
tlively Sep 18, 2025
d7a99c1
noteCopy dst params
tlively Sep 18, 2025
50f328f
remove redundant function map initialization
tlively Sep 18, 2025
7c12a7d
test comment
tlively Sep 18, 2025
60952dc
fix asan error
tlively Sep 18, 2025
80f48d6
Merge branch 'main' into cfp-no-newinfos
tlively Sep 19, 2025
770d1da
Merge branch 'cfp-no-newinfos' into struct-utils-precise-copying
tlively Sep 19, 2025
19c4ed4
Merge branch 'struct-utils-precise-copying' into cfp-copying
tlively Sep 19, 2025
7e0b86e
Merge branch 'main' into struct-utils-precise-copying
tlively Sep 20, 2025
e01339a
Merge branch 'struct-utils-precise-copying' into cfp-copying
tlively Sep 20, 2025
9b24942
fix and add field copy tests
tlively Sep 20, 2025
037b6a3
Merge branch 'main' into cfp-copying
tlively Sep 23, 2025
019a810
principal principle
tlively Sep 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 40 additions & 22 deletions src/ir/possible-constant.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <variant>

#include "ir/properties.h"
#include "support/utilities.h"
#include "wasm-builder.h"
#include "wasm.h"

Expand Down Expand Up @@ -85,6 +86,45 @@ struct PossibleConstantValues {
// identify a constant value here.
void noteUnknown() { value = Many(); }

// Modify the possible constant to account for being written to or read from a
// possibly-packed field. When used to model a read, `isSigned` controls
// whether the value will be sign-extended or not.
void packForField(const Field& field, bool isSigned = false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment for this method. On the face of it it seems quite different than the others above it. Is it called when written to a packed field, or read from one?

if (field.type != Type::i32 || !field.isPacked()) {
return;
}
if (!isConstant()) {
// Nothing to pack.
return;
}
if (isConstantGlobal()) {
// Cannot track global and bit masking simultaneously, so give up.
noteUnknown();
return;
}
assert(isConstantLiteral());
auto val = getConstantLiteral();
assert(val.type == Type::i32);
switch (field.packedType) {
case Field::i8:
if (isSigned) {
value = val.extendS8();
} else {
value = val.and_(Literal(uint32_t(0xff)));
}
break;
case Field::i16:
if (isSigned) {
value = val.extendS16();
} else {
value = val.and_(Literal(uint32_t(0xffff)));
}
break;
case Field::not_packed:
WASM_UNREACHABLE("unexpected packed type");
}
}

// Combine the information in a given PossibleConstantValues to this one. This
// is the same as if we have called note*() on us with all the history of
// calls to that other object.
Expand All @@ -109,28 +149,6 @@ struct PossibleConstantValues {
return true;
}

// Nulls compare equal, and we could consider any of the input nulls as the
// combination of the two (as any of them would be valid to place in the
// location we are working to optimize). In order to have simple symmetric
// behavior here, which does not depend on the order of the inputs, use the
// LUB.
if (isNull() && other.isNull()) {
auto type = getConstantLiteral().type.getHeapType();
auto otherType = other.getConstantLiteral().type.getHeapType();
auto lub = HeapType::getLeastUpperBound(type, otherType);
if (!lub) {
// TODO: Remove this workaround once we have bottom types to assign to
// null literals.
value = Many();
return true;
}
if (*lub != type) {
value = Literal::makeNull(*lub);
return true;
}
return false;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this large chunk of code entirely unneeded? I'm not quite seeing the connection to this PR.

Copy link
Member Author

@tlively tlively Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was just dead code I removed as a drive-by. I can move it to a separate PR if you prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok as is, I was just confused.

return false;
}

Expand Down
Loading
Loading