[InstCombine] "X - (X / C) * C == 0" to "X & C-1 == 0"
authorEgorBo <egorbo@gmail.com>
Fri, 12 Jun 2020 07:08:17 +0000 (10:08 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Fri, 12 Jun 2020 07:20:06 +0000 (10:20 +0300)
commit012909dcaf852d4260decd04a76dfe45e7d329c0
treed5aec07d23d29a444a06226be3423b32234eb2f9
parent6538b3adbeee1c4cf2550014882fb36d3c8bf66d
[InstCombine] "X - (X / C) * C == 0" to "X & C-1 == 0"

Summary:
"X % C == 0" is optimized to "X & C-1 == 0" (where C is a power-of-two)
However, "X % Y" can also be represented as "X - (X / Y) * Y" so if I rewrite the initial expression:
"X - (X / C) * C == 0" it's not currently optimized to "X & C-1 == 0", see godbolt: https://godbolt.org/z/KzuXUj

This is my first contribution to LLVM so I hope I didn't mess things up

Reviewers: lebedev.ri, spatel

Reviewed By: lebedev.ri

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79369
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/add-shl-sdiv-to-srem.ll