Skip to content

ConstraintAnalysis: Add inequality parsing#8891

Merged
kripken merged 13 commits into
WebAssembly:mainfrom
kripken:ineq
Jul 10, 2026
Merged

ConstraintAnalysis: Add inequality parsing#8891
kripken merged 13 commits into
WebAssembly:mainfrom
kripken:ineq

Conversation

@kripken

@kripken kripken commented Jul 9, 2026

Copy link
Copy Markdown
Member

We now parse i32.lt_s and so forth.

This does not include full range analysis yet, so we don't infer
ties between <= and < for example, but this is already enough to infer
the precise inequalities we see, and their negations. This can handle
the simplest kinds of software bounds checks, more will be added later.

Also add proper printing of these opcodes.

@kripken kripken requested a review from tlively July 9, 2026 22:24
@kripken kripken requested a review from a team as a code owner July 9, 2026 22:24

@tlively tlively left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Neat!

Comment thread src/ir/constraint.cpp
Comment on lines +237 to +246
for (auto op : {Abstract::Eq,
Abstract::Ne,
Abstract::LtS,
Abstract::LtU,
Abstract::LeS,
Abstract::LeU,
Abstract::GtS,
Abstract::GtU,
Abstract::GeS,
Abstract::GeU}) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of guess-and-check to see if the binary operation is one we support, can we instead have a function in abstract.h to switch over binary->op and return the corresponding Abstract op, if any? Then we can very efficiently skip operations that don't correspond to any abstract op.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can measure this and look for an optimization. Maybe as an NFC followup?

(The challenge is avoiding code duplication - the current way avoids writing the mapping of opcodes twice.)

)
)

;; CHECK: (func $local-changes (type $3) (param $x i32) (param $y i32) (param $z i32)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I assume local-changes was not changed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I verified it did not change. Just unfortunate git diffing...

;; OPTIN: (func $inequalities-lt_u (type $0) (param $x i32)
;; OPTIN-NEXT: (drop
;; OPTIN-NEXT: (i32.eq
;; OPTIN-NEXT: (i32.lt_u

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add something simple to the tests to prevent the if-elses from being optimized out by OptimizeInstructions?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We could, but I'm not sure it would help - it would make the test longer but not add anything in these cases?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well the stated purpose of the OPTIN tests is to ensure that we still optimize canonicalized IR after optimize-instructions runs, and right now the tests are not showing that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, this matters mostly in the early tests where there are realistic conversions of things. I don't think these later ones need it. I could split out the test files if you think that's better?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense. Splitting might make sense, but it doesn't seem urgent.

@kripken kripken merged commit 2182234 into WebAssembly:main Jul 10, 2026
16 checks passed
@kripken kripken deleted the ineq branch July 10, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants