Simplify integer add expression X % C0 + (( X / C0 ) % C1) * C0 to
X % (C0 * C1). This is a common pattern seen in code generated by the XLA
GPU backend.
Add test cases for this new optimization.
Differential D45976
[InstCombine] Simplify Add with remainder expressions as operands. bixia on Apr 23 2018, 11:16 AM. Authored by
Details Simplify integer add expression X % C0 + (( X / C0 ) % C1) * C0 to Add test cases for this new optimization.
Diff Detail
Event Timeline
Comment Actions Some style nits -- will review the content of the patch once these are fixed. You might want to skim through these: https://llvm.org/docs/CodingStandards.html http://llvm.org/docs/ProgrammersManual.html
Comment Actions I'm not sure I see anything that ensures C1*C2 doesn't overflow. And in particular if C1*C2 overflows and produces 0, the resulting remainder instruction is UB. Comment Actions Mostly nits except for the comment with the Alive proofs (didn't get to the meat of the patch yet).
Comment Actions Fixed Alive proof for the signed case: https://rise4fun.com/Alive/zJr Granted, I'm pretty sure this patch doesn't check the precondition correctly.
Comment Actions lgtm with minor nits.
|