[InstCombine] factorize left shifts of add/sub
authorSanjay Patel <spatel@rotateright.com>
Sun, 20 Sep 2020 16:55:24 +0000 (12:55 -0400)
committerSanjay Patel <spatel@rotateright.com>
Sun, 20 Sep 2020 16:55:24 +0000 (12:55 -0400)
commit7903ae4720a8c4f3c694954d56293c7507e07945
treeed6c159ffb89de7fa41f84ae8d8918733b14e123
parentcf75e83275d16f9172fa5ab448a981afdadd34d0
[InstCombine] factorize left shifts of add/sub

We do similar factorization folds in SimplifyUsingDistributiveLaws,
but that drops no-wrap properties. Propagating those optimally may
help solve:
https://llvm.org/PR47430

The propagation is all-or-nothing for these patterns: when all
3 incoming ops have nsw or nuw, the 2 new ops should have the
same no-wrap property:
https://alive2.llvm.org/ce/z/Dv8wsU

This also solves:
https://llvm.org/PR47584
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/shl-factor.ll