This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fold comparison of integers by parts
ClosedPublic

Authored by nikic on Apr 24 2021, 7:48 AM.

Details

Summary

Let's say you represent (i32, i32) as an i64 from which the parts are extracted with lshr/trunc. Then, if you compare two tuples by parts you get something like A[0] == B[0] && A[1] == B[1], just that the part extraction happens by lshr/trunc and not a narrow load or similar.

The fold implemented here reduces such equality comparisons by converting them into a comparison on a larger part of the integer (which might be the whole integer). It handle both the "and of eq" and the conjugated "or of ne" case.

I'm being conservative with one-use for now, though this could be relaxed if profitable (the base pattern converts 11 instructions into 5 instructions, but there's quite a few variations on how it can play out).

Diff Detail

Event Timeline

nikic created this revision.Apr 24 2021, 7:48 AM
nikic requested review of this revision.Apr 24 2021, 7:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2021, 7:48 AM
nikic updated this revision to Diff 342132.May 1 2021, 3:06 AM
nikic edited the summary of this revision. (Show Details)

Also handle "or of ne". Doesn't really make sense to only handle half of the pattern, and it doesn't come at any additional complexity.

spatel accepted this revision.May 10 2021, 12:23 PM

Sorry for the delay - LGTM.

This revision is now accepted and ready to land.May 10 2021, 12:23 PM
This revision was automatically updated to reflect the committed changes.