[InstCombine] fold sdiv with common shl amount in operands
authorSanjay Patel <spatel@rotateright.com>
Wed, 12 Oct 2022 15:18:55 +0000 (11:18 -0400)
committerSanjay Patel <spatel@rotateright.com>
Wed, 12 Oct 2022 15:32:15 +0000 (11:32 -0400)
commit7b9482df3dde2395608e0d0744c05bff22cff39e
tree3e86f328489dbc088a78cef106f367611b3ada75
parent4c19439d249256db720e323a446e39d05496732f
[InstCombine] fold sdiv with common shl amount in operands

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

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

This requires a surprising "nuw" constraint because we have
to guard against immediate UB via signed-div overflow with
-1 divisor.

This extends 008a89037a49ca0d9 and is another transform
derived from issue #58137.
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/div-shift.ll