From 54f3ac339a854dcfcedb2f964e9f4a1607d69375 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 20 Aug 2026 15:55:12 -0700 Subject: [PATCH 1/2] fix --- src/ir/constraint.cpp | 4 +- test/lit/passes/constraint-analysis.wast | 86 ++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/src/ir/constraint.cpp b/src/ir/constraint.cpp index a1516280deb..13d5891c4e4 100644 --- a/src/ir/constraint.cpp +++ b/src/ir/constraint.cpp @@ -420,7 +420,7 @@ std::optional LocalConstraint::parse(Expression* curr) { }; if (auto* unary = curr->dynCast()) { - if (Abstract::getUnary(unary->type, Abstract::EqZ) == unary->op) { + if (Abstract::getUnary(unary->value->type, Abstract::EqZ) == unary->op) { return parseEqZArgument(unary->value); } return {}; @@ -467,7 +467,7 @@ std::optional LocalConstraint::parse(Expression* curr) { Abstract::GtU, Abstract::GeS, Abstract::GeU}) { - if (Abstract::getBinary(binary->type, op) == binary->op) { + if (Abstract::getBinary(binary->left->type, op) == binary->op) { return parseBinaryArguments(op, binary->left, binary->right); } } diff --git a/test/lit/passes/constraint-analysis.wast b/test/lit/passes/constraint-analysis.wast index 2dd26b27779..6222f24c157 100644 --- a/test/lit/passes/constraint-analysis.wast +++ b/test/lit/passes/constraint-analysis.wast @@ -4649,4 +4649,90 @@ ) ) ) + + ;; CHECK: (func $eqz-condition (type $0) (param $x i32) + ;; CHECK-NEXT: (if + ;; CHECK-NEXT: (i32.eqz + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (then + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; OPTIN: (func $eqz-condition (type $0) (param $x i32) + ;; OPTIN-NEXT: (if + ;; OPTIN-NEXT: (i32.eqz + ;; OPTIN-NEXT: (local.get $x) + ;; OPTIN-NEXT: ) + ;; OPTIN-NEXT: (then + ;; OPTIN-NEXT: (drop + ;; OPTIN-NEXT: (i32.const 1) + ;; OPTIN-NEXT: ) + ;; OPTIN-NEXT: ) + ;; OPTIN-NEXT: ) + ;; OPTIN-NEXT: ) + (func $eqz-condition (param $x i32) + ;; Verify we parse an eqz condition and can optimize after it. + (if + (i32.eqz + (local.get $x) + ) + (then + ;; Also test we parse this binary properly, and see it is equivalent to + ;; the eqz. + (drop + (i32.eq + (local.get $x) + (i32.const 0) + ) + ) + ) + ) + ) + + ;; CHECK: (func $eqz-condition-64 (type $10) (param $x i64) + ;; CHECK-NEXT: (if + ;; CHECK-NEXT: (i64.eqz + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (then + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; OPTIN: (func $eqz-condition-64 (type $10) (param $x i64) + ;; OPTIN-NEXT: (if + ;; OPTIN-NEXT: (i64.eqz + ;; OPTIN-NEXT: (local.get $x) + ;; OPTIN-NEXT: ) + ;; OPTIN-NEXT: (then + ;; OPTIN-NEXT: (drop + ;; OPTIN-NEXT: (i32.const 1) + ;; OPTIN-NEXT: ) + ;; OPTIN-NEXT: ) + ;; OPTIN-NEXT: ) + ;; OPTIN-NEXT: ) + (func $eqz-condition-64 (param $x i64) + ;; As above, but i64. + (if + (i64.eqz + (local.get $x) + ) + (then + (drop + (i64.eq + (local.get $x) + (i64.const 0) + ) + ) + ) + ) + ) + + ;; binary ) From 6274e6853b89380d11866ef7af3d3126419b67c3 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 21 Aug 2026 11:03:01 -0700 Subject: [PATCH 2/2] Apply suggestion from @kripken --- test/lit/passes/constraint-analysis.wast | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/lit/passes/constraint-analysis.wast b/test/lit/passes/constraint-analysis.wast index 6222f24c157..6f04d3c882a 100644 --- a/test/lit/passes/constraint-analysis.wast +++ b/test/lit/passes/constraint-analysis.wast @@ -4733,6 +4733,4 @@ ) ) ) - - ;; binary )