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..6f04d3c882a 100644 --- a/test/lit/passes/constraint-analysis.wast +++ b/test/lit/passes/constraint-analysis.wast @@ -4649,4 +4649,88 @@ ) ) ) + + ;; 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) + ) + ) + ) + ) + ) )