Skip to content

DCE breaks by adding redundant terms #57120

@ThomasMayerl

Description

@ThomasMayerl

Sometimes, DCE breaks by adding a redundant term.

In the following example, the if statement always evaluates to false. LLVM (14) detects that and removes the dead code:

#include <stdbool.h>

void DCEMarker0_();

void f(bool s, bool sc, bool r, bool cr, bool c) {
    if ((((cr && sc && !r) || (c && !c)) && s && (!sc == !(r || r)))) {
        DCEMarker0_();
    }
}

Now, a redundant disjunction is inserted. LLVM is not able anymore to detect the dead code:

#include <stdbool.h>

void DCEMarker0_();

void f(bool s, bool sc, bool r, bool cr, bool c) {
    if (((((cr && sc && !r) || (c && !c)) && s && (!sc == !(r || (r || 0)))))) {
        DCEMarker0_();
    }
}

This is actually a regression: It worked fine up until LLVM 12.0.1. It has been an issue since LLVM 13.

This can also be seen via the following Compiler Explorer link: https://godbolt.org/z/asrdfj6fs

(Might be related to #56711)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions