Skip to content

Conversation

@Qchan233
Copy link

@Qchan233 Qchan233 commented Dec 26, 2025

When debugging, I found that the sccp optimization doesn't work using the following example, though constant folding does the work. I think it would be good that gets optimized early in sccp.

int test()
{
    int c;
    if (1) {
        c = 1;
    } else {
        c = 0;
    }

    return c;
}

Summary by cubic

Mark destinations of OP_load_constant as const in SCCP. This enables early constant propagation so SCCP optimizes trivial branches and assignments (e.g., returning a constant after an if/else).

  • Bug Fixes
    • In simple_sccp, set rd->is_const when opcode == OP_load_constant to allow SCCP to recognize and propagate constants.

Written for commit 483a46a. Summary will update automatically on new commits.

Comment on lines +33 to +35
if (insn->opcode == OP_load_constant) {
insn->rd->is_const = true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it slightly shorter. That is,

            if (insn->opcode == OP_load_constant)
                insn->rd->is_const = true;

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@Qchan233 Qchan233 marked this pull request as draft December 26, 2025 07:31
@jserv jserv changed the title Mark constants early to enable sccp Mark constants early to enable SCCP Dec 26, 2025
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

Successfully merging this pull request may close these issues.

2 participants