Stream: cranelift

Topic: Inspecting inputs during cranelift lowering


view this post on Zulip Sam Parker (Jun 18 2021 at 14:25):

Hi, I've just started working on cranelift and I'm trying to do some pattern matching which involves inspecting values and not just the input opcode. From the instruction I'm lowering, I want to look at the two inputs and figure out if each of them is using the same input value (same virtual register?) Is this possible, or is lowering just not the place where this can happen? I'm coming from LLVM, so any description is those terms of how instructions are represented and can be queried would be most welcome.

view this post on Zulip Notification Bot (Jun 18 2021 at 14:27):

This topic was moved here from #general > Inspecting inputs during cranelift lowering by Till Schneidereit

view this post on Zulip Till Schneidereit (Jun 18 2021 at 14:28):

Hi Sam, and welcome! I moved this topic to the #cranelift stream for more visibility to folks focusing on Cranelift. Many of them will probably only be around a bit later in the day, though :smile:

view this post on Zulip Andrew Brown (Jun 18 2021 at 16:06):

I think the Shuffle operation is doing that in the x64 backend: it checks whether its two operands live in the same register and emits a different lowering if that is the case.

Standalone JIT-style runtime for WebAssembly, using Cranelift - bytecodealliance/wasmtime

view this post on Zulip Sam Parker (Jun 21 2021 at 09:38):

Right, we can do the comparisons on registers once they've been 'put', but can I inspect the inputs to the inputs (which I assumed haven't been visited yet)? From my extremely limited understanding, it looks like lowering is done with a per-instruction context, which is why I'm suspecting I can't look at much but the current instruction.

view this post on Zulip Sam Parker (Jun 21 2021 at 10:31):

And the answer is yes... put_input_in_reg can be used on the input's inputs :)

view this post on Zulip Chris Fallin (Jun 21 2021 at 15:36):

Hi @Sam Parker , there are several lowering patterns in the current backends that look beyond the inputs to the currently-being-lowered instruction; see e.g. lower_to_amode in aarch64 (looks through extends and a tree of adds to find all addends), or xext/uext handling in aarch64, or uext handling in x64

view this post on Zulip Chris Fallin (Jun 21 2021 at 15:36):

and, indeed, once you have an input further up the operand tree you can get it in a reg directly, as you've found!

view this post on Zulip Chris Fallin (Jun 21 2021 at 15:37):

note that some care should be taken when merging effectful ops -- see the sink method on LowerCtx if, e.g., you happen to merge a load


Last updated: Dec 23 2024 at 12:05 UTC