Skip to content

CFG: loops after a return cause missed optimizations #2128

@evantypanski

Description

@evantypanski

It seems like anywhere that a loop appears makes dead code elimination not happen. Given this Hilti code:

module Test {

import hilti;

function void f() {
    local x = 5;
    return;
    while (True) {}
    hilti::print(x);
}

f();

}

The output f is:

$ HILTI_OPTIMIZER_ENABLE_CFG=1 hiltic -p test.hlt
function void f() {
    local uint<64> x = 5;
    return;

    while ( True ) {
    }

    hilti::print(x, True);
}

and replacing the while with if optimizes it correctly (with an extra block but meh):

$ HILTI_OPTIMIZER_ENABLE_CFG=1 hiltic -p test.hlt
function void f() {
    return;
    {
    }
}

Doesn't seem like this should be high priority, but it technically causes missed optimizations, for example if that store in x is expensive. I don't think it'll pop up much. I'm also not sure why it happens, though, so it might be more.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions