[InstCombine] recognizeBSwapOrBitReverseIdiom - recognise zext(bswap(trunc(x))) patte...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 30 Sep 2020 11:07:19 +0000 (12:07 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 30 Sep 2020 11:07:19 +0000 (12:07 +0100)
commitaf47d40b9c68744eb66aa2ef779065e946aaa099
treeb4e590c6c2df255e21fb2e0c195dfb81a17775f8
parentec3f24d4538d1c262377331c7b35ea66e023cf98
[InstCombine] recognizeBSwapOrBitReverseIdiom - recognise zext(bswap(trunc(x))) patterns (PR39793)

PR39793 demonstrated an issue where we fail to recognize 'partial' bswap patterns of the lower bytes of an integer source.

In fact, most of this is already in place collectBitParts suitably tags zero bits, so we just need to correctly handle this case by finding the zero'd upper bits and reducing the bswap pattern just to the active demanded bits.

Differential Revision: https://reviews.llvm.org/D88316
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/InstCombine/bswap.ll