[InstCombine] canEvaluateTruncated - use KnownBits to check for inrange shift amounts
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Fri, 3 Jul 2020 14:51:06 +0000 (15:51 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Fri, 3 Jul 2020 15:02:10 +0000 (16:02 +0100)
commiteb0e7acbd4853c31a1401c8f02586850fee15107
treee586843214a6ead8ed274250e1c8705a034fa440
parent53422e8b4f65a6736896311b10ad8a22fbc9e372
[InstCombine] canEvaluateTruncated - use KnownBits to check for inrange shift amounts

Currently canEvaluateTruncated can only attempt to truncate shifts if they are scalar/uniform constant amounts that are in range.

This patch replaces the constant extraction code with KnownBits handling, using the KnownBits::getMaxValue to check that the amounts are inrange.

This enables support for nonuniform constant cases, and also variable shift amounts that have been masked somehow. Annoyingly, this still won't work for vectors with (demanded) undefs as KnownBits returns nothing in those cases, but its a definite improvement on what we currently have.

Differential Revision: https://reviews.llvm.org/D83127
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/2008-01-21-MulTrunc.ll
llvm/test/Transforms/InstCombine/cast.ll
llvm/test/Transforms/InstCombine/trunc.ll