[InstCombine] try to fold div with constant dividend and select-of-constants divisor
authorSanjay Patel <spatel@rotateright.com>
Wed, 8 Dec 2021 15:03:52 +0000 (10:03 -0500)
committerSanjay Patel <spatel@rotateright.com>
Wed, 8 Dec 2021 15:27:50 +0000 (10:27 -0500)
commita7ed21aa1e1d73e8c51490a52d6ebe6975fc558b
treedd784d104eebea11f72c7b6841d98975b711891a
parent2676759bf22e45def4d37da74f09261b26a98d21
[InstCombine] try to fold div with constant dividend and select-of-constants divisor

We avoid this fold in the more general cases where we use FoldOpIntoSelect.
That's because -- unlike most binary opcodes -- 'div' can't usually be
speculated with a variable divisor since it can have immediate UB. But in
the case where both arms of the select are constants, we can safely evaluate
both sides and eliminate 'div' completely.

This is a follow-up to the equivalent fold for 'rem' opcodes:
D115173 / f65be726ab50
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/div.ll