Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Builder expression simplifications #253

Open
andreistefanescu opened this issue Jan 18, 2024 · 0 comments
Open

Document Builder expression simplifications #253

andreistefanescu opened this issue Jan 18, 2024 · 0 comments

Comments

@andreistefanescu
Copy link
Contributor

This is now a common pattern: optimizing an operation by checking if one of the arguments is ite c then a else b, where a and b are concrete, and pushing the operation down through the ite. One thing that's not as clear is what metrics we use to determine which operations should receive these optimizations—for instance, we apply this optimization to bvAndBits, but not bvXorBits. Was the set of operations to optimize chosen based on an assessment of which operations occurred most commonly in a large SAW proof? Something else?

Either way, it might be helpful to record this information in a Note somewhere. I'm thinking of something like this:

  bvZext sym w x
    ...

    -- See Note [ExprBuilder muxing optimizations]
    | Just (BaseIte _ _ c a b) <- asApp x
    , Just a_bv <- asBV a
    , Just b_bv <- asBV b = do
      Just LeqProof <- return $ isPosNat w
      a' <- bvLit sym w $ BV.zext w a_bv
      b' <- bvLit sym w $ BV.zext w b_bv
      bvIte sym c a' b'

  bvSext sym w x
    ...

    -- See Note [ExprBuilder muxing optimizations]
    | Just (BaseIte _ _ c a b) <- asApp x
    , Just a_bv <- asBV a
    , Just b_bv <- asBV b = do
      Just LeqProof <- return $ isPosNat w
      a' <- bvLit sym w $ BV.sext (bvWidth x) w a_bv
      b' <- bvLit sym w $ BV.sext (bvWidth x) w b_bv
      bvIte sym c a' b'

...

{-
Note [ExprBuilder muxing optimizations]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Whenever we see certain operations of the form op (ite c then a else b), where a and b are concrete,
then we optimize it by ...

We do this because ...

We chose which optimizations receive this optimization by ...
-}

And then reference the Note in each place where we apply this optimization.

Originally posted by @RyanGlScott in #252 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant