daphne-project / daphne-project/daphne

`?:`-operator/`CondOp` with scalar condition calculates both then/else-expressions

Open
#486 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
81
Forks
83
PR merge metrics
No merged PRs in 30d

Description

The conditional operator `cond ? then-value : else-value` in DaphneDSL accepts scalars and matrices for the condition (see DaphneDSL language reference). In DaphneIR, this operator is represented by `daphne::CondOp`. If the condition is a matrix, `CondOp` is lowered to a kernel call. If the condition is a scalar, we don't need kernels, but rewrite the `daphne::CondOp` to a `scf::IfOp` in `CondOp::canonicalize()`.

Currently, in the rewritten IR, the then/else-expressions are evaluated before the `IfOp`, not inside it's branches. This could be good (e.g., if the then/else-values have common subexpressions with other code) or bad (e.g., if they are expensive to compute).

**It would be good to further investigate this, especially to avoid very expensive scenarios.**

Please search for #486 in the codebase.

Contributor guide

Open the contributing guide

Research direction

Search the codebase for #486 and start with CondOp::canonicalize(), the DaphneDSL language reference, and the DaphneIR lowering to scf::IfOp. Trace when the scalar condition's then- and else-expressions are evaluated, then establish the expected evaluation behavior and how to avoid unnecessarily expensive computation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.