Vector35 / Vector35/binaryninja-api

Provide some simplification of common routines like MIN/MAX

Open
#6,942 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Core Core: HLIL Effort: Low IL Optimization Impact: Medium
Dominant language
C++
Stars
1.3k
Forks
298
Avg merge
5d 5h
Merged PRs (30d)
19

Description

Created on behalf of @VisualEhrmanntraut

Optimiser for min, max expressions:

TYPE val;
if (Z > Y) {
  val = Y
} else {
  val = Z
}
// after
TYPE val = MIN(Y, Z);```
```// before 
TYPE val;
if (Z < Y) {
  val = Y
} else {
  val = Z
}
// after
TYPE val = MAX(Y, Z);

This should be done after all IL simplifications like constant propagation so that the analysis has a chance to optimize the MIN/MAX code out entirely. This really is not about any particular architecture plugin either, one can reasonably expect this operation to be performed by a set of instructions rather than any one instruction, were it the latter you might compromise and lift as an intrinsic, however even that is a little disappointing as you will stonewall certain analysis regarding the input and output registers.

Putting this as an HLIL issue because I believe that is the only place this optimization can be made considering the first sentence above.

Slack Message

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the HLIL simplification passes and the existing IL simplifications, especially constant propagation. Determine where a conditional assignment can be recognized as MIN or MAX after those passes, then verify that equivalent expressions are produced and that existing analysis of inputs and outputs is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, reverse-engineering
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.