[InstCombine] fold udiv with common shl amount in operands
authorSanjay Patel <spatel@rotateright.com>
Wed, 12 Oct 2022 14:58:03 +0000 (10:58 -0400)
committerSanjay Patel <spatel@rotateright.com>
Wed, 12 Oct 2022 15:12:26 +0000 (11:12 -0400)
commit008a89037a49ca0d9ed85bb8548a048991ff133b
treed5c4b0b860e11c2edbf4f79cacf8783f37f7f859
parentdbd29ed54b090546624b3215cbc58c92acdcc233
[InstCombine] fold udiv with common shl amount in operands

(X << Z) / (Y << Z) --> X / Y

https://alive2.llvm.org/ce/z/E5eaxU

This fixes the motivating example from issue #58137,
but it is not the most general transform. We should
probably also convert left-shift in the divisor to
right-shift in the dividend for that, but that exposes
another missed canonicalization for shifts and adds.
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/div-shift.ll
llvm/test/Transforms/PhaseOrdering/reassociate-instcombine.ll