[GlobalISel] Combine mulo x, 2 -> addo x, x
authorJessica Paquette <jpaquette@apple.com>
Tue, 28 Sep 2021 22:04:23 +0000 (15:04 -0700)
committerJessica Paquette <jpaquette@apple.com>
Tue, 28 Sep 2021 23:59:43 +0000 (16:59 -0700)
commit15a24e1fdbc446bc3d0fa0bf6c2a1aa44281cc75
treee30a408585348df34cdfc68501f276ab8bb322cb
parentb62d72f3c542729349633c5f77697fe24921251d
[GlobalISel] Combine mulo x, 2 -> addo x, x

Similar to what SDAG does when it sees a smulo/umulo against 2
(see: `DAGCombiner::visitMULO`)

This pattern is fairly common in Swift code AFAICT.

Here's an example extracted from a Swift testcase:

https://godbolt.org/z/6cT8Mesx7

Differential Revision: https://reviews.llvm.org/D110662
llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
llvm/include/llvm/Target/GlobalISel/Combine.td
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
llvm/test/CodeGen/AArch64/GlobalISel/combine-mulo-with-2.mir [new file with mode: 0644]