[PATCH] D115173: [InstCombine] try to fold rem with constant dividend and select-of-constants divisor
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 6 11:26:52 PST 2021
spatel created this revision.
spatel added reviewers: lebedev.ri, craig.topper, nikic.
Herald added subscribers: hiraditya, kristof.beyls, mcrosier.
spatel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
We avoid this fold in the more general cases where we use `FoldOpIntoSelect`. That's because -- unlike most binary opcodes -- 'rem' 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 'rem' completely.
This should fix:
https://llvm.org/PR52102
I think we have the same optimization gap for 'div', but I need to add/run tests to make sure, so I'll do that as a follow-up if this is ok. We already handle the case where the dividend is a select and the divisor is constant - that's just above the diff in this patch.
https://reviews.llvm.org/D115173
Files:
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/rem.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115173.392131.patch
Type: text/x-patch
Size: 7154 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211206/c5494163/attachment.bin>
More information about the llvm-commits
mailing list