[AggressiveInstCombine] Add logical shift right instr to `TruncInstCombine` DAG
authorAnton Afanasyev <anton.a.afanasyev@gmail.com>
Tue, 17 Aug 2021 10:49:53 +0000 (13:49 +0300)
committerAnton Afanasyev <anton.a.afanasyev@gmail.com>
Wed, 18 Aug 2021 19:20:58 +0000 (22:20 +0300)
commitcfb6dfcbd13b417f83d8adca69b60ba4254b4233
treefaaf50e3a7707c7280dd0a6d7e5cc80e5e49dbb5
parent2498c3edcdd271905851d69346be6d24ed292999
[AggressiveInstCombine] Add logical shift right instr to `TruncInstCombine` DAG

Add `lshr` instruction to the DAG post-dominated by `trunc`, allowing
TruncInstCombine to reduce bitwidth of expressions containing
these instructions.

We should be shifting by less than the target bitwidth.
Also it is sufficient to require that all truncated bits
of the value-to-be-shifted are zeros: https://alive2.llvm.org/ce/z/_LytbB

Alive2 variable-length proof:
https://godbolt.org/z/1srE1aqzf => s/32/8/ => https://alive2.llvm.org/ce/z/StwPia

Part of https://reviews.llvm.org/D107766

Differential Revision: https://reviews.llvm.org/D108201
llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
llvm/test/Transforms/AggressiveInstCombine/pr50555.ll
llvm/test/Transforms/AggressiveInstCombine/trunc_shifts.ll
llvm/test/Transforms/PhaseOrdering/X86/pr50555.ll