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

Predication: Another problem #2613

Closed
fruffy opened this issue Nov 19, 2020 · 1 comment
Closed

Predication: Another problem #2613

fruffy opened this issue Nov 19, 2020 · 1 comment
Labels
bug This behavior is unintended and should be fixed. fixed This topic is considered to be fixed. predication-pass Issues related to p4c's Predication pass

Comments

@fruffy
Copy link
Collaborator

fruffy commented Nov 19, 2020

The issues are become rare but there is another case where the predication pass has a problem.
I tried to make the expression look reasonable:

action assign_addrs(inout Headers h, bool check_1, bool check_2) {
    if (check_1) {
        h.eth_hdr.dst_addr = 2;
        if (check_2) {
            // note that this is not dst_addr
            h.eth_hdr.src_addr = 3;
        } else {
            h.eth_hdr.dst_addr = 1;
        }
    }
}

control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
    apply {
        assign_addrs(h, true, true);
    }
}

Is transformed into

control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
    ethernet_t h_1_eth_hdr;
    bool check_1;
    bool check_2;
    @name(".assign_addrs") action assign_addrs() {
        {
            h_1_eth_hdr = h.eth_hdr;
        }
        check_1 = true;
        check_2 = true;
        {
            {
                {
                    h_1_eth_hdr.src_addr = (check_1 ? (check_2 ? 48w3 : h_1_eth_hdr.src_addr) : h_1_eth_hdr.src_addr);
                    h_1_eth_hdr.dst_addr = (check_1 ? (check_2 ? h_1_eth_hdr.dst_addr : 48w1) : h_1_eth_hdr.dst_addr);
                }
            }
        }
        {
            h.eth_hdr = h_1_eth_hdr;
        }
    }
    apply {
        assign_addrs();
    }
}

The assignment h.eth_hdr.dst_addr = 2; is lost here.

predication_issue.p4.txt
predication_issue.stf.txt

@fruffy fruffy changed the title Prediction: Another problem Predication: Another problem Nov 19, 2020
@mihaibudiu mihaibudiu added the bug This behavior is unintended and should be fixed. label Nov 19, 2020
@mihaibudiu
Copy link
Contributor

@anasyrmia : can you please take a look?

anasyrmia added a commit to anasyrmia/p4c-1 that referenced this issue Dec 2, 2020
The removal of the condition on the line 192 leads to the correct predication output. The mentioned condition was not correct, it only tests if the travesalPath is false, which is true when there is any else branch in a p4 test, and the assignment in 'then' should be erased only when there is a statement with the same statementName in the else branch in p4 test.

Then-else handling is correctly managed in if block on line 201 (new line 196), so no other test outputs are changed by this commit.
@fruffy fruffy added predication-pass Issues related to p4c's Predication pass fixed This topic is considered to be fixed. labels Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This behavior is unintended and should be fixed. fixed This topic is considered to be fixed. predication-pass Issues related to p4c's Predication pass
Projects
None yet
Development

No branches or pull requests

2 participants