Stream: cranelift

Topic: Does if-let shadows bindings?


view this post on Zulip Bongjun Jang (Jul 08 2025 at 02:10):

;; or(x, C) + (-C)  -->  and(x, ~C)
(rule
  (simplify (iadd ty
              (bor ty x (iconst_s ty n))
              (iconst_s ty m)))
  (if-let m (i64_checked_neg n))
  (band ty x (iconst ty (imm64_masked ty (i64_cast_unsigned (i64_not n))))))

Hi, looking at this simplify rule, I realized there can be more than one interpretation of this rule.
Does m in the if-let clause shadow the binding of m in the LHS pattern, or
does it checks m is actually a negation of n?
I wanna know what is the expected behavior of ISLE.

view this post on Zulip Chris Fallin (Jul 08 2025 at 07:41):

I think this should treat m as already-bound and thus check for equality -- I say this based on the reused bindings map here. I haven't actually tried though -- it would be good to look at the generated code to ensure this is what's happening.

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

view this post on Zulip fitzgen (he/him) (Jul 09 2025 at 00:11):

I think that let allows shadowing but if-let does not. I have been annoyed by this in the past. I didn't ever consider if this was intentional to allow for equality checks with already-bound variables however


Last updated: Dec 06 2025 at 06:05 UTC