[GlobalISel] Combine G_UMULH x, (1 << c)) -> x >> (bitwidth - c)
authorAmara Emerson <amara@apple.com>
Mon, 4 Oct 2021 05:26:26 +0000 (22:26 -0700)
committerAmara Emerson <amara@apple.com>
Fri, 8 Oct 2021 06:51:37 +0000 (23:51 -0700)
commit08b3c0d995d83060ae0cf3d3b2f9936da380cf29
tree250539f5c543b522a27a23e474e3b82d686acf81
parent23800b05be2be19451f6930ab7bd56aad4dab5e1
[GlobalISel] Combine G_UMULH x, (1 << c)) -> x >> (bitwidth - c)

In order to not generate an unnecessary G_CTLZ, I extended the constant folder
in the CSEMIRBuilder to handle G_CTLZ. I also added some extra handing of
vector constants too. It seems we don't have any support for doing constant
folding of vector constants, so the tests show some other useless G_SUB
instructions too.

Differential Revision: https://reviews.llvm.org/D111036
12 files changed:
llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h
llvm/include/llvm/CodeGen/GlobalISel/Utils.h
llvm/include/llvm/Target/GlobalISel/Combine.td
llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
llvm/lib/CodeGen/GlobalISel/Utils.cpp
llvm/test/CodeGen/AArch64/GlobalISel/combine-udiv.ll
llvm/test/CodeGen/AArch64/GlobalISel/combine-udiv.mir
llvm/test/CodeGen/AArch64/GlobalISel/combine-umulh-to-lshr.mir [new file with mode: 0644]
llvm/test/CodeGen/AMDGPU/GlobalISel/udiv.i32.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/udiv.i64.ll
llvm/unittests/CodeGen/GlobalISel/CSETest.cpp