Stream: cranelift

Topic: egraph optimizations for conditionals


view this post on Zulip Alex Crichton (May 13 2026 at 16:14):

Continuing the discussion from the meeting today, Chris or Nick what was the shape of the simplify_conditional rule y'all were thinking of?

Would it be something like (decl multi simplify_conditional (Value) Value)? Or (decl partial simplify_conditional (Value) Value)? I've never quite wrapped my head around multi things...

Also, how were y'all thinking it'd be applied to trap/brif/select? Naively I'd expect something like:

(rule (simplify (select ty cond a b))
  (if-let simpler_cond (simplify_conditional cond))
  (select ty simpler_cond a b))

but this'd require a partial constructor as opposed to a multi, and with multi I'm not sure how that'd fit in here

view this post on Zulip fitzgen (he/him) (May 13 2026 at 16:15):

I think a partial constructor would be fine

view this post on Zulip fitzgen (he/him) (May 13 2026 at 16:16):

multi would also require that we figure out how to do egraph extraction / best value computation for these values in the context of being zero/non-zero

view this post on Zulip Alex Crichton (May 13 2026 at 16:20):

hm I added:

(decl partial simplify_conditional (Value) Value)

(rule 0 (simplify_conditional (icmp ty (IntCC.NotEqual) a (iconst_u _ 0))) a)
(rule 1 (simplify_conditional (icmp ty (IntCC.NotEqual) (iconst_u _ 0) a)) a)

and got:

  thread 'main' (430396) panicked at cranelift/isle/isle/src/codegen.rs:561:13:
  assertion failed: !block.steps.iter().any(|c| matches!(c.check, ControlFlow::Loop { .. }))
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

during isle compilation

view this post on Zulip Chris Fallin (May 13 2026 at 16:22):

try a multi? (more thoughts here but meetings for a few hours)

view this post on Zulip Alex Crichton (May 13 2026 at 16:24):

how would multi be integrated? Something like this?

(rule (simplify (select ty cond a b))
  (select ty (simplify_conditional cond) a b))

I'm not sure how else to integrate it but that feels like an infinite loop or blowup waiting to happen

view this post on Zulip Chris Fallin (May 13 2026 at 17:13):

yes, exactly. no infinite loops here -- maybe not ideal though if we know for sure that the simplified form is better

view this post on Zulip Chris Fallin (May 13 2026 at 17:14):

we may not have ever run multi-calling-non-multi through the new codegen backend before -- we should fix that


Last updated: Jun 01 2026 at 09:49 UTC