This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fold `(icmp eq/ne (zext i1 X) (sext i1 Y))`-> `(icmp eq/ne (or X, Y), 0)`
ClosedPublic

Authored by goldstein.w.n on Jul 6 2023, 12:30 AM.

Details

Summary

This comes up when adding two bool types in C/C++

    bool foo(bool a, bool b) {
        return a + b;
    }
    ...
    ->
    define i1 @foo(i1 %a, i1 %b) {
        %conv = zext i1 %a to i32
        %conv3.neg = sext i1 %b to i32
        %tobool4 = icmp ne i32 %conv, %conv3.neg
        ret i1 %tobool4
}

Proof: https://alive2.llvm.org/ce/z/HffWAN

Diff Detail

Event Timeline

goldstein.w.n created this revision.Jul 6 2023, 12:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2023, 12:30 AM
goldstein.w.n requested review of this revision.Jul 6 2023, 12:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2023, 12:30 AM
nikic accepted this revision.Jul 6 2023, 12:38 AM

LGTM

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
5264

and -> are

This revision is now accepted and ready to land.Jul 6 2023, 12:38 AM
This revision was landed with ongoing or failed builds.Jul 12 2023, 3:18 PM
This revision was automatically updated to reflect the committed changes.