[InstCombine] Simplify Add with remainder expressions as operands.
authorSanjoy Das <sanjoy@playingwithpointers.com>
Thu, 26 Apr 2018 20:52:28 +0000 (20:52 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Thu, 26 Apr 2018 20:52:28 +0000 (20:52 +0000)
commit6f1937b10f1d67a866f5f84dc923b4a5e0de3a91
treefadfc56703c48a7657b06e314b64a3f0d28c87bf
parent0e643db48ff92b36c19582e544a8e21b3f5c11ca
[InstCombine] Simplify Add with remainder expressions as operands.

Summary:
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.

Patch by Bixia Zheng!

Reviewers: sanjoy

Reviewed By: sanjoy

Subscribers: efriedma, craig.topper, lebedev.ri, llvm-commits, jlebar

Differential Revision: https://reviews.llvm.org/D45976

llvm-svn: 330992
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/test/Transforms/InstCombine/add4.ll